blob: 9ab71ad7bb4982769164d05a4397df78bc0fae91 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 /** User Activity */
385 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
387
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700388 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
389
Derek Tan97ebb422014-09-05 16:55:38 -0700390 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
391 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800392 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800393 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700394
Michelecea4cf22018-12-21 15:00:11 -0800395 // String to store multi SIM allowed
396 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
397
Derek Tan740e1672017-06-27 14:56:27 -0700398 // The AID of ISD-R.
399 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
400
yinxub1bed742017-04-17 11:45:04 -0700401 private NetworkScanRequestTracker mNetworkScanRequestTracker;
402
David Kelly5e06a7f2018-03-12 14:10:59 +0000403 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
404 private static final int MANUFACTURER_CODE_LENGTH = 8;
405
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800407 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408
Derek Tan89e89d42014-07-08 17:00:10 -0700409 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700410 * Experiment flag to enable erase modem config on reset network, default value is false
411 */
412 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
413 "reset_network_erase_modem_config_enabled";
414
Rambo Wang0f050d82021-02-12 11:43:36 -0800415 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800416
sandeepjsb6c87872021-09-27 15:34:44 +0000417 /**
418 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
419 * one ICCID active at the same time.
420 * Apps should use below API signatures if targeting SDK is T and beyond.
421 *
422 * @hide
423 */
424 @ChangeId
425 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
426 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800427
Naina Nallurid63128d2019-09-17 14:10:30 -0700428 /**
Chen Xu540470b2021-12-14 17:15:47 -0800429 * Apps targeting on Android T and beyond will get exception whenever icc close channel
430 * operation fails.
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
435
436 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 * A request object to use for transmitting data to an ICC.
438 */
439 private static final class IccAPDUArgument {
440 public int channel, cla, command, p1, p2, p3;
441 public String data;
442
443 public IccAPDUArgument(int channel, int cla, int command,
444 int p1, int p2, int p3, String data) {
445 this.channel = channel;
446 this.cla = cla;
447 this.command = command;
448 this.p1 = p1;
449 this.p2 = p2;
450 this.p3 = p3;
451 this.data = data;
452 }
453 }
454
455 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700456 * A request object to use for transmitting data to an ICC.
457 */
458 private static final class ManualNetworkSelectionArgument {
459 public OperatorInfo operatorInfo;
460 public boolean persistSelection;
461
462 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
463 this.operatorInfo = operatorInfo;
464 this.persistSelection = persistSelection;
465 }
466 }
467
468 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
470 * request after sending. The main thread will notify the request when it is complete.
471 */
472 private static final class MainThreadRequest {
473 /** The argument to use for the request */
474 public Object argument;
475 /** The result of the request that is run on the main thread */
476 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800477 // The subscriber id that this request applies to. Defaults to
478 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
479 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Nathan Harold92bed182018-10-12 18:16:49 -0700481 // In cases where subId is unavailable, the caller needs to specify the phone.
482 public Phone phone;
483
vagdeviaf9a5b92018-08-15 16:01:53 -0700484 public WorkSource workSource;
485
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 public MainThreadRequest(Object argument) {
487 this.argument = argument;
488 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800489
Nathan Harold92bed182018-10-12 18:16:49 -0700490 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
491 this.argument = argument;
492 if (phone != null) {
493 this.phone = phone;
494 }
495 this.workSource = workSource;
496 }
497
vagdeviaf9a5b92018-08-15 16:01:53 -0700498 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800499 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800500 if (subId != null) {
501 this.subId = subId;
502 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700503 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 }
506
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800507 private static final class IncomingThirdPartyCallArgs {
508 public final ComponentName component;
509 public final String callId;
510 public final String callerDisplayName;
511
512 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
513 String callerDisplayName) {
514 this.component = component;
515 this.callId = callId;
516 this.callerDisplayName = callerDisplayName;
517 }
518 }
519
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 /**
521 * A handler that processes messages on the main thread in the phone process. Since many
522 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
523 * inbound binder threads to the main thread in the phone process. The Binder thread
524 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
525 * on, which will be notified when the operation completes and will contain the result of the
526 * request.
527 *
528 * <p>If a MainThreadRequest object is provided in the msg.obj field,
529 * note that request.result must be set to something non-null for the calling thread to
530 * unblock.
531 */
532 private final class MainThreadHandler extends Handler {
533 @Override
534 public void handleMessage(Message msg) {
535 MainThreadRequest request;
536 Message onCompleted;
537 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000538 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800540 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541
542 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 case CMD_HANDLE_USSD_REQUEST: {
544 request = (MainThreadRequest) msg.obj;
545 final Phone phone = getPhoneFromRequest(request);
546 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800547 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 if (!isUssdApiAllowed(request.subId)) {
551 // Carrier does not support use of this API, return failure.
552 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
553 UssdResponse response = new UssdResponse(ussdRequest, null);
554 Bundle returnData = new Bundle();
555 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
556 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700557
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 request.result = true;
559 notifyRequester(request);
560 return;
561 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700562
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 try {
564 request.result = phone != null
565 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
566 } catch (CallStateException cse) {
567 request.result = false;
568 }
569 // Wake up the requesting thread
570 notifyRequester(request);
571 break;
pkanwar32d516d2016-10-14 19:37:38 -0700572 }
573
Yorke Lee716f67e2015-06-17 15:39:16 -0700574 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700576 final Phone phone = getPhoneFromRequest(request);
577 request.result = phone != null ?
578 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
579 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700580 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 uiccPort = getUiccPortFromRequest(request);
589 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800591 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800595 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000596 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800597 iccArgument.channel, iccArgument.cla, iccArgument.command,
598 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
599 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800609 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800612 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800614 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 } else {
616 loge("iccTransmitApduLogicalChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 uiccPort = getUiccPortFromRequest(request);
626 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800628 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800632 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000633 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800634 iccArgument.cla, iccArgument.command, iccArgument.p1,
635 iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800692 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800696 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800752
753 uiccPort = getUiccPortFromRequest(request);
754 IccLogicalChannelRequest channelRequest =
755 (IccLogicalChannelRequest) request.argument;
756 channelRequest.channel = channelId;
757 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 if (ar.result == null) {
760 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 if (ar.exception != null) {
763 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
764 }
765
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700766 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700767 if (ar.exception instanceof CommandException) {
768 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800769 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700770 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700772 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700773 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 }
775 }
776 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800777 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700779 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 break;
782
783 case CMD_CLOSE_CHANNEL:
784 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000785 uiccPort = getUiccPortFromRequest(request);
786 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800788 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800789 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800790 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700791 } else {
792 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000793 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 break;
796
797 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800798 ar = (AsyncResult) msg.obj;
799 request = (MainThreadRequest) ar.userObj;
800 if (ar.exception == null) {
801 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800802 uiccPort = getUiccPortFromRequest(request);
803 final int channelId = (Integer) request.argument;
804 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800805 } else {
806 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800807 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800808 if (ar.exception instanceof CommandException) {
809 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
810 CommandException.Error error =
811 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800812 if (error == CommandException.Error.INVALID_ARGUMENTS) {
813 // should only throw exceptions from the binder threads.
814 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800815 "iccCloseLogicalChannel: invalid argument ");
816 }
817 } else {
818 loge("iccCloseLogicalChannel: Unknown exception");
819 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800820 request.result = (exception != null) ? exception :
821 new IllegalStateException(
822 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800823 }
824 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800825 break;
826
827 case CMD_NV_READ_ITEM:
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800830 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
831 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800832 break;
833
834 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800840 request.result = "";
841 if (ar.result == null) {
842 loge("nvReadItem: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("nvReadItem: CommandException: " +
845 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800847 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 }
849 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700850 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 break;
852
Jake Hambye994d462014-02-03 13:10:13 -0800853 case CMD_NV_WRITE_ITEM:
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
856 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800857 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700858 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800859 break;
860
861 case EVENT_NV_WRITE_ITEM_DONE:
862 handleNullReturnEvent(msg, "nvWriteItem");
863 break;
864
865 case CMD_NV_WRITE_CDMA_PRL:
866 request = (MainThreadRequest) msg.obj;
867 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800868 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800869 break;
870
871 case EVENT_NV_WRITE_CDMA_PRL_DONE:
872 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
873 break;
874
chen xu6dac5ab2018-10-26 17:39:23 -0700875 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800876 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700877 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800878 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800879 break;
880
chen xu6dac5ab2018-10-26 17:39:23 -0700881 case EVENT_RESET_MODEM_CONFIG_DONE:
882 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800883 break;
884
Sooraj Sasindran37444802020-08-11 10:40:43 -0700885 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
888 request);
889 Phone phone = getPhoneFromRequest(request);
890 if (phone != null) {
891 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
892 } else {
893 loge("isNRDualConnectivityEnabled: No phone object");
894 request.result = false;
895 notifyRequester(request);
896 }
897 break;
898 }
899
900 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result;
905 } else {
906 // request.result must be set to something non-null
907 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700908 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700909 request.result = ar.result;
910 } else {
911 request.result = false;
912 }
913 if (ar.result == null) {
914 loge("isNRDualConnectivityEnabled: Empty response");
915 } else if (ar.exception instanceof CommandException) {
916 loge("isNRDualConnectivityEnabled: CommandException: "
917 + ar.exception);
918 } else {
919 loge("isNRDualConnectivityEnabled: Unknown exception");
920 }
921 }
922 notifyRequester(request);
923 break;
924
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700925 case CMD_IS_VONR_ENABLED: {
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
928 request);
929 Phone phone = getPhoneFromRequest(request);
930 if (phone != null) {
931 phone.isVoNrEnabled(onCompleted, request.workSource);
932 } else {
933 loge("isVoNrEnabled: No phone object");
934 request.result = false;
935 notifyRequester(request);
936 }
937 break;
938 }
939
940 case EVENT_IS_VONR_ENABLED_DONE:
941 ar = (AsyncResult) msg.obj;
942 request = (MainThreadRequest) ar.userObj;
943 if (ar.exception == null && ar.result != null) {
944 request.result = ar.result;
945 } else {
946 // request.result must be set to something non-null
947 // for the calling thread to unblock
948 if (ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = false;
952 }
953 if (ar.result == null) {
954 loge("isVoNrEnabled: Empty response");
955 } else if (ar.exception instanceof CommandException) {
956 loge("isVoNrEnabled: CommandException: "
957 + ar.exception);
958 } else {
959 loge("isVoNrEnabled: Unknown exception");
960 }
961 }
962 notifyRequester(request);
963 break;
964
Sooraj Sasindran37444802020-08-11 10:40:43 -0700965 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
971 request.workSource);
972 } else {
973 loge("enableNrDualConnectivity: No phone object");
974 request.result =
975 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null) {
985 request.result =
986 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
987 } else {
988 request.result =
989 TelephonyManager
990 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
991 if (ar.exception instanceof CommandException) {
992 CommandException.Error error =
993 ((CommandException) (ar.exception)).getCommandError();
994 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
995 request.result =
996 TelephonyManager
997 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000998 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
999 request.result =
1000 TelephonyManager
1001 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001002 }
1003 loge("enableNrDualConnectivity" + ": CommandException: "
1004 + ar.exception);
1005 } else {
1006 loge("enableNrDualConnectivity" + ": Unknown exception");
1007 }
1008 }
1009 notifyRequester(request);
1010 break;
1011 }
1012
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001013 case CMD_ENABLE_VONR: {
1014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1016 Phone phone = getPhoneFromRequest(request);
1017 if (phone != null) {
1018 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1019 request.workSource);
1020 } else {
1021 loge("setVoNrEnabled: No phone object");
1022 request.result =
1023 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1024 notifyRequester(request);
1025 }
1026 break;
1027 }
1028
1029 case EVENT_ENABLE_VONR_DONE: {
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception == null) {
1033 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1034 } else {
1035 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1040 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1041 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1042 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1043 } else {
1044 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1045 }
1046 loge("setVoNrEnabled" + ": CommandException: "
1047 + ar.exception);
1048 } else {
1049 loge("setVoNrEnabled" + ": Unknown exception");
1050 }
1051 }
1052 notifyRequester(request);
1053 break;
1054 }
1055
SongFerngWang3ef3e072020-12-21 16:41:52 +08001056 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001057 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001058 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1059 request);
1060 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001061 break;
1062
SongFerngWang3ef3e072020-12-21 16:41:52 +08001063 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null && ar.result != null) {
1067 request.result = ar.result; // Integer
1068 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301069 // request.result must be set to something non-null
1070 // for the calling thread to unblock
1071 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001073 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 loge("getAllowedNetworkTypesBitmask: CommandException: "
1076 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001078 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001079 }
1080 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001081 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 break;
1083
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1087 request);
1088 Pair<Integer, Long> reasonWithNetworkTypes =
1089 (Pair<Integer, Long>) request.argument;
1090 getPhoneFromRequest(request).setAllowedNetworkTypes(
1091 reasonWithNetworkTypes.first,
1092 reasonWithNetworkTypes.second,
1093 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 break;
1095
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1097 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 break;
1099
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001100 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1101 request = (MainThreadRequest)msg.obj;
1102 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001103 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001104 break;
1105
1106 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1107 ar = (AsyncResult)msg.obj;
1108 request = (MainThreadRequest)ar.userObj;
1109 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001111 break;
1112
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001113 case CMD_SET_VOICEMAIL_NUMBER:
1114 request = (MainThreadRequest) msg.obj;
1115 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1116 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001117 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1118 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001119 break;
1120
1121 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1122 handleNullReturnEvent(msg, "setVoicemailNumber");
1123 break;
1124
Stuart Scott54788802015-03-30 13:18:01 -07001125 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1128 request);
1129 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1130 break;
1131
1132 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1133 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1134 break;
1135
Shishir Agrawal302c8692015-06-19 13:49:39 -07001136 case CMD_PERFORM_NETWORK_SCAN:
1137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1139 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1140 break;
1141
Hall Liu27d24262020-09-18 19:04:59 -07001142 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001145 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1146 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1147 request.argument;
1148 int callForwardingReason = args.first;
1149 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001150 break;
Hall Liu27d24262020-09-18 19:04:59 -07001151 }
1152 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001155 TelephonyManager.CallForwardingInfoCallback callback =
1156 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1157 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001158 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001159 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001160 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1161 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1162 // Service Class is a bit mask per 3gpp 27.007. Search for
1163 // any service for voice call.
1164 if ((callForwardInfo.serviceClass
1165 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001166 callForwardingInfo = new CallForwardingInfo(
1167 callForwardInfo.status
1168 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001169 callForwardInfo.reason,
1170 callForwardInfo.number,
1171 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 break;
1173 }
1174 }
1175 // Didn't find a call forward info for voice call.
1176 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001177 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1178 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 }
Hall Liu27d24262020-09-18 19:04:59 -07001180 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 } else {
1182 if (ar.result == null) {
1183 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1184 }
1185 if (ar.exception != null) {
1186 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1187 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 int errorCode = TelephonyManager
1189 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 if (ar.exception instanceof CommandException) {
1191 CommandException.Error error =
1192 ((CommandException) (ar.exception)).getCommandError();
1193 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager
1195 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 }
1200 }
Hall Liu27d24262020-09-18 19:04:59 -07001201 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203 break;
Hall Liu27d24262020-09-18 19:04:59 -07001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205
Hall Liu27d24262020-09-18 19:04:59 -07001206 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001209 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001211 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1212 request.argument).first;
1213 request.phone.setCallForwardingOption(
1214 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001215 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001216 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001217 callForwardingInfoToSet.getReason(),
1218 callForwardingInfoToSet.getNumber(),
1219 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1220 break;
Hall Liu27d24262020-09-18 19:04:59 -07001221 }
Shuo Qian4a594052020-01-23 11:59:30 -08001222
Hall Liu27d24262020-09-18 19:04:59 -07001223 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001226 Consumer<Integer> callback =
1227 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1228 request.argument).second;
1229 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 int errorCode = TelephonyManager.CallForwardingInfoCallback
1232 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001233 if (ar.exception instanceof CommandException) {
1234 CommandException.Error error =
1235 ((CommandException) (ar.exception)).getCommandError();
1236 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 errorCode = TelephonyManager.CallForwardingInfoCallback
1238 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001239 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001242 }
1243 }
1244 callback.accept(errorCode);
1245 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1254 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001261 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001262 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001264 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 // Service Class is a bit mask per 3gpp 27.007.
1266 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001267 if (callForwardResults.length > 1
1268 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001269 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001270 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001271 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1272 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001274 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
1276 } else {
1277 if (ar.result == null) {
1278 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1279 }
1280 if (ar.exception != null) {
1281 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1282 }
1283 if (ar.exception instanceof CommandException) {
1284 CommandException.Error error =
1285 ((CommandException) (ar.exception)).getCommandError();
1286 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001287 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001288 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001289 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1290 callWaitingStatus =
1291 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001292 }
1293 }
1294 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001296 break;
Hall Liu27d24262020-09-18 19:04:59 -07001297 }
Shuo Qian4a594052020-01-23 11:59:30 -08001298
Hall Liu27d24262020-09-18 19:04:59 -07001299 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001300 request = (MainThreadRequest) msg.obj;
1301 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001302 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1303 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001310 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1311 Consumer<Integer> callback =
1312 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1313 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001314 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001315 if (ar.exception instanceof CommandException) {
1316 CommandException.Error error =
1317 ((CommandException) (ar.exception)).getCommandError();
1318 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1319 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1321 callback.accept(
1322 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001323 } else {
1324 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1325 }
1326 } else {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1328 }
1329 } else {
1330 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1331 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001332 }
Shuo Qian4a594052020-01-23 11:59:30 -08001333 break;
Hall Liu27d24262020-09-18 19:04:59 -07001334 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001335 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
1338 CellNetworkScanResult cellScanResult;
1339 if (ar.exception == null && ar.result != null) {
1340 cellScanResult = new CellNetworkScanResult(
1341 CellNetworkScanResult.STATUS_SUCCESS,
1342 (List<OperatorInfo>) ar.result);
1343 } else {
1344 if (ar.result == null) {
1345 loge("getCellNetworkScanResults: Empty response");
1346 }
1347 if (ar.exception != null) {
1348 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1349 }
1350 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1351 if (ar.exception instanceof CommandException) {
1352 CommandException.Error error =
1353 ((CommandException) (ar.exception)).getCommandError();
1354 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1355 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1356 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1357 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1358 }
1359 }
1360 cellScanResult = new CellNetworkScanResult(errorCode, null);
1361 }
1362 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001363 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001364 break;
1365
1366 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1367 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001368 ManualNetworkSelectionArgument selArg =
1369 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001370 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1371 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001372 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1373 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001374 break;
1375
1376 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 if (ar.exception == null) {
1380 request.result = true;
1381 } else {
1382 request.result = false;
1383 loge("setNetworkSelectionModeManual " + ar.exception);
1384 }
1385 notifyRequester(request);
1386 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001387 break;
1388
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 case CMD_GET_MODEM_ACTIVITY_INFO:
1390 request = (MainThreadRequest) msg.obj;
1391 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001392 if (defaultPhone != null) {
1393 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001394 } else {
1395 ResultReceiver result = (ResultReceiver) request.argument;
1396 Bundle bundle = new Bundle();
1397 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001398 new ModemActivityInfo(0, 0, 0,
1399 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001400 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001401 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001402 break;
1403
Hall Liud0f208c2020-10-14 16:54:44 -07001404 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001408 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001409 if (mLastModemActivityInfo == null) {
1410 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1411 mLastModemActivitySpecificInfo[0] =
1412 new ActivityStatsTechSpecificInfo(
1413 0,
1414 0,
1415 new int[ModemActivityInfo.getNumTxPowerLevels()],
1416 0);
1417 mLastModemActivityInfo =
1418 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1419 }
1420
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001421 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001422 // Update the last modem activity info and the result of the request.
1423 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1424 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001425 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001426 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001427 mLastModemActivityInfo =
1428 new ModemActivityInfo(
1429 mLastModemActivityInfo.getTimestampMillis(),
1430 mLastModemActivityInfo.getSleepTimeMillis(),
1431 mLastModemActivityInfo.getIdleTimeMillis(),
1432 mLastModemActivitySpecificInfo);
1433
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 } else {
1435 if (ar.result == null) {
1436 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001437 error = TelephonyManager.ModemActivityInfoException
1438 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001439 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001440 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001441 error = TelephonyManager.ModemActivityInfoException
1442 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 } else {
1444 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 }
1448 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001449 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001450 if (mLastModemActivityInfo != null) {
1451 bundle.putParcelable(
1452 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1453 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001454 } else {
1455 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1456 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001458 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001460 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461
Meng Wang1a7c35a2016-05-05 20:56:15 -07001462 case CMD_SET_ALLOWED_CARRIERS:
1463 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001464 CarrierRestrictionRules argument =
1465 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001466 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001467 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001468 break;
1469
1470 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
1473 if (ar.exception == null && ar.result != null) {
1474 request.result = ar.result;
1475 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001476 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1477 if (ar.exception instanceof CommandException) {
1478 loge("setAllowedCarriers: CommandException: " + ar.exception);
1479 CommandException.Error error =
1480 ((CommandException) (ar.exception)).getCommandError();
1481 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1482 request.result =
1483 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1484 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001485 } else {
1486 loge("setAllowedCarriers: Unknown exception");
1487 }
1488 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001489 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001490 break;
1491
1492 case CMD_GET_ALLOWED_CARRIERS:
1493 request = (MainThreadRequest) msg.obj;
1494 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001495 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001496 break;
1497
1498 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 if (ar.exception == null && ar.result != null) {
1502 request.result = ar.result;
1503 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001504 request.result = new IllegalStateException(
1505 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001506 if (ar.result == null) {
1507 loge("getAllowedCarriers: Empty response");
1508 } else if (ar.exception instanceof CommandException) {
1509 loge("getAllowedCarriers: CommandException: " +
1510 ar.exception);
1511 } else {
1512 loge("getAllowedCarriers: Unknown exception");
1513 }
1514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001515 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001516 break;
1517
Nathan Haroldb3014052017-01-25 15:57:32 -08001518 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1519 ar = (AsyncResult) msg.obj;
1520 request = (MainThreadRequest) ar.userObj;
1521 if (ar.exception == null && ar.result != null) {
1522 request.result = ar.result;
1523 } else {
1524 request.result = new IllegalArgumentException(
1525 "Failed to retrieve Forbidden Plmns");
1526 if (ar.result == null) {
1527 loge("getForbiddenPlmns: Empty response");
1528 } else {
1529 loge("getForbiddenPlmns: Unknown exception");
1530 }
1531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001532 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001533 break;
1534
1535 case CMD_GET_FORBIDDEN_PLMNS:
1536 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001537 uiccPort = getUiccPortFromRequest(request);
1538 if (uiccPort == null) {
1539 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001540 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001541 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001542 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001543 break;
1544 }
1545 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001546 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 if (uiccApp == null) {
1548 loge("getForbiddenPlmns() no app with specified type -- "
1549 + appType);
1550 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001551 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001552 break;
1553 } else {
1554 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1555 + " specified type -- " + appType);
1556 }
1557 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1558 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1559 onCompleted);
1560 break;
1561
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001562 case CMD_SWITCH_SLOTS:
1563 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001564 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001565 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001566 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001567 break;
1568
1569 case EVENT_SWITCH_SLOTS_DONE:
1570 ar = (AsyncResult) msg.obj;
1571 request = (MainThreadRequest) ar.userObj;
1572 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 notifyRequester(request);
1574 break;
1575 case CMD_GET_NETWORK_SELECTION_MODE:
1576 request = (MainThreadRequest) msg.obj;
1577 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1578 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1579 break;
1580
1581 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1582 ar = (AsyncResult) msg.obj;
1583 request = (MainThreadRequest) ar.userObj;
1584 if (ar.exception != null) {
1585 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1586 } else {
1587 int mode = ((int[]) ar.result)[0];
1588 if (mode == 0) {
1589 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1590 } else {
1591 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1592 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001593 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001594 notifyRequester(request);
1595 break;
1596 case CMD_GET_CDMA_ROAMING_MODE:
1597 request = (MainThreadRequest) msg.obj;
1598 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1599 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1600 break;
1601 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 if (ar.exception != null) {
1605 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1606 } else {
1607 request.result = ((int[]) ar.result)[0];
1608 }
1609 notifyRequester(request);
1610 break;
1611 case CMD_SET_CDMA_ROAMING_MODE:
1612 request = (MainThreadRequest) msg.obj;
1613 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1614 int mode = (int) request.argument;
1615 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1616 break;
1617 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 request.result = ar.exception == null;
1621 notifyRequester(request);
1622 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001623 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1624 request = (MainThreadRequest) msg.obj;
1625 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1626 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1627 break;
1628 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception != null) {
1632 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1633 } else {
1634 request.result = ((int[]) ar.result)[0];
1635 }
1636 notifyRequester(request);
1637 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1639 request = (MainThreadRequest) msg.obj;
1640 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1641 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001642 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1643 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001644 break;
1645 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
1648 request.result = ar.exception == null;
1649 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001650 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 case CMD_GET_ALL_CELL_INFO:
1652 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001653 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001654 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001655 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001656 case EVENT_GET_ALL_CELL_INFO_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001659 // If a timeout occurs, the response will be null
1660 request.result = (ar.exception == null && ar.result != null)
1661 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 synchronized (request) {
1663 request.notifyAll();
1664 }
1665 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001666 case CMD_REQUEST_CELL_INFO_UPDATE:
1667 request = (MainThreadRequest) msg.obj;
1668 request.phone.requestCellInfoUpdate(request.workSource,
1669 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1670 break;
1671 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1672 ar = (AsyncResult) msg.obj;
1673 request = (MainThreadRequest) ar.userObj;
1674 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1675 try {
1676 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001677 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001678 cb.onError(
1679 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1680 ar.exception.getClass().getName(),
1681 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001682 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001683 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001684 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 } else {
1686 // use the result as returned
1687 cb.onCellInfo((List<CellInfo>) ar.result);
1688 }
1689 } catch (RemoteException re) {
1690 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1691 }
1692 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001693 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 request = (MainThreadRequest) msg.obj;
1695 WorkSource ws = (WorkSource) request.argument;
1696 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001697 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001698 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001699 }
1700 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 if (ar.exception == null) {
1704 request.result = ar.result;
1705 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001706 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001707 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001708 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 }
1710
1711 synchronized (request) {
1712 request.notifyAll();
1713 }
1714 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001715 }
chen xu6dac5ab2018-10-26 17:39:23 -07001716 case CMD_MODEM_REBOOT:
1717 request = (MainThreadRequest) msg.obj;
1718 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001719 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001720 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001721 case EVENT_CMD_MODEM_REBOOT_DONE:
1722 handleNullReturnEvent(msg, "rebootModem");
1723 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001724 case CMD_REQUEST_ENABLE_MODEM:
1725 request = (MainThreadRequest) msg.obj;
1726 boolean enable = (boolean) request.argument;
1727 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001728 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001729 PhoneConfigurationManager.getInstance()
1730 .enablePhone(request.phone, enable, onCompleted);
1731 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001732 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001736 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001737 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001738 if ((boolean) request.result) {
1739 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1740 updateModemStateMetrics();
1741 } else {
1742 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1743 + ar.exception);
1744 }
1745 notifyRequester(request);
1746 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001747 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001748 case CMD_GET_MODEM_STATUS:
1749 request = (MainThreadRequest) msg.obj;
1750 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1751 PhoneConfigurationManager.getInstance()
1752 .getPhoneStatusFromModem(request.phone, onCompleted);
1753 break;
1754 case EVENT_GET_MODEM_STATUS_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 int id = request.phone.getPhoneId();
1758 if (ar.exception == null && ar.result != null) {
1759 request.result = ar.result;
1760 //update the cache as modem status has changed
1761 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1762 (boolean) request.result);
1763 } else {
1764 // Return true if modem status cannot be retrieved. For most cases,
1765 // modem status is on. And for older version modems, GET_MODEM_STATUS
1766 // and disable modem are not supported. Modem is always on.
1767 // TODO: this should be fixed in R to support a third
1768 // status UNKNOWN b/131631629
1769 request.result = true;
1770 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1771 + ar.exception);
1772 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001773 notifyRequester(request);
1774 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001775 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1776 request = (MainThreadRequest) msg.obj;
1777 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1778 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1779 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1780 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1781 break;
1782 }
1783 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1787 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1788 args.second.accept(ar.exception == null);
1789 notifyRequester(request);
1790 break;
1791 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001792 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1793 request = (MainThreadRequest) msg.obj;
1794 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1795 Phone phone = getPhoneFromRequest(request);
1796 if (phone != null) {
1797 phone.getSystemSelectionChannels(onCompleted);
1798 } else {
1799 loge("getSystemSelectionChannels: No phone object");
1800 request.result = new ArrayList<RadioAccessSpecifier>();
1801 notifyRequester(request);
1802 }
1803 break;
1804 }
1805 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1806 ar = (AsyncResult) msg.obj;
1807 request = (MainThreadRequest) ar.userObj;
1808 if (ar.exception == null && ar.result != null) {
1809 request.result = ar.result;
1810 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001811 request.result = new IllegalStateException(
1812 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001813 if (ar.result == null) {
1814 loge("getSystemSelectionChannels: Empty response");
1815 } else {
1816 loge("getSystemSelectionChannels: Unknown exception");
1817 }
1818 }
1819 notifyRequester(request);
1820 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001821 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1822 ar = (AsyncResult) msg.obj;
1823 request = (MainThreadRequest) ar.userObj;
1824 if (ar.exception == null && ar.result != null) {
1825 request.result = ar.result;
1826 } else {
1827 request.result = -1;
1828 loge("Failed to set Forbidden Plmns");
1829 if (ar.result == null) {
1830 loge("setForbidenPlmns: Empty response");
1831 } else if (ar.exception != null) {
1832 loge("setForbiddenPlmns: Exception: " + ar.exception);
1833 request.result = -1;
1834 } else {
1835 loge("setForbiddenPlmns: Unknown exception");
1836 }
1837 }
1838 notifyRequester(request);
1839 break;
1840 case CMD_SET_FORBIDDEN_PLMNS:
1841 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001842 uiccPort = getUiccPortFromRequest(request);
1843 if (uiccPort == null) {
1844 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001845 request.result = -1;
1846 notifyRequester(request);
1847 break;
1848 }
1849 Pair<Integer, List<String>> setFplmnsArgs =
1850 (Pair<Integer, List<String>>) request.argument;
1851 appType = setFplmnsArgs.first;
1852 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001853 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001854 if (uiccApp == null) {
1855 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1856 request.result = -1;
1857 loge("Failed to get UICC App");
1858 notifyRequester(request);
1859 } else {
1860 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1861 ((SIMRecords) uiccApp.getIccRecords())
1862 .setForbiddenPlmns(onCompleted, fplmns);
1863 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001864 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001865 case CMD_ERASE_MODEM_CONFIG:
1866 request = (MainThreadRequest) msg.obj;
1867 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1868 defaultPhone.eraseModemConfig(onCompleted);
1869 break;
1870 case EVENT_ERASE_MODEM_CONFIG_DONE:
1871 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001872 break;
zoey chene02881a2019-12-30 16:11:23 +08001873
Kai Shif70f46f2021-03-03 13:59:46 -08001874 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1875 request = (MainThreadRequest) msg.obj;
1876 request.result = defaultPhone.eraseDataInSharedPreferences();
1877 notifyRequester(request);
1878 break;
1879
zoey chene02881a2019-12-30 16:11:23 +08001880 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1883 Pair<String, String> changed = (Pair<String, String>) request.argument;
1884 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1885 changed.first, changed.second, onCompleted);
1886 break;
1887 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890 if (ar.exception == null) {
1891 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001892 // If the operation is successful, update the PIN storage
1893 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1894 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001895 UiccController.getInstance().getPinStorage()
1896 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001897 } else {
1898 request.result = msg.arg1;
1899 }
1900 notifyRequester(request);
1901 break;
1902
Michele Berionne5e411512020-11-13 02:36:59 +00001903 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001904 request = (MainThreadRequest) msg.obj;
1905 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1906 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1907 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1908 enabled.first, enabled.second, onCompleted);
1909 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001910 }
zoey chene02881a2019-12-30 16:11:23 +08001911 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1912 ar = (AsyncResult) msg.obj;
1913 request = (MainThreadRequest) ar.userObj;
1914 if (ar.exception == null) {
1915 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001916 // If the operation is successful, update the PIN storage
1917 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1918 int phoneId = getPhoneFromRequest(request).getPhoneId();
1919 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001920 UiccController.getInstance().getPinStorage()
1921 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001922 } else {
1923 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1924 }
zoey chene02881a2019-12-30 16:11:23 +08001925 } else {
1926 request.result = msg.arg1;
1927 }
Michele Berionne5e411512020-11-13 02:36:59 +00001928
1929
zoey chene02881a2019-12-30 16:11:23 +08001930 notifyRequester(request);
1931 break;
1932
Peter Wangdafb9ac2020-01-15 14:13:38 -08001933 case MSG_NOTIFY_USER_ACTIVITY:
1934 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001935 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001936 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1937 getDefaultPhone().getContext().sendBroadcastAsUser(
1938 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1939 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001940
1941 case CMD_SET_DATA_THROTTLING: {
1942 request = (MainThreadRequest) msg.obj;
1943 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1944 DataThrottlingRequest dataThrottlingRequest =
1945 (DataThrottlingRequest) request.argument;
1946 Phone phone = getPhoneFromRequest(request);
1947 if (phone != null) {
1948 phone.setDataThrottling(onCompleted,
1949 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1950 dataThrottlingRequest.getCompletionDurationMillis());
1951 } else {
1952 loge("setDataThrottling: No phone object");
1953 request.result =
1954 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1955 notifyRequester(request);
1956 }
1957
1958 break;
1959 }
1960 case EVENT_SET_DATA_THROTTLING_DONE:
1961 ar = (AsyncResult) msg.obj;
1962 request = (MainThreadRequest) ar.userObj;
1963
1964 if (ar.exception == null) {
1965 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1966 } else if (ar.exception instanceof CommandException) {
1967 loge("setDataThrottling: CommandException: " + ar.exception);
1968 CommandException.Error error =
1969 ((CommandException) (ar.exception)).getCommandError();
1970
1971 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1972 request.result = TelephonyManager
1973 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1974 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1975 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001976 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1977 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001978 } else {
1979 request.result =
1980 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1981 }
1982 } else {
1983 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1984 }
1985 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1986 notifyRequester(request);
1987 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001988
1989 case CMD_SET_SIM_POWER: {
1990 request = (MainThreadRequest) msg.obj;
1991 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1992 request = (MainThreadRequest) msg.obj;
1993 int stateToSet =
1994 ((Pair<Integer, IIntegerConsumer>)
1995 request.argument).first;
1996 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1997 break;
1998 }
1999 case EVENT_SET_SIM_POWER_DONE: {
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 IIntegerConsumer callback =
2003 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2004 if (ar.exception != null) {
2005 loge("setSimPower exception: " + ar.exception);
2006 int errorCode = TelephonyManager.CallForwardingInfoCallback
2007 .RESULT_ERROR_UNKNOWN;
2008 if (ar.exception instanceof CommandException) {
2009 CommandException.Error error =
2010 ((CommandException) (ar.exception)).getCommandError();
2011 if (error == CommandException.Error.SIM_ERR) {
2012 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2013 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2014 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2015 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2016 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2017 } else {
2018 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2019 }
2020 }
2021 try {
2022 callback.accept(errorCode);
2023 } catch (RemoteException e) {
2024 // Ignore if the remote process is no longer available to call back.
2025 Log.w(LOG_TAG, "setSimPower: callback not available.");
2026 }
2027 } else {
2028 try {
2029 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2030 } catch (RemoteException e) {
2031 // Ignore if the remote process is no longer available to call back.
2032 Log.w(LOG_TAG, "setSimPower: callback not available.");
2033 }
2034 }
2035 break;
2036 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002037 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2038 request = (MainThreadRequest) msg.obj;
2039
2040 final Phone phone = getPhoneFromRequest(request);
2041 if (phone == null || phone.getServiceStateTracker() == null) {
2042 request.result = new IllegalStateException("Phone or SST is null");
2043 notifyRequester(request);
2044 break;
2045 }
2046
2047 Pair<Integer, SignalStrengthUpdateRequest> pair =
2048 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2049 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2050 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002051 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002052 request.subId, pair.first /*callingUid*/,
2053 pair.second /*request*/, onCompleted);
2054 break;
2055 }
2056 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2057 ar = (AsyncResult) msg.obj;
2058 request = (MainThreadRequest) ar.userObj;
2059 // request.result will be the exception of ar if present, true otherwise.
2060 // Be cautious not to leave result null which will wait() forever
2061 request.result = ar.exception != null ? ar.exception : true;
2062 notifyRequester(request);
2063 break;
2064 }
2065 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2066 request = (MainThreadRequest) msg.obj;
2067
2068 Phone phone = getPhoneFromRequest(request);
2069 if (phone == null || phone.getServiceStateTracker() == null) {
2070 request.result = new IllegalStateException("Phone or SST is null");
2071 notifyRequester(request);
2072 break;
2073 }
2074
2075 Pair<Integer, SignalStrengthUpdateRequest> pair =
2076 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2077 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2078 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002079 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002080 request.subId, pair.first /*callingUid*/,
2081 pair.second /*request*/, onCompleted);
2082 break;
2083 }
2084 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2085 ar = (AsyncResult) msg.obj;
2086 request = (MainThreadRequest) ar.userObj;
2087 request.result = ar.exception != null ? ar.exception : true;
2088 notifyRequester(request);
2089 break;
2090 }
Jordan Liu109698e2020-11-24 14:50:34 -08002091
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002092 case CMD_GET_SLICING_CONFIG: {
2093 request = (MainThreadRequest) msg.obj;
2094 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2095 request.phone.getSlicingConfig(onCompleted);
2096 break;
2097 }
2098 case EVENT_GET_SLICING_CONFIG_DONE: {
2099 ar = (AsyncResult) msg.obj;
2100 request = (MainThreadRequest) ar.userObj;
2101 ResultReceiver result = (ResultReceiver) request.argument;
2102
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002103 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002104 Bundle bundle = new Bundle();
2105 int resultCode = 0;
2106 if (ar.exception != null) {
2107 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2108 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002109 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002110 } else if (ar.result == null) {
2111 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002112 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 } else {
2114 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002115 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2116 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002117 }
2118
2119 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002120 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 }
2122 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2123 result.send(resultCode, bundle);
2124 notifyRequester(request);
2125 break;
2126 }
2127
Michele Berionne5e411512020-11-13 02:36:59 +00002128 case CMD_PREPARE_UNATTENDED_REBOOT:
2129 request = (MainThreadRequest) msg.obj;
2130 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002131 UiccController.getInstance().getPinStorage()
2132 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002133 notifyRequester(request);
2134 break;
2135
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 default:
2137 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2138 break;
2139 }
2140 }
Jake Hambye994d462014-02-03 13:10:13 -08002141
Pengquan Menga1bb6272018-09-06 09:59:22 -07002142 private void notifyRequester(MainThreadRequest request) {
2143 synchronized (request) {
2144 request.notifyAll();
2145 }
2146 }
2147
Jake Hambye994d462014-02-03 13:10:13 -08002148 private void handleNullReturnEvent(Message msg, String command) {
2149 AsyncResult ar = (AsyncResult) msg.obj;
2150 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2151 if (ar.exception == null) {
2152 request.result = true;
2153 } else {
2154 request.result = false;
2155 if (ar.exception instanceof CommandException) {
2156 loge(command + ": CommandException: " + ar.exception);
2157 } else {
2158 loge(command + ": Unknown exception");
2159 }
2160 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002161 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 }
2164
2165 /**
2166 * Posts the specified command to be executed on the main thread,
2167 * waits for the request to complete, and returns the result.
2168 * @see #sendRequestAsync
2169 */
2170 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002171 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2172 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002173 }
2174
2175 /**
2176 * Posts the specified command to be executed on the main thread,
2177 * waits for the request to complete, and returns the result.
2178 * @see #sendRequestAsync
2179 */
2180 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2181 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002182 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002183 }
2184
2185 /**
2186 * Posts the specified command to be executed on the main thread,
2187 * waits for the request to complete, and returns the result.
2188 * @see #sendRequestAsync
2189 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002190 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002191 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2192 }
2193
2194 /**
2195 * Posts the specified command to be executed on the main thread,
2196 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2197 * if not timeout or null otherwise.
2198 * @see #sendRequestAsync
2199 */
2200 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2201 long timeoutInMs) {
2202 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002203 }
2204
2205 /**
2206 * Posts the specified command to be executed on the main thread,
2207 * waits for the request to complete, and returns the result.
2208 * @see #sendRequestAsync
2209 */
Nathan Harold92bed182018-10-12 18:16:49 -07002210 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002211 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -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 */
2219 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002220 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2221 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002222 }
2223
2224 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002225 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2226 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2227 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002228 * @see #sendRequestAsync
2229 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002230 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2231 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2233 throw new RuntimeException("This method will deadlock if called from the main thread.");
2234 }
2235
Nathan Harold92bed182018-10-12 18:16:49 -07002236 MainThreadRequest request = null;
2237 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2238 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2239 } else if (phone != null) {
2240 request = new MainThreadRequest(argument, phone, workSource);
2241 } else {
2242 request = new MainThreadRequest(argument, subId, workSource);
2243 }
2244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 Message msg = mMainThreadHandler.obtainMessage(command, request);
2246 msg.sendToTarget();
2247
Rambo Wang0f050d82021-02-12 11:43:36 -08002248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002250 if (timeoutInMs >= 0) {
2251 // Wait for at least timeoutInMs before returning null request result
2252 long now = SystemClock.elapsedRealtime();
2253 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002254 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002255 try {
2256 request.wait(deadline - now);
2257 } catch (InterruptedException e) {
2258 // Do nothing, go back and check if request is completed or timeout
2259 } finally {
2260 now = SystemClock.elapsedRealtime();
2261 }
2262 }
2263 } else {
2264 // Wait for the request to complete
2265 while (request.result == null) {
2266 try {
2267 request.wait();
2268 } catch (InterruptedException e) {
2269 // Do nothing, go back and wait until the request is complete
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272 }
2273 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002274 if (request.result == null) {
2275 Log.wtf(LOG_TAG,
2276 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 return request.result;
2279 }
2280
2281 /**
2282 * Asynchronous ("fire and forget") version of sendRequest():
2283 * Posts the specified command to be executed on the main thread, and
2284 * returns immediately.
2285 * @see #sendRequest
2286 */
2287 private void sendRequestAsync(int command) {
2288 mMainThreadHandler.sendEmptyMessage(command);
2289 }
2290
2291 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002292 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002293 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002294 */
2295 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002296 sendRequestAsync(command, argument, null, null);
2297 }
2298
2299 /**
2300 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2301 * @see {@link #sendRequest(int,Object)}
2302 */
2303 private void sendRequestAsync(
2304 int command, Object argument, Phone phone, WorkSource workSource) {
2305 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002306 Message msg = mMainThreadHandler.obtainMessage(command, request);
2307 msg.sendToTarget();
2308 }
2309
2310 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 * Initialize the singleton PhoneInterfaceManager instance.
2312 * This is only done once, at startup, from PhoneApp.onCreate().
2313 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002314 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 synchronized (PhoneInterfaceManager.class) {
2316 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002317 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 } else {
2319 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2320 }
2321 return sInstance;
2322 }
2323 }
2324
2325 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002326 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002329 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002330 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002332 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002334 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002335 mTelephonySharedPreferences =
2336 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002337 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002338 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002339 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002340 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002341 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 publish();
2343 }
2344
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002345 private Phone getDefaultPhone() {
2346 Phone thePhone = getPhone(getDefaultSubscription());
2347 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2348 }
2349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 private void publish() {
2351 if (DBG) log("publish: " + this);
2352
Peter Wangc035ce42020-01-08 21:00:22 -08002353 TelephonyFrameworkInitializer
2354 .getTelephonyServiceManager()
2355 .getTelephonyServiceRegisterer()
2356 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358
Stuart Scott584921c2015-01-15 17:10:34 -08002359 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002360 if (request.phone != null) {
2361 return request.phone;
2362 } else {
2363 return getPhoneFromSubId(request.subId);
2364 }
2365 }
2366
2367 private Phone getPhoneFromSubId(int subId) {
2368 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2369 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002370 }
2371
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002372 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002373 Phone phone = getPhoneFromRequest(request);
2374 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002375 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002376 }
2377
Wink Saville36469e72014-06-11 15:17:00 -07002378 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002379 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002380 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382
Kai Shif70f46f2021-03-03 13:59:46 -08002383 private void sendEraseModemConfig(@NonNull Phone phone) {
2384 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2385 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2386 }
2387
2388 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2389 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2390 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002391 }
2392
Peter Wang44b186e2020-01-13 23:33:09 -08002393 private boolean isImsAvailableOnDevice() {
2394 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2395 if (pm == null) {
2396 // For some reason package manger is not available.. This will fail internally anyway,
2397 // so do not throw error and allow.
2398 return true;
2399 }
2400 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2401 }
2402
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002404 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002405 }
2406
Wink Savilleb564aae2014-10-23 10:18:09 -07002407 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 if (DBG) log("dial: " + number);
2409 // No permission check needed here: This is just a wrapper around the
2410 // ACTION_DIAL intent, which is available to any app since it puts up
2411 // the UI before it does anything.
2412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 String url = createTelUrl(number);
2416 if (url == null) {
2417 return;
2418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420 // PENDING: should we just silently fail if phone is offhook or ringing?
2421 PhoneConstants.State state = mCM.getState(subId);
2422 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2423 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2424 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2425 mApp.startActivity(intent);
2426 }
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430 }
2431
2432 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002433 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002434 }
2435
Wink Savilleb564aae2014-10-23 10:18:09 -07002436 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 if (DBG) log("call: " + number);
2438
2439 // This is just a wrapper around the ACTION_CALL intent, but we still
2440 // need to do a permission check since we're calling startActivity()
2441 // from the context of the phone app.
2442 enforceCallPermission();
2443
Jordan Liu1617b712019-07-10 15:06:26 -07002444 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 != AppOpsManager.MODE_ALLOWED) {
2446 return;
2447 }
2448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 String url = createTelUrl(number);
2452 if (url == null) {
2453 return;
2454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 boolean isValid = false;
2457 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2458 if (slist != null) {
2459 for (SubscriptionInfo subInfoRecord : slist) {
2460 if (subInfoRecord.getSubscriptionId() == subId) {
2461 isValid = true;
2462 break;
2463 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002464 }
Wink Saville08874612014-08-31 19:19:58 -07002465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 if (!isValid) {
2467 return;
2468 }
Wink Saville08874612014-08-31 19:19:58 -07002469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2471 intent.putExtra(SUBSCRIPTION_KEY, subId);
2472 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2473 mApp.startActivity(intent);
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
2476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Wink Savilleb564aae2014-10-23 10:18:09 -07002479 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002480 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002481 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2482 }
2483
Wink Savilleb564aae2014-10-23 10:18:09 -07002484 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002485 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002486 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2487 }
2488
Wink Savilleb564aae2014-10-23 10:18:09 -07002489 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002494 Phone phone = getPhone(subId);
2495 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 checkSimPin.start();
2497 return checkSimPin.unlockSim(null, pin);
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
2500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002508 Phone phone = getPhone(subId);
2509 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 checkSimPuk.start();
2511 return checkSimPuk.unlockSim(puk, pin);
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
2517 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002518 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 * a synchronous one.
2520 */
2521 private static class UnlockSim extends Thread {
2522
2523 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002524 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525
2526 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002527 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2528 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529
2530 // For replies from SimCard interface
2531 private Handler mHandler;
2532
2533 // For async handler to identify request type
2534 private static final int SUPPLY_PIN_COMPLETE = 100;
2535
Michele Berionne5e411512020-11-13 02:36:59 +00002536 UnlockSim(int phoneId, IccCard simCard) {
2537 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 mSimCard = simCard;
2539 }
2540
2541 @Override
2542 public void run() {
2543 Looper.prepare();
2544 synchronized (UnlockSim.this) {
2545 mHandler = new Handler() {
2546 @Override
2547 public void handleMessage(Message msg) {
2548 AsyncResult ar = (AsyncResult) msg.obj;
2549 switch (msg.what) {
2550 case SUPPLY_PIN_COMPLETE:
2551 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2552 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002553 mRetryCount = msg.arg1;
2554 if (ar.exception != null) {
2555 if (ar.exception instanceof CommandException &&
2556 ((CommandException)(ar.exception)).getCommandError()
2557 == CommandException.Error.PASSWORD_INCORRECT) {
2558 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002559 } //When UiccCardApp dispose,handle message and return exception
2560 else if (ar.exception instanceof CommandException &&
2561 ((CommandException) (ar.exception)).getCommandError()
2562 == CommandException.Error.ABORTED) {
2563 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002564 } else {
2565 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2566 }
2567 } else {
2568 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 mDone = true;
2571 UnlockSim.this.notifyAll();
2572 }
2573 break;
2574 }
2575 }
2576 };
2577 UnlockSim.this.notifyAll();
2578 }
2579 Looper.loop();
2580 }
2581
2582 /*
2583 * Use PIN or PUK to unlock SIM card
2584 *
2585 * If PUK is null, unlock SIM card with PIN
2586 *
2587 * If PUK is not null, unlock SIM card with PUK and set PIN code
2588 */
Wink Saville9de0f752013-10-22 19:04:03 -07002589 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590
2591 while (mHandler == null) {
2592 try {
2593 wait();
2594 } catch (InterruptedException e) {
2595 Thread.currentThread().interrupt();
2596 }
2597 }
2598 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2599
2600 if (puk == null) {
2601 mSimCard.supplyPin(pin, callback);
2602 } else {
2603 mSimCard.supplyPuk(puk, pin, callback);
2604 }
2605
2606 while (!mDone) {
2607 try {
2608 Log.d(LOG_TAG, "wait for done");
2609 wait();
2610 } catch (InterruptedException e) {
2611 // Restore the interrupted status
2612 Thread.currentThread().interrupt();
2613 }
2614 }
2615 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002616 int[] resultArray = new int[2];
2617 resultArray[0] = mResult;
2618 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002619
2620 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002621 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002622 }
2623
Wink Saville9de0f752013-10-22 19:04:03 -07002624 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626 }
2627
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002628 /**
2629 * This method has been removed due to privacy and stability concerns.
2630 */
2631 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002633 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2634 return;
Wink Saville36469e72014-06-11 15:17:00 -07002635 }
2636
Nathan Harold1f889d82020-06-04 17:05:26 -07002637 @Override
2638 public void updateServiceLocationWithPackageName(String callingPackage) {
2639 mApp.getSystemService(AppOpsManager.class)
2640 .checkPackage(Binder.getCallingUid(), callingPackage);
2641
Nathan Haroldf096d982020-11-18 17:18:06 -08002642 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002643 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2644 // Callers targeting S have no business invoking this method.
2645 return;
2646 }
2647
2648 LocationAccessPolicy.LocationPermissionResult locationResult =
2649 LocationAccessPolicy.checkLocationPermission(mApp,
2650 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2651 .setCallingPackage(callingPackage)
2652 .setCallingFeatureId(null)
2653 .setCallingPid(Binder.getCallingPid())
2654 .setCallingUid(Binder.getCallingUid())
2655 .setMethod("updateServiceLocation")
2656 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2657 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2658 .build());
2659 // Apps that lack location permission have no business calling this method;
2660 // however, because no permission was declared in the public API, denials must
2661 // all be "soft".
2662 switch (locationResult) {
2663 case DENIED_HARD: /* fall through */
2664 case DENIED_SOFT:
2665 return;
2666 }
2667
2668 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 final long identity = Binder.clearCallingIdentity();
2670 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002671 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002673 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002680 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002681 @Override
2682 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002683 return isRadioOnWithFeature(callingPackage, null);
2684 }
2685
2686
2687 @Override
2688 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2689 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2690 callingFeatureId);
2691 }
2692
2693 @Deprecated
2694 @Override
2695 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2696 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002697 }
2698
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002700 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2701 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002703 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002704 return false;
2705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706
2707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 return isRadioOnForSubscriber(subId);
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
2712 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002713 }
2714
2715 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 final Phone phone = getPhone(subId);
2719 if (phone != null) {
2720 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2721 } else {
2722 return false;
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
2728
2729 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002730 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 }
Wink Saville36469e72014-06-11 15:17:00 -07002732
Wink Savilleb564aae2014-10-23 10:18:09 -07002733 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
2736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 final Phone phone = getPhone(subId);
2739 if (phone != null) {
2740 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 }
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
2747 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002748 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002749 }
2750
Wink Savilleb564aae2014-10-23 10:18:09 -07002751 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 final Phone phone = getPhone(subId);
2757 if (phone == null) {
2758 return false;
2759 }
2760 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2761 toggleRadioOnOffForSubscriber(subId);
2762 }
2763 return true;
2764 } finally {
2765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 }
Wink Saville36469e72014-06-11 15:17:00 -07002768
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002769 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002770 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002771 /*
2772 * If any of the Radios are available, it will need to be
2773 * shutdown. So return true if any Radio is available.
2774 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2778 Phone phone = PhoneFactory.getPhone(i);
2779 if (phone != null && phone.isRadioAvailable()) return true;
2780 }
2781 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2782 return false;
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002786 }
2787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002789 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 enforceModifyPermission();
2791
2792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2795 logv("Shutting down Phone " + i);
2796 shutdownRadioUsingPhoneId(i);
2797 }
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 }
2801 }
2802
2803 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002804 Phone phone = PhoneFactory.getPhone(phoneId);
2805 if (phone != null && phone.isRadioAvailable()) {
2806 phone.shutdownRadio();
2807 }
2808 }
2809
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812
2813 final long identity = Binder.clearCallingIdentity();
2814 try {
2815 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2816 if (defaultPhone != null) {
2817 defaultPhone.setRadioPower(turnOn);
2818 return true;
2819 } else {
2820 loge("There's no default phone.");
2821 return false;
2822 }
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002825 }
Wink Saville36469e72014-06-11 15:17:00 -07002826 }
2827
Wink Savilleb564aae2014-10-23 10:18:09 -07002828 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830
2831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 final Phone phone = getPhone(subId);
2834 if (phone != null) {
2835 phone.setRadioPower(turnOn);
2836 return true;
2837 } else {
2838 return false;
2839 }
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 }
2844
Wink Saville36469e72014-06-11 15:17:00 -07002845 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002847 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 int subId = mSubscriptionController.getDefaultDataSubId();
2853 final Phone phone = getPhone(subId);
2854 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002855 if (phone.isUsingNewDataStack()) {
2856 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002857 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002858 } else {
2859 phone.getDataEnabledSettings().setDataEnabled(
2860 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 return true;
2863 } else {
2864 return false;
2865 }
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 }
2870
Wink Saville36469e72014-06-11 15:17:00 -07002871 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002872 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002873 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875
2876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 int subId = mSubscriptionController.getDefaultDataSubId();
2879 final Phone phone = getPhone(subId);
2880 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002881 if (phone.isUsingNewDataStack()) {
2882 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002883 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002884 } else {
2885 phone.getDataEnabledSettings().setDataEnabled(
2886 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888 return true;
2889 } else {
2890 return false;
2891 }
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002898 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 final Phone phone = getPhone(subId);
2902 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002903 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 } else {
2905 return false;
2906 }
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
2912 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002913 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002914 }
2915
pkanwarae03a6b2016-11-06 20:37:09 -08002916 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 enforceCallPermission();
2918
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2922 return;
2923 }
2924 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2925 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
pkanwar32d516d2016-10-14 19:37:38 -07002929 };
2930
Wink Savilleb564aae2014-10-23 10:18:09 -07002931 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2937 return false;
2938 }
2939 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 }
2944
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002945 /**
2946 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2947 * tag on getCallState Binder call.
2948 */
2949 @Deprecated
2950 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002952 if (CompatChanges.isChangeEnabled(
2953 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2954 Binder.getCallingUid())) {
2955 // Do not allow this API to be called on API version 31+, it should only be
2956 // called on old apps using this Binder call directly.
2957 throw new SecurityException("This method can only be used for applications "
2958 + "targeting API version 30 or less.");
2959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 final long identity = Binder.clearCallingIdentity();
2961 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002962 Phone phone = getPhone(getDefaultSubscription());
2963 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2964 PhoneConstantConversions.convertCallState(phone.getState());
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
2968 }
2969
2970 @Override
2971 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2972 if (CompatChanges.isChangeEnabled(
2973 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2974 Binder.getCallingUid())) {
2975 // Check READ_PHONE_STATE for API version 31+
2976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2977 featureId, "getCallStateForSubscription")) {
2978 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2979 + "targeting API level 31+.");
2980 }
2981 }
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2986 PhoneConstantConversions.convertCallState(phone.getState());
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 }
2991
Sanket Padawe356d7632015-06-22 14:03:32 -07002992 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002993 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002994 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2995 }
2996
2997 @Override
2998 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 final long identity = Binder.clearCallingIdentity();
3000 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003001 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003003 if (phone.isUsingNewDataStack()) {
3004 return phone.getDataNetworkController().getInternetDataNetworkState();
3005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3007 } else {
3008 return PhoneConstantConversions.convertDataState(
3009 PhoneConstants.DataState.DISCONNECTED);
3010 }
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003014 }
3015
Sanket Padawe356d7632015-06-22 14:03:32 -07003016 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003017 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003018 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3019 }
3020
3021 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003022 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 final long identity = Binder.clearCallingIdentity();
3024 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003025 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003027 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 } else {
3029 return TelephonyManager.DATA_ACTIVITY_NONE;
3030 }
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003034 }
3035
3036 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003037 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003038 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003039 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003040
3041 LocationAccessPolicy.LocationPermissionResult locationResult =
3042 LocationAccessPolicy.checkLocationPermission(mApp,
3043 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3044 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003045 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003046 .setCallingPid(Binder.getCallingPid())
3047 .setCallingUid(Binder.getCallingUid())
3048 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003049 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003050 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3051 .build());
3052 switch (locationResult) {
3053 case DENIED_HARD:
3054 throw new SecurityException("Not allowed to access cell location");
3055 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003056 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3057 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 }
3059
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003064 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003065 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Svetoslav64fad262015-04-14 14:35:21 -07003069 }
3070
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003072 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003073 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3074 // registered cell info, so return a NULL country instead.
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003077 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3078 // Get default phone in this case.
3079 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3080 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003081 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003083 if (phone == null) return "";
3084 ServiceStateTracker sst = phone.getServiceStateTracker();
3085 if (sst == null) return "";
3086 LocaleTracker lt = sst.getLocaleTracker();
3087 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003088 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003092 }
3093
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003094 /**
3095 * This method was removed due to potential issues caused by performing partial
3096 * updates of service state, and lack of a credible use case.
3097 *
3098 * This has the ability to break the telephony implementation by disabling notification of
3099 * changes in device connectivity. DO NOT USE THIS!
3100 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003101 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 public void enableLocationUpdates() {
3103 mApp.enforceCallingOrSelfPermission(
3104 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -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 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 @Override
3115 public void disableLocationUpdates() {
3116 mApp.enforceCallingOrSelfPermission(
3117 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 }
3119
3120 @Override
3121 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003122 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3123 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003124 try {
3125 mApp.getSystemService(AppOpsManager.class)
3126 .checkPackage(Binder.getCallingUid(), callingPackage);
3127 } catch (SecurityException e) {
3128 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3129 throw e;
3130 }
3131
Nathan Haroldf096d982020-11-18 17:18:06 -08003132 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003133 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3134 throw new SecurityException(
3135 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3136 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003137
Jordan Liu1617b712019-07-10 15:06:26 -07003138 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003139 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3140 return null;
3141 }
Svetoslav64fad262015-04-14 14:35:21 -07003142
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003143 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003145 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003146 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147
Nathan Haroldf180aac2018-06-01 18:43:55 -07003148 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3149 for (CellInfo ci : info) {
3150 if (ci instanceof CellInfoGsm) {
3151 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3152 } else if (ci instanceof CellInfoWcdma) {
3153 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003155 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003156 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003159 private List<CellInfo> getCachedCellInfo() {
3160 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3161 for (Phone phone : PhoneFactory.getPhones()) {
3162 List<CellInfo> info = phone.getAllCellInfo();
3163 if (info != null) cellInfos.addAll(info);
3164 }
3165 return cellInfos;
3166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167
3168 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003169 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003170 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003171 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003172
3173 LocationAccessPolicy.LocationPermissionResult locationResult =
3174 LocationAccessPolicy.checkLocationPermission(mApp,
3175 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3176 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003177 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003178 .setCallingPid(Binder.getCallingPid())
3179 .setCallingUid(Binder.getCallingUid())
3180 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003181 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003182 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3183 .build());
3184 switch (locationResult) {
3185 case DENIED_HARD:
3186 throw new SecurityException("Not allowed to access cell info");
3187 case DENIED_SOFT:
3188 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 }
3190
Nathan Haroldf096d982020-11-18 17:18:06 -08003191 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003192 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3193 return getCachedCellInfo();
3194 }
3195
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003196 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003197 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3201 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003202 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003203 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 if (info != null) cellInfos.addAll(info);
3205 }
3206 return cellInfos;
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 }
3210 }
3211
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003212 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003213 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3214 String callingFeatureId) {
3215 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3216 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003217 }
3218
3219 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003220 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3221 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003222 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003224 }
3225
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003226 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3227 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003229 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003230
3231 LocationAccessPolicy.LocationPermissionResult locationResult =
3232 LocationAccessPolicy.checkLocationPermission(mApp,
3233 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3234 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003235 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003236 .setCallingPid(Binder.getCallingPid())
3237 .setCallingUid(Binder.getCallingUid())
3238 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003239 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3240 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003241 .build());
3242 switch (locationResult) {
3243 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003244 if (TelephonyPermissions
3245 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003246 // Safetynet logging for b/154934934
3247 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3248 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003249 throw new SecurityException("Not allowed to access cell info");
3250 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003251 if (TelephonyPermissions
3252 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003253 // Safetynet logging for b/154934934
3254 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3255 }
Nathan Harold5320c422019-05-09 10:26:08 -07003256 try {
3257 cb.onCellInfo(new ArrayList<CellInfo>());
3258 } catch (RemoteException re) {
3259 // Drop without consequences
3260 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003261 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003262 }
3263
Nathan Harolda939a962019-05-09 10:13:47 -07003264
3265 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003266 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3267
3268 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3269 }
3270
3271 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003273 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275
3276 final long identity = Binder.clearCallingIdentity();
3277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003278 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 }
3283
Shishir Agrawala9f32182016-04-12 12:00:16 -07003284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003285 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003286 Phone phone = PhoneFactory.getPhone(slotIndex);
3287 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003288 return null;
3289 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003290 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003291 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003292 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003293 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003294 return null;
3295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 return phone.getImei();
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
3302 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003303 }
3304
3305 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003306 public String getTypeAllocationCodeForSlot(int slotIndex) {
3307 Phone phone = PhoneFactory.getPhone(slotIndex);
3308 String tac = null;
3309 if (phone != null) {
3310 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003311 try {
3312 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3313 } catch (IndexOutOfBoundsException e) {
3314 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3315 return null;
3316 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003317 }
3318 return tac;
3319 }
3320
3321 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003322 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003323 try {
3324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3325 } catch (SecurityException se) {
3326 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3327 throw new SecurityException("Package " + callingPackage + " does not belong to "
3328 + Binder.getCallingUid());
3329 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003330 Phone phone = PhoneFactory.getPhone(slotIndex);
3331 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003332 return null;
3333 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334
Jeff Davidson913390f2018-02-23 17:11:49 -08003335 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003336 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003337 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003338 return null;
3339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 return phone.getMeid();
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
Jack Yu2af8d712017-03-15 17:14:14 -07003347 }
3348
3349 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003350 public String getManufacturerCodeForSlot(int slotIndex) {
3351 Phone phone = PhoneFactory.getPhone(slotIndex);
3352 String manufacturerCode = null;
3353 if (phone != null) {
3354 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003355 try {
3356 manufacturerCode =
3357 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3358 } catch (IndexOutOfBoundsException e) {
3359 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3360 return null;
3361 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003362 }
3363 return manufacturerCode;
3364 }
3365
3366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003367 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3368 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003369 Phone phone = PhoneFactory.getPhone(slotIndex);
3370 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 return null;
3372 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003373 int subId = phone.getSubId();
3374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003375 mApp, subId, callingPackage, callingFeatureId,
3376 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003377 return null;
3378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 return phone.getDeviceSvn();
3383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003386 }
3387
fionaxu43304da2017-11-27 22:51:16 -08003388 @Override
3389 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 final Phone phone = getPhone(subId);
3393 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
fionaxu43304da2017-11-27 22:51:16 -08003397 }
3398
3399 @Override
3400 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 final Phone phone = getPhone(subId);
3404 return phone == null ? null : phone.getCarrierName();
3405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
fionaxu43304da2017-11-27 22:51:16 -08003408 }
3409
calvinpanffe225e2018-11-01 19:43:06 +08003410 @Override
chen xu0026ca62019-03-06 15:28:50 -08003411 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 final Phone phone = getPhone(subId);
3415 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003416 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 }
3421
3422 @Override
chen xu0026ca62019-03-06 15:28:50 -08003423 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003427 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
3431 }
3432
chen xu651eec72018-11-11 19:03:44 -08003433 @Override
chen xu864e11c2018-12-06 22:10:03 -08003434 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3435 if (!isSubscriptionMccMnc) {
3436 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3437 }
chen xu651eec72018-11-11 19:03:44 -08003438 final Phone phone = PhoneFactory.getPhone(slotIndex);
3439 if (phone == null) {
3440 return TelephonyManager.UNKNOWN_CARRIER_ID;
3441 }
3442 final long identity = Binder.clearCallingIdentity();
3443 try {
3444 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 //
3451 // Internal helper methods.
3452 //
3453
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003454 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003455 * Make sure the caller is the calling package itself
3456 *
3457 * @throws SecurityException if the caller is not the calling package
3458 */
3459 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3460 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003461 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3462 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003463 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003464 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003465 } catch (PackageManager.NameNotFoundException e) {
3466 // packageUid is -1
3467 }
3468 if (packageUid != callingUid) {
3469 throw new SecurityException(message + ": Package " + callingPackage
3470 + " does not belong to " + callingUid);
3471 }
3472 }
3473
3474 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3476 *
3477 * @throws SecurityException if the caller does not have the required permission
3478 */
3479 private void enforceModifyPermission() {
3480 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3481 }
3482
Shuo Qian3b6ee772019-11-13 17:43:31 -08003483 private void enforceActiveEmergencySessionPermission() {
3484 mApp.enforceCallingOrSelfPermission(
3485 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3486 }
3487
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488 /**
3489 * Make sure the caller has the CALL_PHONE permission.
3490 *
3491 * @throws SecurityException if the caller does not have the required permission
3492 */
3493 private void enforceCallPermission() {
3494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3495 }
3496
paulhu5a773602019-08-23 19:17:33 +08003497 private void enforceSettingsPermission() {
3498 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003499 }
3500
Michele Berionne5e411512020-11-13 02:36:59 +00003501 private void enforceRebootPermission() {
3502 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3503 }
3504
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 private String createTelUrl(String number) {
3506 if (TextUtils.isEmpty(number)) {
3507 return null;
3508 }
3509
Jake Hambye994d462014-02-03 13:10:13 -08003510 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 }
3512
Ihab Awadf9e92732013-12-05 18:02:52 -08003513 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3515 }
3516
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003517 private static void logv(String msg) {
3518 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3519 }
3520
Ihab Awadf9e92732013-12-05 18:02:52 -08003521 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3523 }
3524
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003527 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003528 }
3529
Sanket Padawe356d7632015-06-22 14:03:32 -07003530 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003531 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 final Phone phone = PhoneFactory.getPhone(slotIndex);
3535 if (phone == null) {
3536 return PhoneConstants.PHONE_TYPE_NONE;
3537 } else {
3538 return phone.getPhoneType();
3539 }
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543 }
3544
3545 /**
3546 * Returns the CDMA ERI icon index to display
3547 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003548 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003549 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3550 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3551 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003552 }
3553
Sanket Padawe356d7632015-06-22 14:03:32 -07003554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003555 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3556 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 mApp, subId, callingPackage, callingFeatureId,
3559 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003560 return -1;
3561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 final Phone phone = getPhone(subId);
3566 if (phone != null) {
3567 return phone.getCdmaEriIconIndex();
3568 } else {
3569 return -1;
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 }
3575
3576 /**
3577 * Returns the CDMA ERI icon mode,
3578 * 0 - ON
3579 * 1 - FLASHING
3580 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003582 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3583 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3584 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003585 }
3586
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003588 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3589 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 mApp, subId, callingPackage, callingFeatureId,
3592 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003593 return -1;
3594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 final Phone phone = getPhone(subId);
3599 if (phone != null) {
3600 return phone.getCdmaEriIconMode();
3601 } else {
3602 return -1;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003607 }
3608
3609 /**
3610 * Returns the CDMA ERI text,
3611 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003612 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003613 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3614 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3615 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003616 }
3617
Sanket Padawe356d7632015-06-22 14:03:32 -07003618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003619 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3620 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003622 mApp, subId, callingPackage, callingFeatureId,
3623 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003624 return null;
3625 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626
3627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 final Phone phone = getPhone(subId);
3630 if (phone != null) {
3631 return phone.getCdmaEriText();
3632 } else {
3633 return null;
3634 }
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003638 }
3639
3640 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003641 * Returns the CDMA MDN.
3642 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003643 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003644 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3646 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 return phone.getLine1Number();
3653 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 return null;
3656 }
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003659 }
3660 }
3661
3662 /**
3663 * Returns the CDMA MIN.
3664 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003665 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003666 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3668 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 final Phone phone = getPhone(subId);
3673 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3674 return phone.getCdmaMin();
3675 } else {
3676 return null;
3677 }
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003680 }
3681 }
3682
Hall Liud892bec2018-11-30 14:51:45 -08003683 @Override
3684 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3685 INumberVerificationCallback callback, String callingPackage) {
3686 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3687 != PERMISSION_GRANTED) {
3688 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3689 }
3690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3691
3692 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3693 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003694 throw new SecurityException("Calling package must be configured in the device config: "
3695 + "calling package: " + callingPackage
3696 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003697 }
3698
3699 if (range == null) {
3700 throw new NullPointerException("Range must be non-null");
3701 }
3702
3703 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003704 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003705
3706 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3707 }
3708
Junda Liuca05d5d2014-08-14 22:36:34 -07003709 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003710 * Returns true if CDMA provisioning needs to run.
3711 */
3712 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 final long identity = Binder.clearCallingIdentity();
3714 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003715 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003719 }
3720
3721 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003722 * Sets the voice mail number of a given subId.
3723 */
3724 @Override
3725 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003726 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3727 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728
3729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3732 new Pair<String, String>(alphaTag, number), new Integer(subId));
3733 return success;
3734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003737 }
3738
Ta-wei Yen87c49842016-05-13 21:19:52 -07003739 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003740 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003742 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3743 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003744 if (!TextUtils.equals(callingPackage, systemDialer)) {
3745 throw new SecurityException("caller must be system dialer");
3746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
3748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3751 if (phoneAccountHandle == null) {
3752 return null;
3753 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 } finally {
3756 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003757 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003758 }
3759
3760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3762 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003765 mApp, subId, callingPackage, callingFeatureId,
3766 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003767 return null;
3768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003770 final long identity = Binder.clearCallingIdentity();
3771 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003772 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003776 }
3777
3778 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003779 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3780 VisualVoicemailSmsFilterSettings settings) {
3781 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782
3783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003786 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003790 }
3791
3792 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003793 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 mApp, callingPackage, subId);
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 VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3807 String callingPackage, int subId) {
3808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
3810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003813 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003817 }
3818
3819 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003820 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822
3823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003826 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003830 }
3831
3832 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003833 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3834 String callingAttributionTag, int subId, String number, int port, String text,
3835 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003836 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003837 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003838 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003839 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003840 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3841 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003842 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003843
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003844 /**
fionaxu0152e512016-11-14 13:36:14 -08003845 * Sets the voice activation state of a given subId.
3846 */
3847 @Override
3848 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3850 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851
3852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 final Phone phone = getPhone(subId);
3855 if (phone != null) {
3856 phone.setVoiceActivationState(activationState);
3857 } else {
3858 loge("setVoiceActivationState fails with invalid subId: " + subId);
3859 }
3860 } finally {
3861 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003862 }
3863 }
3864
3865 /**
3866 * Sets the data activation state of a given subId.
3867 */
3868 @Override
3869 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3871 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872
3873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 final Phone phone = getPhone(subId);
3876 if (phone != null) {
3877 phone.setDataActivationState(activationState);
3878 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003879 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880 }
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003883 }
3884 }
3885
3886 /**
3887 * Returns the voice activation state of a given subId.
3888 */
3889 @Override
3890 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892
fionaxu0152e512016-11-14 13:36:14 -08003893 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894 final long identity = Binder.clearCallingIdentity();
3895 try {
3896 if (phone != null) {
3897 return phone.getVoiceActivationState();
3898 } else {
3899 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3900 }
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003903 }
3904 }
3905
3906 /**
3907 * Returns the data activation state of a given subId.
3908 */
3909 @Override
3910 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912
fionaxu0152e512016-11-14 13:36:14 -08003913 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 if (phone != null) {
3917 return phone.getDataActivationState();
3918 } else {
3919 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3920 }
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003923 }
3924 }
3925
3926 /**
Wink Saville36469e72014-06-11 15:17:00 -07003927 * Returns the unread count of voicemails for a subId
3928 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003929 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003930 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3931 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003933 mApp, subId, callingPackage, callingFeatureId,
3934 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003935 return 0;
3936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 final Phone phone = getPhone(subId);
3940 if (phone != null) {
3941 return phone.getVoiceMessageCount();
3942 } else {
3943 return 0;
3944 }
3945 } finally {
3946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003948 }
3949
3950 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003951 * returns true, if the device is in a state where both voice and data
3952 * are supported simultaneously. This can change based on location or network condition.
3953 */
3954 @Override
3955 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 final Phone phone = getPhone(subId);
3959 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003963 }
3964
3965 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003966 * Send the dialer code if called from the current default dialer or the caller has
3967 * carrier privilege.
3968 * @param inputCode The dialer code to send
3969 */
3970 @Override
3971 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003974 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3975 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003976 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003977 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003978 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003983 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 } finally {
3985 Binder.restoreCallingIdentity(identity);
3986 }
fionaxu235cc5e2017-03-06 22:25:57 -08003987 }
3988
Pengquan Menga1bb6272018-09-06 09:59:22 -07003989 @Override
3990 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003991 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003992 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003993 mApp, subId, "getNetworkSelectionMode");
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 if (!isActiveSubscription(subId)) {
3997 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3998 }
3999 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4000 } finally {
4001 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004002 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004003 }
4004
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004006 public boolean isInEmergencySmsMode() {
4007 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 for (Phone phone : PhoneFactory.getPhones()) {
4011 if (phone.isInEmergencySmsMode()) {
4012 return true;
4013 }
4014 }
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
4017 }
4018 return false;
4019 }
4020
shilu366312e2019-12-17 09:28:10 -08004021 /**
4022 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4023 * @param subId The subscription to use to check the configuration.
4024 * @param c The callback that will be used to send the result.
4025 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004026 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004027 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4028 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004029 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004030 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004031
4032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4034 "IMS not available on device.");
4035 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 final long token = Binder.clearCallingIdentity();
4037 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004038 int slotId = getSlotIndexOrException(subId);
4039 verifyImsMmTelConfiguredOrThrow(slotId);
4040 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004041 } catch (ImsException e) {
4042 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 } finally {
4044 Binder.restoreCallingIdentity(token);
4045 }
4046 }
4047
shilu366312e2019-12-17 09:28:10 -08004048 /**
4049 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4050 * @param subId The subscription to use to check the configuration.
4051 * @param c The callback that will be used to send the result.
4052 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004054 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004055 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004056 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004057 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4058 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4059 }
Meng Wangafbc5852019-09-19 17:37:13 -07004060 final long token = Binder.clearCallingIdentity();
4061 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004062 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4063 .removeRegistrationCallbackForSubscription(c, subId);
4064 } catch (ImsException e) {
4065 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4066 + "is inactive, ignoring unregister.");
4067 // If the subscription is no longer active, just return, since the callback
4068 // will already have been removed internally.
4069 } finally {
4070 Binder.restoreCallingIdentity(token);
4071 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 }
4073
Brad Ebingera34a6c22019-10-22 17:36:18 -07004074 /**
4075 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4076 */
4077 @Override
4078 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4079 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4080 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4081 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4082 "IMS not available on device.");
4083 }
4084 final long token = Binder.clearCallingIdentity();
4085 try {
4086 Phone phone = getPhone(subId);
4087 if (phone == null) {
4088 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4089 + subId + "'");
4090 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4091 }
4092 phone.getImsRegistrationState(regState -> {
4093 try {
4094 consumer.accept((regState == null)
4095 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4096 } catch (RemoteException e) {
4097 // Ignore if the remote process is no longer available to call back.
4098 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4099 }
4100 });
4101 } finally {
4102 Binder.restoreCallingIdentity(token);
4103 }
4104 }
4105
4106 /**
4107 * Get the transport type for the IMS service registration state.
4108 */
4109 @Override
4110 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004111 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004112 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004113 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4114 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4115 "IMS not available on device.");
4116 }
4117 final long token = Binder.clearCallingIdentity();
4118 try {
4119 Phone phone = getPhone(subId);
4120 if (phone == null) {
4121 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4122 + subId + "'");
4123 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4124 }
4125 phone.getImsRegistrationTech(regTech -> {
4126 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4127 int regTechConverted = (regTech == null)
4128 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4129 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4130 regTechConverted);
4131 try {
4132 consumer.accept(regTechConverted);
4133 } catch (RemoteException e) {
4134 // Ignore if the remote process is no longer available to call back.
4135 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4136 }
4137 });
4138 } finally {
4139 Binder.restoreCallingIdentity(token);
4140 }
4141 }
4142
shilu366312e2019-12-17 09:28:10 -08004143 /**
4144 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4145 * @param subId The subscription to use to check the configuration.
4146 * @param c The callback that will be used to send the result.
4147 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004148 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004149 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4150 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004151 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004152 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004153 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4154 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4155 "IMS not available on device.");
4156 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 final long token = Binder.clearCallingIdentity();
4158 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004159 int slotId = getSlotIndexOrException(subId);
4160 verifyImsMmTelConfiguredOrThrow(slotId);
4161 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004162 } catch (ImsException e) {
4163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 } finally {
4165 Binder.restoreCallingIdentity(token);
4166 }
4167 }
4168
shilu366312e2019-12-17 09:28:10 -08004169 /**
4170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4171 * @param subId The subscription to use to check the configuration.
4172 * @param c The callback that will be used to send the result.
4173 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004175 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004176 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004177 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4179 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4180 }
Meng Wangafbc5852019-09-19 17:37:13 -07004181
4182 final long token = Binder.clearCallingIdentity();
4183 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004184 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004185 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004186 } catch (ImsException e) {
4187 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4188 + "is inactive, ignoring unregister.");
4189 // If the subscription is no longer active, just return, since the callback
4190 // will already have been removed internally.
4191 } finally {
4192 Binder.restoreCallingIdentity(token);
4193 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 }
4195
4196 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004197 public boolean isCapable(int subId, int capability, int regTech) {
4198 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 final long token = Binder.clearCallingIdentity();
4200 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004201 int slotId = getSlotIndexOrException(subId);
4202 verifyImsMmTelConfiguredOrThrow(slotId);
4203 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4204 } catch (com.android.ims.ImsException e) {
4205 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4206 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004207 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004208 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4209 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 } finally {
4211 Binder.restoreCallingIdentity(token);
4212 }
4213 }
4214
4215 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004216 public boolean isAvailable(int subId, int capability, int regTech) {
4217 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 final long token = Binder.clearCallingIdentity();
4219 try {
4220 Phone phone = getPhone(subId);
4221 if (phone == null) return false;
4222 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004223 } catch (com.android.ims.ImsException e) {
4224 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4225 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004226 } finally {
4227 Binder.restoreCallingIdentity(token);
4228 }
4229 }
4230
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004231 /**
4232 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4233 * subscription.
4234 * @param subId The subscription to use to check the configuration.
4235 * @param callback The callback that will be used to send the result.
4236 * @param capability The MmTelFeature capability that will be used to send the result.
4237 * @param transportType The transport type of the MmTelFeature capability.
4238 */
4239 @Override
4240 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4241 int transportType) {
4242 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004243 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4244 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4245 "IMS not available on device.");
4246 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004247 final long token = Binder.clearCallingIdentity();
4248 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004249 int slotId = getSlotIndex(subId);
4250 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4251 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4252 + subId + "'");
4253 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4254 }
4255 verifyImsMmTelConfiguredOrThrow(slotId);
4256 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4257 transportType, aBoolean -> {
4258 try {
4259 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4260 } catch (RemoteException e) {
4261 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4262 + "running. Ignore");
4263 }
4264 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004265 } catch (ImsException e) {
4266 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004267 } finally {
4268 Binder.restoreCallingIdentity(token);
4269 }
4270 }
4271
shilu366312e2019-12-17 09:28:10 -08004272 /**
4273 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4274 * @param subId The subscription to use to check the configuration.
4275 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 @Override
4277 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004278 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004279 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004280
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 final long token = Binder.clearCallingIdentity();
4282 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004284 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004286 } catch (ImsException e) {
4287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 } finally {
4289 Binder.restoreCallingIdentity(token);
4290 }
4291 }
4292
4293 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004294 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004296 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004300 // This setting doesn't require an active ImsService connection, so do not verify. The
4301 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004303 } catch (ImsException e) {
4304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308 }
4309
shilu366312e2019-12-17 09:28:10 -08004310 /**
4311 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4312 * @param subId The subscription to use to check the configuration.
4313 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004315 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004316 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004317 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 final long identity = Binder.clearCallingIdentity();
4319 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004320 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004321 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004323 } catch (ImsException e) {
4324 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
4328 }
4329
4330 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004331 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004333 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 final long identity = Binder.clearCallingIdentity();
4335 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004337 // This setting doesn't require an active ImsService connection, so do not verify. The
4338 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004339 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004340 } catch (ImsException e) {
4341 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
4345 }
4346
shilu366312e2019-12-17 09:28:10 -08004347 /**
4348 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4349 * @param subId The subscription to use to check the configuration.
4350 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 @Override
4352 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004353 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004354 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 final long identity = Binder.clearCallingIdentity();
4356 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004358 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004360 } catch (ImsException e) {
4361 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 } finally {
4363 Binder.restoreCallingIdentity(identity);
4364 }
4365 }
4366
4367 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004368 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004370 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 final long identity = Binder.clearCallingIdentity();
4372 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004374 // This setting doesn't require an active ImsService connection, so do not verify. The
4375 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 } catch (ImsException e) {
4378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
4382 }
4383
shilu366312e2019-12-17 09:28:10 -08004384 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004385 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4386 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4387 * @param subId The subscription to use to check the configuration.
4388 */
4389 @Override
4390 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004391 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004392 mApp, subId, "isCrossSimCallingEnabledByUser");
4393 final long identity = Binder.clearCallingIdentity();
4394 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004396 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004398 } catch (ImsException e) {
4399 throw new ServiceSpecificException(e.getCode());
4400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
4403 }
4404
4405 /**
4406 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4407 * Requires MODIFY_PHONE_STATE permission.
4408 * @param subId The subscription to use to check the configuration.
4409 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4410 * false otherwise
4411 */
4412 @Override
4413 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4415 "setCrossSimCallingEnabled");
4416 final long identity = Binder.clearCallingIdentity();
4417 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004418 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004419 // This setting doesn't require an active ImsService connection, so do not verify. The
4420 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004421 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004422 } catch (ImsException e) {
4423 throw new ServiceSpecificException(e.getCode());
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
4427 }
4428
4429 /**
shilu366312e2019-12-17 09:28:10 -08004430 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4431 * @param subId The subscription to use to check the configuration.
4432 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004434
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004436 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004437 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 final long identity = Binder.clearCallingIdentity();
4439 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004440 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004441 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004443 } catch (ImsException e) {
4444 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004445 } finally {
4446 Binder.restoreCallingIdentity(identity);
4447 }
4448 }
4449
4450 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004451 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004453 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 final long identity = Binder.clearCallingIdentity();
4455 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004457 // This setting doesn't require an active ImsService connection, so do not verify. The
4458 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004460 } catch (ImsException e) {
4461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
4465 }
4466
4467 @Override
4468 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4470 "setVoWiFiNonPersistent");
4471 final long identity = Binder.clearCallingIdentity();
4472 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004474 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004476 } catch (ImsException e) {
4477 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
4481 }
4482
shilu366312e2019-12-17 09:28:10 -08004483 /**
4484 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4485 * @param subId The subscription to use to check the configuration.
4486 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 @Override
4488 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004489 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004490 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 final long identity = Binder.clearCallingIdentity();
4492 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004494 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004496 } catch (ImsException e) {
4497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
4501 }
4502
4503 @Override
4504 public void setVoWiFiModeSetting(int subId, int mode) {
4505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4506 "setVoWiFiModeSetting");
4507 final long identity = Binder.clearCallingIdentity();
4508 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004509 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004510 // This setting doesn't require an active ImsService connection, so do not verify. The
4511 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004513 } catch (ImsException e) {
4514 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004515 } finally {
4516 Binder.restoreCallingIdentity(identity);
4517 }
4518 }
4519
4520 @Override
4521 public int getVoWiFiRoamingModeSetting(int subId) {
4522 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4523 final long identity = Binder.clearCallingIdentity();
4524 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004525 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004526 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004528 } catch (ImsException e) {
4529 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
4533 }
4534
4535 @Override
4536 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4538 "setVoWiFiRoamingModeSetting");
4539 final long identity = Binder.clearCallingIdentity();
4540 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004542 // This setting doesn't require an active ImsService connection, so do not verify. The
4543 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
4546 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
4550 }
4551
4552 @Override
4553 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4555 "setRttCapabilityEnabled");
4556 final long identity = Binder.clearCallingIdentity();
4557 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004559 // This setting doesn't require an active ImsService connection, so do not verify. The
4560 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004561 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004562 } catch (ImsException e) {
4563 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
4567 }
4568
shilu366312e2019-12-17 09:28:10 -08004569 /**
4570 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4571 * @param subId The subscription to use to check the configuration.
4572 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004573 @Override
4574 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004575 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004576 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 final long identity = Binder.clearCallingIdentity();
4578 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004580 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004581 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004582 } catch (ImsException e) {
4583 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
4587 }
4588
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004589 @Override
4590 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4591 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004592
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 final long identity = Binder.clearCallingIdentity();
4594 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004595 if (!isImsAvailableOnDevice()) {
4596 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4597 "IMS not available on device.");
4598 }
4599 int slotId = getSlotIndexOrException(subId);
4600 verifyImsMmTelConfiguredOrThrow(slotId);
4601 ImsManager.getInstance(mApp, slotId)
4602 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004603 } catch (ImsException e) {
4604 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
4608 }
4609
4610 @Override
4611 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4612 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004613
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004614 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4616 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4617 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004618 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004619 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004620 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004622 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4623 + "is inactive, ignoring unregister.");
4624 // If the subscription is no longer active, just return, since the callback will already
4625 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
4629 }
4630
joonhunshincffb7fc2021-11-28 07:32:01 +00004631 @Override
4632 public void registerFeatureProvisioningChangedCallback(int subId,
4633 IFeatureProvisioningCallback callback) {
4634 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4635 mApp, subId, "registerFeatureProvisioningChangedCallback");
4636
4637 final long identity = Binder.clearCallingIdentity();
4638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4639 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4640 }
4641
joonhunshin91bc1952022-04-29 08:47:15 +00004642 try {
4643 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4644 if (controller == null) {
4645 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4646 "Device does not support IMS");
4647 }
4648 controller.addFeatureProvisioningChangedCallback(subId, callback);
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
4651 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004652 }
4653
4654 @Override
4655 public void unregisterFeatureProvisioningChangedCallback(int subId,
4656 IFeatureProvisioningCallback callback) {
4657 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4658 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4659
4660 final long identity = Binder.clearCallingIdentity();
4661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4662 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4663 }
4664
joonhunshin91bc1952022-04-29 08:47:15 +00004665 try {
4666 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4667 if (controller == null) {
4668 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4669 return;
4670 }
4671 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4672 } finally {
4673 Binder.restoreCallingIdentity(identity);
4674 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004675 }
allenwtsu99c623b2020-01-03 18:24:23 +08004676
4677 private void checkModifyPhoneStatePermission(int subId, String message) {
4678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4679 message);
4680 }
4681
allenwtsu99c623b2020-01-03 18:24:23 +08004682 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004683 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004684 boolean isProvisioned) {
4685 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4686
4687 final long identity = Binder.clearCallingIdentity();
4688 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004689 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4690 if (controller == null) {
4691 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4692 return;
4693 }
4694 controller.setRcsProvisioningStatusForCapability(
4695 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
allenwtsu99c623b2020-01-03 18:24:23 +08004699 }
4700
4701
4702 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004703 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4704 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4705 mApp, subId, "getRcsProvisioningStatusForCapability");
4706
allenwtsu99c623b2020-01-03 18:24:23 +08004707 final long identity = Binder.clearCallingIdentity();
4708 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004709 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4710 if (controller == null) {
4711 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4712
4713 // device does not support IMS, this method will return true always.
4714 return true;
4715 }
4716 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
4720 }
4721
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004722 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004723 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4724 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004725 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004726
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004729 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4730 if (controller == null) {
4731 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4732 return;
4733 }
4734 controller.setImsProvisioningStatusForCapability(
4735 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
4739 }
4740
4741 @Override
4742 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004743 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4744 mApp, subId, "getProvisioningStatusForCapability");
4745
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004746 final long identity = Binder.clearCallingIdentity();
4747 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004748 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4749 if (controller == null) {
4750 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751
joonhunshin91bc1952022-04-29 08:47:15 +00004752 // device does not support IMS, this method will return true always.
4753 return true;
4754 }
4755 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756 } finally {
4757 Binder.restoreCallingIdentity(identity);
4758 }
4759 }
4760
4761 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004762 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4763 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4764 mApp, subId, "isProvisioningRequiredForCapability");
4765
4766 final long identity = Binder.clearCallingIdentity();
4767 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004768 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4769 if (controller == null) {
4770 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4771
4772 // device does not support IMS, this method will return false
4773 return false;
4774 }
4775 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004776 } finally {
4777 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004778 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004779 }
4780
4781 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004782 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4783 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4784 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004785
joonhunshincffb7fc2021-11-28 07:32:01 +00004786 final long identity = Binder.clearCallingIdentity();
4787 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004788 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4789 if (controller == null) {
4790 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4791
4792 // device does not support IMS, this method will return false
4793 return false;
4794 }
4795 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004796 } finally {
4797 Binder.restoreCallingIdentity(identity);
4798 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004799 }
4800
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004801 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004802 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004803 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4804 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4805 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004806 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4807 mApp, subId, "getImsProvisioningInt");
4808
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004809 final long identity = Binder.clearCallingIdentity();
4810 try {
4811 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004812 int slotId = getSlotIndex(subId);
4813 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4814 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4815 + subId + "' for key:" + key);
4816 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4817 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004818
joonhunshin91bc1952022-04-29 08:47:15 +00004819 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4820 if (controller == null) {
4821 loge("getImsProvisioningInt: Device does not support IMS");
4822
4823 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4824 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4825 }
4826 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004827 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4828 return retVal;
4829 }
4830
calvinpanb5a34062021-02-08 19:59:36 +08004831 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004832 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004833 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4834 + subId + "' for key:" + key);
4835 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004836 } finally {
4837 Binder.restoreCallingIdentity(identity);
4838 }
4839 }
4840
4841 @Override
4842 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004843 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4844 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4845 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004846 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4847 mApp, subId, "getImsProvisioningString");
4848
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004852 int slotId = getSlotIndex(subId);
4853 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4854 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4855 + subId + "' for key:" + key);
4856 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4857 }
calvinpanb5a34062021-02-08 19:59:36 +08004858 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004859 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004860 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4861 + subId + "' for key:" + key);
4862 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
4866 }
4867
4868 @Override
4869 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004870 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4871 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4872 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4874 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004875
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 int slotId = getSlotIndex(subId);
4880 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4881 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4882 + subId + "' for key:" + key);
4883 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4884 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004885
joonhunshin91bc1952022-04-29 08:47:15 +00004886 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4887 if (controller == null) {
4888 loge("setImsProvisioningInt: Device does not support IMS");
4889
4890 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4891 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4892 }
4893 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004894 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4895 return retVal;
4896 }
4897
calvinpanb5a34062021-02-08 19:59:36 +08004898 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4899 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004901 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
4906 }
4907
4908 @Override
4909 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004910 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4911 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4912 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4914 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004915 final long identity = Binder.clearCallingIdentity();
4916 try {
4917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004918 int slotId = getSlotIndex(subId);
4919 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4920 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4921 + subId + "' for key:" + key);
4922 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4923 }
calvinpanb5a34062021-02-08 19:59:36 +08004924 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4925 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004926 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004927 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004928 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
4932 }
4933
Brad Ebinger919631e2021-06-02 17:46:35 -07004934 /**
4935 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4936 * for the given slot ID or no ImsResolver instance has been created.
4937 * @param slotId The slot ID that the IMS service is created for.
4938 * @throws ImsException If there is no ImsService configured for this slot.
4939 */
4940 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4941 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4942 ImsFeature.FEATURE_MMTEL)) {
4943 throw new ImsException("This subscription does not support MMTEL over IMS",
4944 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4945 }
4946 }
4947
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004948 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004949 int slotId = SubscriptionManager.getSlotIndex(subId);
4950 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004951 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4952 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004953 }
4954 return slotId;
4955 }
4956
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 private int getSlotIndex(int subId) {
4958 int slotId = SubscriptionManager.getSlotIndex(subId);
4959 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4960 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4961 }
4962 return slotId;
4963 }
4964
Wink Saville36469e72014-06-11 15:17:00 -07004965 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004966 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004967 */
4968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004969 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4970 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004971 try {
4972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4973 } catch (SecurityException se) {
4974 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4975 throw new SecurityException("Package " + callingPackage + " does not belong to "
4976 + Binder.getCallingUid());
4977 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004978 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004979 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004980 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004981 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004982 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004983 mApp, subId, callingPackage, callingFeatureId,
4984 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004985 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4986 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 final Phone phone = getPhone(subId);
4991 if (phone != null) {
4992 return phone.getServiceState().getDataNetworkType();
4993 } else {
4994 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4995 }
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004999 }
5000
5001 /**
5002 * Returns the data network type
5003 */
5004 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005005 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005006 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5007 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005008 }
5009
5010 /**
5011 * Returns the data network type for a subId
5012 */
5013 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005014 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5015 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005016 String functionName = "getDataNetworkTypeForSubscriber";
5017 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5018 mApp, functionName)) {
5019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5020 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5021 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5022 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005023 }
5024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 final Phone phone = getPhone(subId);
5028 if (phone != null) {
5029 return phone.getServiceState().getDataNetworkType();
5030 } else {
5031 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5032 }
5033 } finally {
5034 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005036 }
5037
5038 /**
Wink Saville36469e72014-06-11 15:17:00 -07005039 * Returns the Voice network type for a subId
5040 */
5041 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005042 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5043 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005044 String functionName = "getVoiceNetworkTypeForSubscriber";
5045 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5046 mApp, functionName)) {
5047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5048 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5049 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5050 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005051 }
5052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
5055 final Phone phone = getPhone(subId);
5056 if (phone != null) {
5057 return phone.getServiceState().getVoiceNetworkType();
5058 } else {
5059 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5060 }
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005064 }
5065
5066 /**
5067 * @return true if a ICC card is present
5068 */
5069 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005070 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005071 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5072 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005073 }
5074
5075 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005076 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005077 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005078 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005079 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 final Phone phone = PhoneFactory.getPhone(slotIndex);
5083 if (phone != null) {
5084 return phone.getIccCard().hasIccCard();
5085 } else {
5086 return false;
5087 }
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005091 }
5092
5093 /**
5094 * Return if the current radio is LTE on CDMA. This
5095 * is a tri-state return value as for a period of time
5096 * the mode may be unknown.
5097 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005098 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005099 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005100 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005101 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005103 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5104 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5105 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005106 }
5107
Sanket Padawe356d7632015-06-22 14:03:32 -07005108 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005109 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5110 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005111 try {
5112 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5113 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005114 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5115 }
5116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 final long identity = Binder.clearCallingIdentity();
5118 try {
5119 final Phone phone = getPhone(subId);
5120 if (phone == null) {
5121 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5122 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005123 return TelephonyProperties.lte_on_cdma_device()
5124 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 }
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005128 }
Wink Saville36469e72014-06-11 15:17:00 -07005129 }
5130
Wink Saville36469e72014-06-11 15:17:00 -07005131 /**
5132 * {@hide}
5133 * Returns Default subId, 0 in the case of single standby.
5134 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005135 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005136 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005137 }
5138
Shishir Agrawala9f32182016-04-12 12:00:16 -07005139 private int getSlotForDefaultSubscription() {
5140 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5141 }
5142
Wink Savilleb564aae2014-10-23 10:18:09 -07005143 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005144 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005145 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005146
Pengquan Menge92a50d2018-09-21 15:54:48 -07005147 private boolean isActiveSubscription(int subId) {
5148 return mSubscriptionController.isActiveSubId(subId);
5149 }
5150
Ihab Awadf2177b72013-11-25 13:33:23 -08005151 /**
5152 * @see android.telephony.TelephonyManager.WifiCallingChoices
5153 */
5154 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 final long identity = Binder.clearCallingIdentity();
5156 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005157 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5159 getWhenToMakeWifiCallsDefaultPreference());
5160 } finally {
5161 Binder.restoreCallingIdentity(identity);
5162 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005163 }
5164
5165 /**
5166 * @see android.telephony.TelephonyManager.WifiCallingChoices
5167 */
5168 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005177 }
5178
Sailesh Nepald1e68152013-12-12 19:08:02 -08005179 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005180 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005181 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005182 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005183
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005184 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5185 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5186 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005187 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005188 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5189 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005190 }
5191 return PhoneFactory.getPhone(phoneId);
5192 }
5193
Shishir Agrawal566b7612013-10-28 14:41:00 -07005194 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005195 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005196 @NonNull IccLogicalChannelRequest request) {
5197 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5198 /*message=*/ "iccOpenLogicalChannel");
5199
5200 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5201 // Verify that the callingPackage in the request belongs to the calling UID
5202 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5203
5204 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005205 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005206
Rambo Wanga1782702021-11-10 20:15:19 -08005207 private Phone getPhoneFromValidIccLogicalChannelRequest(
5208 @NonNull IccLogicalChannelRequest request, String message) {
5209 Phone phone;
5210 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5212 mApp, request.subId, message);
5213 phone = getPhoneFromSubId(request.subId);
5214 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5215 enforceModifyPermission();
5216 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5217 } else {
5218 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005219 }
Rambo Wanga1782702021-11-10 20:15:19 -08005220 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005221 }
5222
5223 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005224 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005227 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005229 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5230 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005231 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5232 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 loge("The calling package is not allowed to access ISD-R.");
5234 throw new SecurityException(
5235 "The calling package is not allowed to access ISD-R.");
5236 }
Derek Tan740e1672017-06-27 14:56:27 -07005237 }
Derek Tan740e1672017-06-27 14:56:27 -07005238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005240 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5241 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 return response;
5243 } finally {
5244 Binder.restoreCallingIdentity(identity);
5245 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005246 }
5247
5248 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005249 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5250 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5251 /*message=*/"iccCloseLogicalChannel");
5252
5253 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5254
5255 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005256 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005257
Rambo Wanga1782702021-11-10 20:15:19 -08005258 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5259 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005260 // before this feature is enabled, this API should only return false if
5261 // the operation fails instead of throwing runtime exception for
5262 // backward-compatibility.
5263 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5264 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 final long identity = Binder.clearCallingIdentity();
5266 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005267 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005268 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 }
Chen Xue9d737e2022-01-01 23:41:31 -08005270 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005271 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005272 Boolean success = false;
5273 if (result instanceof RuntimeException) {
5274 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005275 if (shouldThrowExceptionOnFailure) {
5276 throw (RuntimeException) result;
5277 } else {
5278 return false;
5279 }
Chen Xue9d737e2022-01-01 23:41:31 -08005280 } else if (result instanceof Boolean) {
5281 success = (Boolean) result;
5282 } else {
5283 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5284 }
Rambo Wanga1782702021-11-10 20:15:19 -08005285 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 return success;
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005289 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005290 }
5291
5292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005293 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005294 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5296 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005297 if (DBG) {
5298 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5299 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5300 + p3 + " data=" + data);
5301 }
5302 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5303 command, p1, p2, p3, data);
5304 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005305
Jordan Liu4c733742019-02-28 12:03:40 -08005306 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005307 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5308 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005309 enforceModifyPermission();
5310 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005311 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5312 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5313 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005314 }
5315 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005316 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5317 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005318 }
5319
5320 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5321 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 final long identity = Binder.clearCallingIdentity();
5323 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005324 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 return "";
5326 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005329 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5330 null /* workSource */);
5331 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 // Append the returned status code to the end of the response payload.
5334 String s = Integer.toHexString(
5335 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5336 if (response.payload != null) {
5337 s = IccUtils.bytesToHexString(response.payload) + s;
5338 }
5339 return s;
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005342 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005343 }
Jake Hambye994d462014-02-03 13:10:13 -08005344
Evan Charltonc66da362014-05-16 14:06:40 -07005345 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005346 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5347 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5349 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005351 if (DBG) {
5352 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5353 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5354 }
5355 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5356 cla, command, p1, p2, p3, data);
5357 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005358
Jordan Liu4c733742019-02-28 12:03:40 -08005359 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005360 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5361 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005362 enforceModifyPermission();
5363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5364 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005365 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5366 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5367 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005368 }
5369
5370 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005371 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5372 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005373 }
5374
5375 // open APDU basic channel assuming the caller has sufficient permissions
5376 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5377 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 final long identity = Binder.clearCallingIdentity();
5379 try {
5380 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5381 && TextUtils.equals(ISDR_AID, data)) {
5382 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005383 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5384 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 if (bestComponent == null
5386 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5387 loge("The calling package is not allowed to select ISD-R.");
5388 throw new SecurityException(
5389 "The calling package is not allowed to select ISD-R.");
5390 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005391 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005394 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5395 null /* workSource */);
5396 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 // Append the returned status code to the end of the response payload.
5399 String s = Integer.toHexString(
5400 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5401 if (response.payload != null) {
5402 s = IccUtils.bytesToHexString(response.payload) + s;
5403 }
5404 return s;
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005407 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005408 }
5409
5410 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005411 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005412 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5414 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 final long identity = Binder.clearCallingIdentity();
5417 try {
5418 if (DBG) {
5419 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5420 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5421 }
5422
5423 IccIoResult response =
5424 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5425 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5426 subId);
5427
5428 if (DBG) {
5429 log("Exchange SIM_IO [R]" + response);
5430 }
5431
5432 byte[] result = null;
5433 int length = 2;
5434 if (response.payload != null) {
5435 length = 2 + response.payload.length;
5436 result = new byte[length];
5437 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5438 } else {
5439 result = new byte[length];
5440 }
5441
5442 result[length - 1] = (byte) response.sw2;
5443 result[length - 2] = (byte) response.sw1;
5444 return result;
5445 } finally {
5446 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005447 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005448 }
5449
Nathan Haroldb3014052017-01-25 15:57:32 -08005450 /**
5451 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5452 * on a particular subscription
5453 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005454 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5455 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005457 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005458 return null;
5459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460
5461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 if (appType != TelephonyManager.APPTYPE_USIM
5464 && appType != TelephonyManager.APPTYPE_SIM) {
5465 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5466 return null;
5467 }
5468 Object response = sendRequest(
5469 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5470 if (response instanceof String[]) {
5471 return (String[]) response;
5472 }
yincheng zhao2737e882019-09-06 17:06:54 -07005473 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005475 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 } finally {
5477 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005478 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005479 }
5480
yincheng zhao2737e882019-09-06 17:06:54 -07005481 /**
5482 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5483 * subscription.
5484 *
5485 * @param subId the id of the subscription.
5486 * @param appType the uicc app type, must be USIM or SIM.
5487 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5488 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005489 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005490 * @return number of fplmns that is successfully written to the SIM.
5491 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005492 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5493 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5495 mApp, subId, "setForbiddenPlmns");
5496
yincheng zhao2737e882019-09-06 17:06:54 -07005497 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5498 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5499 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5500 }
5501 if (fplmns == null) {
5502 throw new IllegalArgumentException("Fplmn List provided is null");
5503 }
5504 for (String fplmn : fplmns) {
5505 if (!CellIdentity.isValidPlmn(fplmn)) {
5506 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5507 }
5508 }
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 Object response = sendRequest(
5512 CMD_SET_FORBIDDEN_PLMNS,
5513 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5514 subId);
5515 return (int) response;
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
5519 }
5520
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005521 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005522 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5524 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 final long identity = Binder.clearCallingIdentity();
5527 try {
5528 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5529 if (response.payload == null) {
5530 return "";
5531 }
Evan Charltonc66da362014-05-16 14:06:40 -07005532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 // Append the returned status code to the end of the response payload.
5534 String s = Integer.toHexString(
5535 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5536 s = IccUtils.bytesToHexString(response.payload) + s;
5537 return s;
5538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
Evan Charltonc66da362014-05-16 14:06:40 -07005541 }
5542
Jake Hambye994d462014-02-03 13:10:13 -08005543 /**
5544 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5545 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5546 *
5547 * @param itemID the ID of the item to read
5548 * @return the NV item as a String, or null on error.
5549 */
5550 @Override
5551 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005552 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5554 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555
5556 final long identity = Binder.clearCallingIdentity();
5557 try {
5558 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005559 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5561 return value;
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
5564 }
Jake Hambye994d462014-02-03 13:10:13 -08005565 }
5566
5567 /**
5568 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5569 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5570 *
5571 * @param itemID the ID of the item to read
5572 * @param itemValue the value to write, as a String
5573 * @return true on success; false on any failure
5574 */
5575 @Override
5576 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005577 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5584 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005585 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5587 return success;
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
Jake Hambye994d462014-02-03 13:10:13 -08005591 }
5592
5593 /**
5594 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5595 * Used for device configuration by some CDMA operators.
5596 *
5597 * @param preferredRoamingList byte array containing the new PRL
5598 * @return true on success; false on any failure
5599 */
5600 @Override
5601 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5603 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5608 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5609 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5610 return success;
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Jake Hambye994d462014-02-03 13:10:13 -08005614 }
5615
5616 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005617 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005618 * Used for device configuration by some CDMA operators.
5619 *
chen xu6dac5ab2018-10-26 17:39:23 -07005620 * @param slotIndex - device slot.
5621 *
Jake Hambye994d462014-02-03 13:10:13 -08005622 * @return true on success; false on any failure
5623 */
5624 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005625 public boolean resetModemConfig(int slotIndex) {
5626 Phone phone = PhoneFactory.getPhone(slotIndex);
5627 if (phone != null) {
5628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5629 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630
chen xu6dac5ab2018-10-26 17:39:23 -07005631 final long identity = Binder.clearCallingIdentity();
5632 try {
5633 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5634 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5635 return success;
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 }
chen xu6dac5ab2018-10-26 17:39:23 -07005640 return false;
5641 }
5642
5643 /**
5644 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5645 *
5646 * @param slotIndex - device slot.
5647 *
5648 * @return true on success; false on any failure
5649 */
5650 @Override
5651 public boolean rebootModem(int slotIndex) {
5652 Phone phone = PhoneFactory.getPhone(slotIndex);
5653 if (phone != null) {
5654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5655 mApp, phone.getSubId(), "rebootModem");
5656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5660 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5661 return success;
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
5665 }
5666 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005667 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005668
Brad Ebinger51f743a2017-01-23 13:50:20 -08005669 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005670 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5671 * {@link #disableIms(int)}.
5672 * @param slotIndex device slot.
5673 */
5674 public void resetIms(int slotIndex) {
5675 enforceModifyPermission();
5676
5677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 if (mImsResolver == null) {
5680 // may happen if the does not support IMS.
5681 return;
5682 }
5683 mImsResolver.disableIms(slotIndex);
5684 mImsResolver.enableIms(slotIndex);
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689
5690 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005691 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5692 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005693 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005694 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005695 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696
5697 final long identity = Binder.clearCallingIdentity();
5698 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005699 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005700 // may happen if the device does not support IMS.
5701 return;
5702 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005703 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005707 }
5708
5709 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005710 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5711 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005712 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005713 public void disableIms(int slotId) {
5714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005718 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005719 // may happen if the device does not support IMS.
5720 return;
5721 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005722 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005726 }
5727
5728 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005729 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5730 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005731 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005732 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005733 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5740 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005741 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005742 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005746 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005747 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005748 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5749 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005750 @Override
5751 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005752 enforceModifyPermission();
5753
5754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005757 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005758 } finally {
5759 Binder.restoreCallingIdentity(identity);
5760 }
5761 }
5762
5763 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005764 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005765 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005766 */
5767 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5768 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005772 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005773 // may happen if the device does not support IMS.
5774 return null;
5775 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005776 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 } finally {
5778 Binder.restoreCallingIdentity(identity);
5779 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005780 }
5781
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005782 /**
5783 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005784 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005785 */
5786 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5787 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788
5789 final long identity = Binder.clearCallingIdentity();
5790 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005791 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005792 // may happen if the device does not support IMS.
5793 return null;
5794 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005795 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005799 }
5800
Brad Ebinger884c07b2018-02-15 16:17:40 -08005801 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005802 * Sets the ImsService Package Name that Telephony will bind to.
5803 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005804 * @param slotIndex the slot ID that the ImsService should bind for.
5805 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005806 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005807 * @param featureTypes An integer array of feature types associated with a packageName.
5808 * @param packageName The name of the package that the current configuration will be replaced
5809 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005810 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005811 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5813 int[] featureTypes, String packageName) {
5814 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5817 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005818 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820 final long identity = Binder.clearCallingIdentity();
5821 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005823 // may happen if the device does not support IMS.
5824 return false;
5825 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 Map<Integer, String> featureConfig = new HashMap<>();
5827 for (int featureType : featureTypes) {
5828 featureConfig.put(featureType, packageName);
5829 }
5830 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5831 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 } finally {
5833 Binder.restoreCallingIdentity(identity);
5834 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005835 }
5836
5837 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005838 * Clears any carrier ImsService overrides for the slot index specified that were previously
5839 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5840 *
5841 * This should only be used for testing.
5842 *
5843 * @param slotIndex the slot ID that the ImsService should bind for.
5844 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5845 */
5846 @Override
5847 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5848 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5850 "clearCarrierImsServiceOverride");
5851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5852 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5853 "clearCarrierImsServiceOverride");
5854
5855 final long identity = Binder.clearCallingIdentity();
5856 try {
5857 if (mImsResolver == null) {
5858 // may happen if the device does not support IMS.
5859 return false;
5860 }
5861 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
5865 }
5866
5867 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005868 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005869 *
5870 * @param slotId The slot that the ImsService is associated with.
5871 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5872 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005873 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 * @return the package name of the ImsService configuration.
5875 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5877 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005878 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005879 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005880 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5882 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 final long identity = Binder.clearCallingIdentity();
5885 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005887 // may happen if the device does not support IMS.
5888 return "";
5889 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005890 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005891 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5892 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005896 }
5897
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005898 /**
5899 * Get the MmTelFeature state associated with the requested subscription id.
5900 * @param subId The subscription that the MmTelFeature is associated with.
5901 * @param callback A callback with an integer containing the
5902 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5903 */
5904 @Override
5905 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5906 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005907 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5908 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5909 "IMS not available on device.");
5910 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005911 final long token = Binder.clearCallingIdentity();
5912 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005913 int slotId = getSlotIndex(subId);
5914 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5915 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5916 + subId + "'");
5917 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5918 }
5919 verifyImsMmTelConfiguredOrThrow(slotId);
5920 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5921 try {
5922 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5923 } catch (RemoteException e) {
5924 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5925 + "Ignore");
5926 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005927 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005928 } catch (ImsException e) {
5929 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005930 } finally {
5931 Binder.restoreCallingIdentity(token);
5932 }
5933 }
5934
Daniel Brightbb5840b2021-01-12 15:48:18 -08005935 /**
5936 * Sets the ims registration state on all valid {@link Phone}s.
5937 */
5938 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005939 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940
5941 final long identity = Binder.clearCallingIdentity();
5942 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005943 // NOTE: Before S, this method only set the default phone.
5944 for (final Phone phone : PhoneFactory.getPhones()) {
5945 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5946 phone.setImsRegistrationState(registered);
5947 }
5948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 } finally {
5950 Binder.restoreCallingIdentity(identity);
5951 }
Wink Saville36469e72014-06-11 15:17:00 -07005952 }
5953
5954 /**
Stuart Scott54788802015-03-30 13:18:01 -07005955 * Set the network selection mode to automatic.
5956 *
5957 */
5958 @Override
5959 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5961 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962
5963 final long identity = Binder.clearCallingIdentity();
5964 try {
shilufc958392020-01-20 11:36:01 -08005965 if (!isActiveSubscription(subId)) {
5966 return;
5967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005969 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5970 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Stuart Scott54788802015-03-30 13:18:01 -07005974 }
5975
Jack Yud10cdd42020-09-28 20:28:01 -07005976 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005977 * Ask the radio to connect to the input network and change selection mode to manual.
5978 *
5979 * @param subId the id of the subscription.
5980 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5981 * the operator to attach to.
5982 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5983 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5984 * normal network selection next time.
5985 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005986 */
5987 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005988 public boolean setNetworkSelectionModeManual(
5989 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5991 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005992
5993 if (!isActiveSubscription(subId)) {
5994 return false;
5995 }
5996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 final long identity = Binder.clearCallingIdentity();
5998 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005999 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006001 if (DBG) {
6002 log("setNetworkSelectionModeManual: subId: " + subId
6003 + " operator: " + operatorInfo);
6004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6006 } finally {
6007 Binder.restoreCallingIdentity(identity);
6008 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006009 }
shilu84f6e8b2019-12-19 13:58:01 -08006010 /**
6011 * Get the manual network selection
6012 *
6013 * @param subId the id of the subscription.
6014 *
6015 * @return the previously saved user selected PLMN
6016 */
6017 @Override
6018 public String getManualNetworkSelectionPlmn(int subId) {
6019 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006020 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006021 mApp, subId, "getManualNetworkSelectionPlmn");
6022
6023 final long identity = Binder.clearCallingIdentity();
6024 try {
6025 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006026 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006027 }
6028
6029 final Phone phone = getPhone(subId);
6030 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006031 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006032 }
6033 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6034 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6035 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
6039 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006040
6041 /**
6042 * Scans for available networks.
6043 */
6044 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006045 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6046 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6048 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006049 LocationAccessPolicy.LocationPermissionResult locationResult =
6050 LocationAccessPolicy.checkLocationPermission(mApp,
6051 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6052 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006053 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006054 .setCallingPid(Binder.getCallingPid())
6055 .setCallingUid(Binder.getCallingUid())
6056 .setMethod("getCellNetworkScanResults")
6057 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006058 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6059 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006060 .build());
6061 switch (locationResult) {
6062 case DENIED_HARD:
6063 throw new SecurityException("Not allowed to access scan results -- location");
6064 case DENIED_SOFT:
6065 return null;
6066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067
Pengquan Menga1bb6272018-09-06 09:59:22 -07006068 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 try {
6070 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006071 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 } finally {
6074 Binder.restoreCallingIdentity(identity);
6075 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006076 }
6077
6078 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006079 * Get the call forwarding info, given the call forwarding reason.
6080 */
6081 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006082 public void getCallForwarding(int subId, int callForwardingReason,
6083 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006084 enforceReadPrivilegedPermission("getCallForwarding");
6085 long identity = Binder.clearCallingIdentity();
6086 try {
6087 if (DBG) {
6088 log("getCallForwarding: subId " + subId
6089 + " callForwardingReason" + callForwardingReason);
6090 }
Hall Liu27d24262020-09-18 19:04:59 -07006091
6092 Phone phone = getPhone(subId);
6093 if (phone == null) {
6094 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006095 callback.onError(
6096 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006097 } catch (RemoteException e) {
6098 // ignore
6099 }
6100 return;
6101 }
6102
6103 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6104 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6105 @Override
6106 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6107 try {
6108 callback.onCallForwardingInfoAvailable(info);
6109 } catch (RemoteException e) {
6110 // ignore
6111 }
6112 }
6113
6114 @Override
6115 public void onError(int error) {
6116 try {
6117 callback.onError(error);
6118 } catch (RemoteException e) {
6119 // ignore
6120 }
6121 }
6122 });
6123 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006124 } finally {
6125 Binder.restoreCallingIdentity(identity);
6126 }
6127 }
6128
6129 /**
6130 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6131 * reason, the number to forward, and the timeout before the forwarding is attempted.
6132 */
6133 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006134 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6135 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006136 enforceModifyPermission();
6137 long identity = Binder.clearCallingIdentity();
6138 try {
6139 if (DBG) {
6140 log("setCallForwarding: subId " + subId
6141 + " callForwardingInfo" + callForwardingInfo);
6142 }
Hall Liu27d24262020-09-18 19:04:59 -07006143
6144 Phone phone = getPhone(subId);
6145 if (phone == null) {
6146 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006147 callback.accept(
6148 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006149 } catch (RemoteException e) {
6150 // ignore
6151 }
6152 return;
6153 }
6154
6155 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6156 FunctionalUtils.ignoreRemoteException(callback::accept));
6157
6158 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
6162 }
6163
6164 /**
Hall Liu27d24262020-09-18 19:04:59 -07006165 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006166 */
6167 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006168 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006169 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006170 long identity = Binder.clearCallingIdentity();
6171 try {
Hall Liu27d24262020-09-18 19:04:59 -07006172 Phone phone = getPhone(subId);
6173 if (phone == null) {
6174 try {
6175 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6176 } catch (RemoteException e) {
6177 // ignore
6178 }
6179 return;
6180 }
SongFerngWang0e767992021-03-31 22:08:45 +08006181 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6182 PersistableBundle c = configManager.getConfigForSubId(subId);
6183 boolean requireUssd = c.getBoolean(
6184 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006185
Shuo Qian4a594052020-01-23 11:59:30 -08006186 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006187 if (requireUssd) {
6188 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6189 getSubscriptionCarrierId(subId));
6190 String newUssdCommand = "";
6191 try {
6192 newUssdCommand = carrierXmlParser.getFeature(
6193 CarrierXmlParser.FEATURE_CALL_WAITING)
6194 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6195 } catch (NullPointerException e) {
6196 loge("Failed to generate USSD number" + e);
6197 }
6198 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6199 mMainThreadHandler, callback, carrierXmlParser,
6200 CarrierXmlParser.SsEntry.SSAction.QUERY);
6201 final String ussdCommand = newUssdCommand;
6202 Executors.newSingleThreadExecutor().execute(() -> {
6203 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6204 });
6205 } else {
6206 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6207 callback::accept);
6208 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6209 }
Shuo Qian4a594052020-01-23 11:59:30 -08006210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
6213 }
6214
6215 /**
Hall Liu27d24262020-09-18 19:04:59 -07006216 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006217 */
6218 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006219 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006220 enforceModifyPermission();
6221 long identity = Binder.clearCallingIdentity();
6222 try {
Hall Liu27d24262020-09-18 19:04:59 -07006223 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6224
6225 Phone phone = getPhone(subId);
6226 if (phone == null) {
6227 try {
6228 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6229 } catch (RemoteException e) {
6230 // ignore
6231 }
6232 return;
6233 }
6234
SongFerngWang0e767992021-03-31 22:08:45 +08006235 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6236 PersistableBundle c = configManager.getConfigForSubId(subId);
6237 boolean requireUssd = c.getBoolean(
6238 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006239
SongFerngWang0e767992021-03-31 22:08:45 +08006240 if (DBG) log("getCallWaitingStatus: subId " + subId);
6241 if (requireUssd) {
6242 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6243 getSubscriptionCarrierId(subId));
6244 CarrierXmlParser.SsEntry.SSAction ssAction =
6245 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6246 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6247 String newUssdCommand = "";
6248 try {
6249 newUssdCommand = carrierXmlParser.getFeature(
6250 CarrierXmlParser.FEATURE_CALL_WAITING)
6251 .makeCommand(ssAction, null);
6252 } catch (NullPointerException e) {
6253 loge("Failed to generate USSD number" + e);
6254 }
6255 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6256 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6257 final String ussdCommand = newUssdCommand;
6258 Executors.newSingleThreadExecutor().execute(() -> {
6259 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6260 });
6261 } else {
6262 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6263 FunctionalUtils.ignoreRemoteException(callback::accept));
6264
6265 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6266 }
Shuo Qian4a594052020-01-23 11:59:30 -08006267 } finally {
6268 Binder.restoreCallingIdentity(identity);
6269 }
6270 }
6271
6272 /**
yinxub1bed742017-04-17 11:45:04 -07006273 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006274 *
yinxub1bed742017-04-17 11:45:04 -07006275 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006276 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6277 * location related information which will be sent if the caller already possess
6278 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006279 * @param request contains the radio access networks with bands/channels to scan
6280 * @param messenger callback messenger for scan results or errors
6281 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006282 * @return the id of the requested scan which can be used to stop the scan.
6283 */
6284 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006285 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6286 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006287 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6289 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006290 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006291 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6292 if (!renounceFineLocationAccess) {
6293 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6294 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6295 .setCallingPackage(callingPackage)
6296 .setCallingFeatureId(callingFeatureId)
6297 .setCallingPid(Binder.getCallingPid())
6298 .setCallingUid(Binder.getCallingUid())
6299 .setMethod("requestNetworkScan")
6300 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6301 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6302 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6303 .build());
6304 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006305 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006306 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6307 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006308 if (e != null) {
6309 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6310 throw e;
6311 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006312 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006313 return TelephonyScanManager.INVALID_SCAN_ID;
6314 }
6315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 }
Hall Liu912dfd32019-04-25 14:02:26 -07006317 int callingUid = Binder.getCallingUid();
6318 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006322 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006323 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006324 } finally {
6325 Binder.restoreCallingIdentity(identity);
6326 }
yinxu504e1392017-04-12 16:03:22 -07006327 }
6328
Hall Liub2ac8ef2019-02-28 15:56:23 -08006329 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006330 NetworkScanRequest request, int subId, String callingPackage) {
6331 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006332 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6333 boolean hasNetworkScanPermission =
6334 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6335 == PERMISSION_GRANTED;
6336
6337 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6338 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6339 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006340 }
6341
6342 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6343 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006344 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6345 return new SecurityException("Specific channels must not be"
6346 + " scanned without location access.");
6347 }
6348 }
6349 }
6350
Hall Liub2ac8ef2019-02-28 15:56:23 -08006351 return null;
6352 }
6353
yinxu504e1392017-04-12 16:03:22 -07006354 /**
6355 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006356 *
6357 * @param subId id of the subscription
6358 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006359 */
6360 @Override
6361 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6363 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364
Hall Liu912dfd32019-04-25 14:02:26 -07006365 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366 final long identity = Binder.clearCallingIdentity();
6367 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006368 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
yinxu504e1392017-04-12 16:03:22 -07006372 }
6373
6374 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006375 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006376 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006377 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006378 */
6379 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006380 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006381 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006382 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006383 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384
6385 final long identity = Binder.clearCallingIdentity();
6386 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006387 if (DBG) log("getAllowedNetworkTypesBitmask");
6388 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6389 int networkTypesBitmask = (result != null ? result[0] : -1);
6390 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6391 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006395 }
6396
6397 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006398 * Get the allowed network types for certain reason.
6399 *
6400 * @param subId the id of the subscription.
6401 * @param reason the reason the allowed network type change is taking place
6402 * @return the allowed network types.
6403 */
6404 @Override
6405 public long getAllowedNetworkTypesForReason(int subId,
6406 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006407 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006408 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
6415 }
6416
6417 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006418 * Enable/Disable E-UTRA-NR Dual Connectivity
6419 * @param subId subscription id of the sim card
6420 * @param nrDualConnectivityState expected NR dual connectivity state
6421 * This can be passed following states
6422 * <ol>
6423 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6424 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6425 * <li>Disable NR dual connectivity and force secondary cell to be released
6426 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6427 * </ol>
6428 * @return operation result.
6429 */
6430 @Override
6431 public int setNrDualConnectivityState(int subId,
6432 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6434 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006435 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006436 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6437 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6438 }
6439
Sooraj Sasindran37444802020-08-11 10:40:43 -07006440 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6444 nrDualConnectivityState, subId,
6445 workSource);
6446 if (DBG) log("enableNRDualConnectivity result: " + result);
6447 return result;
6448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
6451 }
6452
6453 /**
6454 * Is E-UTRA-NR Dual Connectivity enabled
6455 * @return true if dual connectivity is enabled else false
6456 */
6457 @Override
6458 public boolean isNrDualConnectivityEnabled(int subId) {
6459 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006460 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006461 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006462 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006463 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6464 return false;
6465 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006466 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6467 final long identity = Binder.clearCallingIdentity();
6468 try {
6469 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6470 null, subId, workSource);
6471 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6472 return isEnabled;
6473 } finally {
6474 Binder.restoreCallingIdentity(identity);
6475 }
6476 }
6477
6478 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006479 * Set the allowed network types of the device and
6480 * provide the reason triggering the allowed network change.
6481 *
6482 * @param subId the id of the subscription.
6483 * @param reason the reason the allowed network type change is taking place
6484 * @param allowedNetworkTypes the allowed network types.
6485 * @return true on success; false on any failure.
6486 */
6487 @Override
6488 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006489 @TelephonyManager.AllowedNetworkTypesReason int reason,
6490 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6492 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006493 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006494 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6495 return false;
6496 }
6497 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6498 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006499 return false;
6500 }
6501
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006502 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6503 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6504
6505
6506 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6507 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6508 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006509 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006510
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006511 final long identity = Binder.clearCallingIdentity();
6512 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006513 Boolean success = (Boolean) sendRequest(
6514 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6515 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6516
6517 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6518 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
6522 }
6523
6524 /**
Miaoa84611c2019-03-15 09:21:10 +08006525 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006526 *
Miaoa84611c2019-03-15 09:21:10 +08006527 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006528 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006529 * @hide
6530 */
6531 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006532 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006533 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006535 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 try {
Miaoa84611c2019-03-15 09:21:10 +08006537 if (phone != null) {
6538 return phone.hasMatchedTetherApnSetting();
6539 } else {
6540 return false;
6541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 } finally {
6543 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006544 }
Junda Liu475951f2014-11-07 16:45:03 -08006545 }
6546
6547 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006548 * Get the user enabled state of Mobile Data.
6549 *
6550 * TODO: remove and use isUserDataEnabled.
6551 * This can't be removed now because some vendor codes
6552 * calls through ITelephony directly while they should
6553 * use TelephonyManager.
6554 *
6555 * @return true on enabled
6556 */
6557 @Override
6558 public boolean getDataEnabled(int subId) {
6559 return isUserDataEnabled(subId);
6560 }
6561
6562 /**
6563 * Get whether mobile data is enabled per user setting.
6564 *
6565 * There are other factors deciding whether mobile data is actually enabled, but they are
6566 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006567 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006568 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6569 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006570 *
6571 * @return {@code true} if data is enabled else {@code false}
6572 */
6573 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006574 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006575 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006576 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006577 try {
6578 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6579 functionName);
6580 } catch (Exception e) {
6581 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6582 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006583 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006585 mApp, subId, functionName);
6586
Robert Greenwalt646120a2014-05-23 11:54:03 -07006587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588
6589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 int phoneId = mSubscriptionController.getPhoneId(subId);
6592 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6593 Phone phone = PhoneFactory.getPhone(phoneId);
6594 if (phone != null) {
6595 boolean retVal = phone.isUserDataEnabled();
6596 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6597 return retVal;
6598 } else {
6599 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6600 return false;
6601 }
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006604 }
6605 }
6606
6607 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006608 * Checks if the device is capable of mobile data by considering whether whether the
6609 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6610 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006611 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006612 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006613 */
6614 @Override
6615 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006616 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006617 try {
6618 try {
6619 mApp.enforceCallingOrSelfPermission(
6620 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006621 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006622 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006623 try {
6624 mApp.enforceCallingOrSelfPermission(
6625 android.Manifest.permission.READ_PHONE_STATE,
6626 functionName);
6627 } catch (Exception e2) {
6628 mApp.enforceCallingOrSelfPermission(
6629 permission.READ_BASIC_PHONE_STATE, functionName);
6630 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006631 }
6632 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635
6636 final long identity = Binder.clearCallingIdentity();
6637 try {
6638 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 Phone phone = PhoneFactory.getPhone(phoneId);
6640 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006641 boolean retVal;
6642 if (phone.isUsingNewDataStack()) {
Sarah Chin2c094c52022-03-09 13:57:52 -08006643 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006644 } else {
6645 retVal = phone.getDataEnabledSettings().isDataEnabled();
6646 }
6647 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648 return retVal;
6649 } else {
6650 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6651 return false;
6652 }
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006655 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006656 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006657
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006658 /**
6659 * Check if data is enabled for a specific reason
6660 * @param subId Subscription index
6661 * @param reason the reason the data enable change is taking place
6662 * @return {@code true} if the overall data is enabled; {@code false} if not.
6663 */
6664 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006666 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006667 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006668 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006669 try {
6670 mApp.enforceCallingOrSelfPermission(
6671 android.Manifest.permission.ACCESS_NETWORK_STATE,
6672 functionName);
6673 } catch (Exception e) {
6674 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6675 functionName);
6676 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006677 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006678 try {
6679 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006680 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006681 } catch (Exception e2) {
6682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006683 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006684 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 }
6686
6687
6688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 int phoneId = mSubscriptionController.getPhoneId(subId);
6691 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006692 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006693 + " reason=" + reason);
6694 }
6695 Phone phone = PhoneFactory.getPhone(phoneId);
6696 if (phone != null) {
6697 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006698 if (phone.isUsingNewDataStack()) {
6699 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006700 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006701 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6702 retVal = phone.isUserDataEnabled();
6703 } else {
6704 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6705 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006706 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006707 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006708 return retVal;
6709 } else {
6710 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006711 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006712 + subId + " retVal=false");
6713 }
6714 return false;
6715 }
6716 } finally {
6717 Binder.restoreCallingIdentity(identity);
6718 }
6719 }
6720
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006721 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006722 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006723 // No permission needed; this only lets the caller inspect their own status.
6724 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006725 }
Junda Liu29340342014-07-10 15:23:27 -07006726
6727 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006728 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006729 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006730 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6731 }
6732
6733 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6734 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006736 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006737 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6738 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006739 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6740 if (cpt == null) {
6741 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006742 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6743 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006744 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006745 }
6746
6747 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006748 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006749 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006750 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006752 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006753 Phone phone = getPhone(subId);
6754 if (phone == null) {
6755 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6757 }
6758 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6759 if (cpt == null) {
6760 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6762 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006763 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006764 }
6765
6766 @Override
6767 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006768 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006769 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6770 }
6771
6772 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006773 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006775 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006776 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006777 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6778 Phone phone = PhoneFactory.getPhone(phoneId);
6779 if (phone == null) {
6780 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006781 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006782 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6783 if (cpt == null) {
6784 continue;
6785 }
6786 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006787 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6788 break;
6789 }
6790 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006791 return result;
Junda Liu29340342014-07-10 15:23:27 -07006792 }
Derek Tan89e89d42014-07-08 17:00:10 -07006793
6794 @Override
Junda Liue64de782015-04-16 17:19:16 -07006795 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006796 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006797 Phone phone = PhoneFactory.getPhone(phoneId);
6798 if (phone == null) {
6799 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006800 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006801 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6802 if (cpt == null) {
6803 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006804 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006805 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006806 }
6807
Amith Yamasani6e118872016-02-19 12:53:51 -08006808 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006809 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006810 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006811 Phone phone = PhoneFactory.getPhone(phoneId);
6812 if (phone == null) {
6813 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006814 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006815 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6816 if (cpt == null) {
6817 return Collections.emptyList();
6818 }
6819 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006820 }
6821
chen xuf7e9fe82019-05-09 19:31:02 -07006822 @Override
6823 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006824 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006825 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006826 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006827 try {
6828 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6829 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6830 }
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006833 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006834 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006835 }
6836
Rambo Wang6812ffb2022-03-15 16:54:17 -07006837 @Override
6838 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6839 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6840
6841 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6842 if (phone == null) {
6843 return null;
6844 }
6845 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6846 if (cpt == null) {
6847 return null;
6848 }
6849 return cpt.getCarrierServicePackageName();
6850 }
6851
Wink Savilleb564aae2014-10-23 10:18:09 -07006852 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006853 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006854 UiccPort port = phone == null ? null : phone.getUiccPort();
6855 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006856 return null;
6857 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006858 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006859 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006860 return null;
6861 }
6862 return iccId;
6863 }
6864
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006865 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006866 public void setCallComposerStatus(int subId, int status) {
6867 enforceModifyPermission();
6868
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
6871 Phone phone = getPhone(subId);
6872 if (phone != null) {
6873 Phone defaultPhone = phone.getImsPhone();
6874 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6875 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6876 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006877 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6878 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006879 }
6880 }
Shuo Qian284ae752020-12-22 19:10:14 -08006881 } catch (ImsException e) {
6882 throw new ServiceSpecificException(e.getCode());
6883 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006884 Binder.restoreCallingIdentity(identity);
6885 }
6886 }
6887
6888 @Override
6889 public int getCallComposerStatus(int subId) {
6890 enforceReadPrivilegedPermission("getCallComposerStatus");
6891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
6894 Phone phone = getPhone(subId);
6895 if (phone != null) {
6896 Phone defaultPhone = phone.getImsPhone();
6897 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6898 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6899 return imsPhone.getCallComposerStatus();
6900 }
6901 }
6902 } finally {
6903 Binder.restoreCallingIdentity(identity);
6904 }
6905 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6906 }
6907
6908 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006909 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6910 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006911 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006912 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 final long identity = Binder.clearCallingIdentity();
6915 try {
6916 final String iccId = getIccId(subId);
6917 final Phone phone = getPhone(subId);
6918 if (phone == null) {
6919 return false;
6920 }
6921 final String subscriberId = phone.getSubscriberId();
6922
6923 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006924 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 + subscriberId + " to " + number);
6926 }
6927
6928 if (TextUtils.isEmpty(iccId)) {
6929 return false;
6930 }
6931
6932 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6933
6934 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6935 if (alphaTag == null) {
6936 editor.remove(alphaTagPrefKey);
6937 } else {
6938 editor.putString(alphaTagPrefKey, alphaTag);
6939 }
6940
6941 // Record both the line number and IMSI for this ICCID, since we need to
6942 // track all merged IMSIs based on line number
6943 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6944 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6945 if (number == null) {
6946 editor.remove(numberPrefKey);
6947 editor.remove(subscriberPrefKey);
6948 } else {
6949 editor.putString(numberPrefKey, number);
6950 editor.putString(subscriberPrefKey, subscriberId);
6951 }
6952
6953 editor.commit();
6954 return true;
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006957 }
Derek Tan7226c842014-07-02 17:42:23 -07006958 }
6959
6960 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006961 public String getLine1NumberForDisplay(int subId, String callingPackage,
6962 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006963 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006965 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006966 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006967 return null;
6968 }
Derek Tan97ebb422014-09-05 16:55:38 -07006969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 final long identity = Binder.clearCallingIdentity();
6971 try {
6972 String iccId = getIccId(subId);
6973 if (iccId != null) {
6974 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6975 if (DBG_MERGE) {
6976 log("getLine1NumberForDisplay returning "
6977 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6978 }
6979 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6982 return null;
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006985 }
Derek Tan7226c842014-07-02 17:42:23 -07006986 }
6987
6988 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006989 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6990 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006992 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006993 return null;
6994 }
Derek Tan97ebb422014-09-05 16:55:38 -07006995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 String iccId = getIccId(subId);
6999 if (iccId != null) {
7000 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7001 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7002 }
7003 return null;
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007006 }
Derek Tan7226c842014-07-02 17:42:23 -07007007 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007008
7009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007010 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7011 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007012 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7013 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007015 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007016 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007017 return null;
7018 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007019
Jordan Liub49b04b2019-05-06 14:45:15 -07007020 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7021 // the process, where TelephonyManager was instantiated.
7022 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007023 final long identity = Binder.clearCallingIdentity();
7024 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007025 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 final TelephonyManager tele = TelephonyManager.from(context);
7027 final SubscriptionManager sub = SubscriptionManager.from(context);
7028
7029 // Figure out what subscribers are currently active
7030 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031
Jordan Liub49b04b2019-05-06 14:45:15 -07007032 // Only consider subs which match the current subId
7033 // This logic can be simplified. See b/131189269 for progress.
7034 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007035 activeSubscriberIds.add(tele.getSubscriberId(subId));
7036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037
7038 // First pass, find a number override for an active subscriber
7039 String mergeNumber = null;
7040 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7041 for (String key : prefs.keySet()) {
7042 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7043 final String subscriberId = (String) prefs.get(key);
7044 if (activeSubscriberIds.contains(subscriberId)) {
7045 final String iccId = key.substring(
7046 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7047 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7048 mergeNumber = (String) prefs.get(numberKey);
7049 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007050 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 + " for active subscriber " + subscriberId);
7052 }
7053 if (!TextUtils.isEmpty(mergeNumber)) {
7054 break;
7055 }
7056 }
7057 }
7058 }
7059
7060 // Shortcut when no active merged subscribers
7061 if (TextUtils.isEmpty(mergeNumber)) {
7062 return null;
7063 }
7064
7065 // Second pass, find all subscribers under that line override
7066 final ArraySet<String> result = new ArraySet<>();
7067 for (String key : prefs.keySet()) {
7068 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7069 final String number = (String) prefs.get(key);
7070 if (mergeNumber.equals(number)) {
7071 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7072 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7073 final String subscriberId = (String) prefs.get(subscriberKey);
7074 if (!TextUtils.isEmpty(subscriberId)) {
7075 result.add(subscriberId);
7076 }
7077 }
7078 }
7079 }
7080
7081 final String[] resultArray = result.toArray(new String[result.size()]);
7082 Arrays.sort(resultArray);
7083 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007084 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7086 }
7087 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007088 } finally {
7089 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007090 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007091 }
7092
7093 @Override
zoey chen38003472019-12-13 17:16:31 +08007094 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7095 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007096
7097 final long identity = Binder.clearCallingIdentity();
7098 try {
7099 final TelephonyManager telephonyManager = mApp.getSystemService(
7100 TelephonyManager.class);
7101 String subscriberId = telephonyManager.getSubscriberId(subId);
7102 if (subscriberId == null) {
7103 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007104 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007105 + subId);
7106 }
7107 return null;
7108 }
7109
7110 final SubscriptionInfo info = SubscriptionController.getInstance()
7111 .getSubscriptionInfo(subId);
7112 final ParcelUuid groupUuid = info.getGroupUuid();
7113 // If it doesn't belong to any group, return just subscriberId of itself.
7114 if (groupUuid == null) {
7115 return new String[]{subscriberId};
7116 }
7117
7118 // Get all subscriberIds from the group.
7119 final List<String> mergedSubscriberIds = new ArrayList<>();
7120 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007121 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007122 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007123 for (SubscriptionInfo subInfo : groupInfos) {
7124 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7125 if (subscriberId != null) {
7126 mergedSubscriberIds.add(subscriberId);
7127 }
7128 }
7129
7130 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
7133
7134 }
7135 }
7136
7137 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007138 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007139 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007140 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141
7142 final long identity = Binder.clearCallingIdentity();
7143 try {
7144 final Phone phone = getPhone(subId);
7145 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
7148 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007149 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007150
7151 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007152 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007153 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7154 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007155 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7156 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157
7158 final long identity = Binder.clearCallingIdentity();
7159 try {
7160 final Phone phone = getPhone(subId);
7161 if (phone == null) {
7162 return false;
7163 }
7164 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7165 cdmaNonRoamingList);
7166 } finally {
7167 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007168 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007169 }
7170
7171 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007172 @Deprecated
7173 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7174 enforceModifyPermission();
7175
7176 int returnValue = 0;
7177 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007178 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007179 if(result.exception == null) {
7180 if (result.result != null) {
7181 byte[] responseData = (byte[])(result.result);
7182 if(responseData.length > oemResp.length) {
7183 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7184 responseData.length + "bytes. Buffer Size is " +
7185 oemResp.length + "bytes.");
7186 }
7187 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7188 returnValue = responseData.length;
7189 }
7190 } else {
7191 CommandException ex = (CommandException) result.exception;
7192 returnValue = ex.getCommandError().ordinal();
7193 if(returnValue > 0) returnValue *= -1;
7194 }
7195 } catch (RuntimeException e) {
7196 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7197 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7198 if(returnValue > 0) returnValue *= -1;
7199 }
7200
7201 return returnValue;
7202 }
7203
7204 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007205 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007206 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007207 try {
7208 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007209 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007210 mApp, phone.getSubId(), "getRadioAccessFamily");
7211 } catch (SecurityException e) {
7212 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7213 throw e;
7214 }
chen xub97461a2018-10-26 14:17:57 -07007215 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007216 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007217 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 final long identity = Binder.clearCallingIdentity();
7220 try {
chen xub97461a2018-10-26 14:17:57 -07007221 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007222 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007223 mApp, phone.getSubId(), "getRadioAccessFamily");
7224 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227 }
chen xub97461a2018-10-26 14:17:57 -07007228 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007229 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007230
7231 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007232 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007233 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007234 try {
7235 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7236 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007237 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007238 }
7239 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007240 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007241 }
7242 RoleManager rm = mApp.getSystemService(RoleManager.class);
7243 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7244 if (!dialerRoleHolders.contains(callingPackage)) {
7245 throw new SecurityException("App must be the dialer role holder to"
7246 + " upload a call composer pic");
7247 }
7248
7249 Executors.newSingleThreadExecutor().execute(() -> {
7250 ByteArrayOutputStream output = new ByteArrayOutputStream(
7251 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7252 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7253 boolean readUntilEnd = false;
7254 int totalBytesRead = 0;
7255 byte[] buffer = new byte[16 * 1024];
7256 while (true) {
7257 int numRead;
7258 try {
7259 numRead = input.read(buffer);
7260 } catch (IOException e) {
7261 try {
7262 fd.checkError();
7263 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7264 null);
7265 } catch (IOException e1) {
7266 // This means that the other side closed explicitly with an error. If this
7267 // happens, log and ignore.
7268 loge("Remote end of call composer picture pipe closed: " + e1);
7269 }
7270 break;
7271 }
7272 if (numRead == -1) {
7273 readUntilEnd = true;
7274 break;
7275 }
7276 totalBytesRead += numRead;
7277 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7278 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7279 try {
7280 input.close();
7281 } catch (IOException e) {
7282 // ignore
7283 }
7284 break;
7285 }
7286 output.write(buffer, 0, numRead);
7287 }
7288 // Generally, the remote end will close the file descriptors. The only case where we
7289 // close is above, where the picture size is too big.
7290
7291 try {
7292 fd.checkError();
7293 } catch (IOException e) {
7294 loge("Remote end for call composer closed with an error: " + e);
7295 return;
7296 }
7297
Hall Liuaa4211e2021-01-20 15:43:39 -08007298 if (!readUntilEnd) {
7299 loge("Did not finish reading entire image; aborting");
7300 return;
7301 }
Hall Liu82694d52020-12-11 18:22:04 -08007302
Hall Liuaa4211e2021-01-20 15:43:39 -08007303 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7304 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7305 new CallComposerPictureTransfer.Factory() {},
7306 imageData,
7307 (result) -> {
7308 if (result.first != null) {
7309 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7310 Bundle outputResult = new Bundle();
7311 outputResult.putParcelable(
7312 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7313 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7314 outputResult);
7315 } else {
7316 callback.send(result.second, null);
7317 }
7318 }
7319 );
Hall Liu82694d52020-12-11 18:22:04 -08007320 });
7321 }
7322
7323 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007324 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007325 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007326 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327
7328 final long identity = Binder.clearCallingIdentity();
7329 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007330 ImsManager.getInstance(defaultPhone.getContext(),
7331 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 } finally {
7333 Binder.restoreCallingIdentity(identity);
7334 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007335 }
7336
7337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007338 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007339 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7341 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007342 return false;
7343 }
Svet Ganovb320e182015-04-16 12:30:10 -07007344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 // Check the user preference and the system-level IMS setting. Even if the user has
7348 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7349 // In the long run, we may instead need to check if there exists a connection service
7350 // which can support video calling.
7351 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007352 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 return imsManager.isVtEnabledByPlatform()
7354 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7355 && imsManager.isVtEnabledByUser();
7356 } finally {
7357 Binder.restoreCallingIdentity(identity);
7358 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007359 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007360
Andrew Leea1239f22015-03-02 17:44:07 -08007361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007362 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7363 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007365 mApp, subId, callingPackage, callingFeatureId,
7366 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 return false;
7368 }
7369
7370 final long identity = Binder.clearCallingIdentity();
7371 try {
7372 CarrierConfigManager configManager =
7373 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007374 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
7378 }
Andrew Leea1239f22015-03-02 17:44:07 -08007379 }
7380
7381 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007382 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007384 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 return false;
7386 }
7387
7388 final long identity = Binder.clearCallingIdentity();
7389 try {
7390 CarrierConfigManager configManager =
7391 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7394 } finally {
7395 Binder.restoreCallingIdentity(identity);
7396 }
Andrew Leea1239f22015-03-02 17:44:07 -08007397 }
7398
Andrew Lee9431b832015-03-09 18:46:45 -07007399 @Override
7400 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007401 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007402 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007403 }
7404
7405 @Override
7406 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 final long identity = Binder.clearCallingIdentity();
7408 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007409 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 } finally {
7411 Binder.restoreCallingIdentity(identity);
7412 }
Andrew Lee9431b832015-03-09 18:46:45 -07007413 }
7414
Hall Liuf6668912018-10-31 17:05:23 -07007415 /**
7416 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7417 * support for the feature and device firmware support.
7418 *
7419 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7420 */
7421 @Override
7422 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007424 final Phone phone = getPhone(subscriptionId);
7425 if (phone == null) {
7426 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7427 return false;
7428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007430 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7432 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007433 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 return isCarrierSupported && isDeviceSupported;
7435 } finally {
7436 Binder.restoreCallingIdentity(identity);
7437 }
Hall Liu98187582018-01-22 19:15:32 -08007438 }
7439
Hall Liuf6668912018-10-31 17:05:23 -07007440 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007441 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7442 * RTT setting, will return true if the device and carrier both support RTT.
7443 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007444 */
7445 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 final long identity = Binder.clearCallingIdentity();
7447 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007448 boolean isRttSupported = isRttSupported(subscriptionId);
7449 boolean isUserRttSettingOn = Settings.Secure.getInt(
7450 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7451 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7452 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7453 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 } finally {
7455 Binder.restoreCallingIdentity(identity);
7456 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007457 }
7458
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007459 @Deprecated
7460 @Override
7461 public String getDeviceId(String callingPackage) {
7462 return getDeviceIdWithFeature(callingPackage, null);
7463 }
7464
Sanket Padawe7310cc72015-01-14 09:53:20 -08007465 /**
7466 * Returns the unique device ID of phone, for example, the IMEI for
7467 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7468 *
7469 * <p>Requires Permission:
7470 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7471 */
7472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007473 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007474 try {
7475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7476 } catch (SecurityException se) {
7477 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7478 throw new SecurityException("Package " + callingPackage + " does not belong to "
7479 + Binder.getCallingUid());
7480 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007481 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007482 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007483 return null;
7484 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007485 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007486 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007488 return null;
7489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
7493 return phone.getDeviceId();
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007497 }
7498
Ping Sunc67b7c22016-03-02 19:16:45 +08007499 /**
7500 * {@hide}
7501 * Returns the IMS Registration Status on a particular subid
7502 *
7503 * @param subId
7504 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007505 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007506 Phone phone = getPhone(subId);
7507 if (phone != null) {
7508 return phone.isImsRegistered();
7509 } else {
7510 return false;
7511 }
7512 }
7513
Santos Cordon7a1885b2015-02-03 11:15:19 -08007514 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007515 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007518 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007519 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7520 }
7521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
7527 }
7528
7529 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007530 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007531 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007532 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007533 mApp,
7534 subscriptionId,
7535 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 Phone phone = getPhone(subscriptionId);
7539 if (phone == null) {
7540 return null;
7541 }
7542 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
7546 }
7547
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007548 /**
7549 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007550 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007551 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 Phone phone = getPhone(subId);
7555 if (phone != null) {
7556 return phone.isWifiCallingEnabled();
7557 } else {
7558 return false;
7559 }
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007562 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007563 }
7564
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007565 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007566 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007567 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007568 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 Phone phone = getPhone(subId);
7572 if (phone != null) {
7573 return phone.isVideoEnabled();
7574 } else {
7575 return false;
7576 }
7577 } finally {
7578 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007579 }
7580 }
7581
7582 /**
7583 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7584 * defined in {@link ImsRegistrationImplBase}.
7585 */
7586 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 Phone phone = getPhone(subId);
7590 if (phone != null) {
7591 return phone.getImsRegistrationTech();
7592 } else {
7593 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7594 }
7595 } finally {
7596 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007597 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007598 }
7599
Stuart Scott8eef64f2015-04-08 15:13:54 -07007600 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007601 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007602 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007603 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7604 return;
7605 }
Kai Shif70f46f2021-03-03 13:59:46 -08007606 Phone defaultPhone = getDefaultPhone();
7607 if (defaultPhone != null) {
7608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7609 mApp, getDefaultPhone().getSubId(), "factoryReset");
7610 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007611 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007612
Svet Ganovcc087f82015-05-12 20:35:54 -07007613 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007614 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7615 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007616 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007617 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007618 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007619 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007620 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007621 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007622 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007623 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007624 // There has been issues when Sms raw table somehow stores orphan
7625 // fragments. They lead to garbled message when new fragments come
7626 // in and combined with those stale ones. In case this happens again,
7627 // user can reset all network settings which will clean up this table.
7628 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007629 // Clean up IMS settings as well here.
7630 int slotId = getSlotIndex(subId);
7631 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7632 ImsManager.getInstance(mApp, slotId).factoryReset();
7633 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007634
Kai Shif70f46f2021-03-03 13:59:46 -08007635 if (defaultPhone == null) {
7636 return;
7637 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007638 // Erase modem config if erase modem on network setting is enabled.
7639 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7640 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7641 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007642 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007643 }
Kai Shif70f46f2021-03-03 13:59:46 -08007644
7645 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007646 } finally {
7647 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007648 }
7649 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007650
SongFerngWangfd89b102021-05-27 22:44:54 +08007651 @VisibleForTesting
7652 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7653 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7654 return;
7655 }
7656 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7657 RILConstants.PREFERRED_NETWORK_MODE);
7658 SubscriptionManager.setSubscriptionProperty(subId,
7659 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7660 "user=" + defaultNetworkType);
7661 phone.loadAllowedNetworksFromSubscriptionDatabase();
7662 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7663 defaultNetworkType, null);
7664 }
7665
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007666 private void cleanUpSmsRawTable(Context context) {
7667 ContentResolver resolver = context.getContentResolver();
7668 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7669 resolver.delete(uri, null, null);
7670 }
7671
Narayan Kamath1c496c22015-04-16 14:40:19 +01007672 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007673 public String getSimLocaleForSubscriber(int subId) {
7674 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7675 final Phone phone = getPhone(subId);
7676 if (phone == null) {
7677 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007678 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 final long identity = Binder.clearCallingIdentity();
7681 try {
chen xu5d3637b2019-01-21 23:31:38 -08007682 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007683 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007684 if (info == null) {
7685 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7686 return null;
7687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 // Try and fetch the locale from the carrier properties or from the SIM language
7689 // preferences (EF-PL and EF-LI)...
7690 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007692 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7693 if (localeFromDefaultSim != null) {
7694 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7695 if (DBG) log("Using locale from subId: " + subId + " locale: "
7696 + localeFromDefaultSim);
7697 return localeFromDefaultSim.toLanguageTag();
7698 } else {
7699 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 }
7701 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 // The SIM language preferences only store a language (e.g. fr = French), not an
7704 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7705 // the SIM and carrier preferences does not include a country we add the country
7706 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007707 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007709 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 return mccLocale.toLanguageTag();
7711 }
7712
7713 if (DBG) log("No locale found - returning null");
7714 return null;
7715 } finally {
7716 Binder.restoreCallingIdentity(identity);
7717 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007718 }
7719
7720 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007721 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007722 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007723 }
7724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 /**
7726 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7727 */
7728 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007729 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007730 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007731 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007732
Gary Jian3aa9a762022-01-24 16:41:19 +08007733 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7734 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007735
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007736 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007737 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7738 * representing the state of the modem.
7739 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007740 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7741 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007742 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007743 */
7744 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007745 public void requestModemActivityInfo(ResultReceiver result) {
7746 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007747 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748
7749 final long identity = Binder.clearCallingIdentity();
7750 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007751 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 } finally {
7753 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007754 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007755 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007756
Siddharth Rayb8114062018-06-17 15:02:38 -07007757 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7758 // less than total activity duration.
7759 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7760 if (info == null) {
7761 return false;
7762 }
7763 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007764 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7765 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7766
Siddharth Rayb8114062018-06-17 15:02:38 -07007767 return (info.isValid()
7768 && (info.getSleepTimeMillis() <= activityDurationMs)
7769 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007770 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007771 && (totalTxTimeMs <= activityDurationMs));
7772 }
7773
Gary Jian3aa9a762022-01-24 16:41:19 +08007774 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7775 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7776 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7777 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7778
7779 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7780 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7781 }
7782
7783 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7784 mLastModemActivityInfo.setReceiveTimeMillis(
7785 rat,
7786 freq,
7787 info.getReceiveTimeMillis(rat, freq)
7788 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7789 }
7790
7791 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7792 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7793 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7794 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7795
7796 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7797 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7798 }
7799 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7800 mLastModemActivityInfo.setReceiveTimeMillis(
7801 rat,
7802 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7803 }
7804
7805 /**
7806 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7807 * @param info recent ModemActivityInfo
7808 */
7809 private void mergeModemActivityInfo(ModemActivityInfo info) {
7810 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7811 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7812 boolean matched;
7813 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7814 matched = false;
7815 int rat = info.getSpecificInfoRat(i);
7816 int freq = info.getSpecificInfoFrequencyRange(i);
7817 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7818 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7819 //if it already exists
7820 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7821 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7822 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7823 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7824 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7825 updateLastModemActivityInfo(info, rat, freq);
7826 matched = true;
7827 }
7828 } else {
7829 updateLastModemActivityInfo(info, rat);
7830 matched = true;
7831 }
7832 }
7833 }
7834
7835 if (!matched) {
7836 mDeltaSpecificInfo =
7837 new ActivityStatsTechSpecificInfo(
7838 rat,
7839 freq,
7840 info.getTransmitTimeMillis(rat, freq),
7841 (int) info.getReceiveTimeMillis(rat, freq));
7842 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7843 }
7844 }
7845 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7846 mLastModemActivitySpecificInfo =
7847 new ActivityStatsTechSpecificInfo[merged.size()];
7848 merged.toArray(mLastModemActivitySpecificInfo);
7849
7850 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7851 mLastModemActivityInfo.setSleepTimeMillis(
7852 info.getSleepTimeMillis()
7853 + mLastModemActivityInfo.getSleepTimeMillis());
7854 mLastModemActivityInfo.setIdleTimeMillis(
7855 info.getIdleTimeMillis()
7856 + mLastModemActivityInfo.getIdleTimeMillis());
7857 }
7858
Jack Yu85bd38a2015-11-09 11:34:32 -08007859 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007860 * Returns the service state information on specified subscription.
7861 */
7862 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007863 public ServiceState getServiceStateForSubscriber(int subId,
7864 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7865 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007867 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007868 return null;
7869 }
7870
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007871 boolean hasFinePermission = false;
7872 boolean hasCoarsePermission = false;
7873 if (!renounceFineLocationAccess) {
7874 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7875 LocationAccessPolicy.checkLocationPermission(mApp,
7876 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7877 .setCallingPackage(callingPackage)
7878 .setCallingFeatureId(callingFeatureId)
7879 .setCallingPid(Binder.getCallingPid())
7880 .setCallingUid(Binder.getCallingUid())
7881 .setMethod("getServiceStateForSubscriber")
7882 .setLogAsInfo(true)
7883 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7884 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7885 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7886 .build());
7887 hasFinePermission =
7888 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7889 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007890
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007891 if (!renounceCoarseLocationAccess) {
7892 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7893 LocationAccessPolicy.checkLocationPermission(mApp,
7894 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7895 .setCallingPackage(callingPackage)
7896 .setCallingFeatureId(callingFeatureId)
7897 .setCallingPid(Binder.getCallingPid())
7898 .setCallingUid(Binder.getCallingUid())
7899 .setMethod("getServiceStateForSubscriber")
7900 .setLogAsInfo(true)
7901 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7902 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7903 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7904 .build());
7905 hasCoarsePermission =
7906 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7907 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007908
Jack Yu479f40e2020-10-27 21:29:25 -07007909 final Phone phone = getPhone(subId);
7910 if (phone == null) {
7911 return null;
7912 }
7913
Jordan Liu0f2bc442020-11-18 16:47:37 -08007914 final long identity = Binder.clearCallingIdentity();
7915
Jack Yu479f40e2020-10-27 21:29:25 -07007916 boolean isCallingPackageDataService = phone.getDataServicePackages()
7917 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007918 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007919 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7920 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7921 Rlog.d(LOG_TAG,
7922 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7923 return null;
7924 }
7925
Hall Liuf19c44f2018-11-27 14:38:17 -08007926 ServiceState ss = phone.getServiceState();
7927
7928 // Scrub out the location info in ServiceState depending on what level of access
7929 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007930 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007931 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7932 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 } finally {
7934 Binder.restoreCallingIdentity(identity);
7935 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007936 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007937
7938 /**
7939 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7940 *
7941 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7942 * voicemail ringtone.
7943 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7944 * PhoneAccount.
7945 */
7946 @Override
7947 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 final long identity = Binder.clearCallingIdentity();
7949 try {
7950 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7951 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007952 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007959 }
7960
7961 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007962 * Sets the per-account voicemail ringtone.
7963 *
7964 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7965 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7966 *
7967 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7968 * voicemail ringtone.
7969 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7970 * PhoneAccount.
7971 */
7972 @Override
7973 public void setVoicemailRingtoneUri(String callingPackage,
7974 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007975 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007977 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7978 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7980 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7981 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983
7984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7987 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 }
7990 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007993 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007994 }
7995
7996 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007997 * Returns whether vibration is set for voicemail notification in Phone settings.
7998 *
7999 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8000 * voicemail vibration setting.
8001 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8002 */
8003 @Override
8004 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8008 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008009 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008016 }
8017
Youhan Wange64578a2016-05-02 15:32:42 -07008018 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 * Sets the per-account voicemail vibration.
8020 *
8021 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8022 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8023 *
8024 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8025 * voicemail vibration setting.
8026 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8027 * specific PhoneAccount.
8028 */
8029 @Override
8030 public void setVoicemailVibrationEnabled(String callingPackage,
8031 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008032 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008034 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8035 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8037 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8038 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008039 }
8040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8044 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008045 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046 }
8047 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008050 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008051 }
8052
8053 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008054 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8055 *
8056 * @throws SecurityException if the caller does not have the required permission
8057 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008058 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008059 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008060 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008061 }
8062
8063 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008064 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8065 * permission.
8066 *
8067 * @throws SecurityException if the caller does not have the required permission
8068 */
8069 private void enforceSendSmsPermission() {
8070 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8071 }
8072
8073 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008074 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008075 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008076 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008077 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008078 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008082 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 if (componentName == null) {
8084 throw new SecurityException(
8085 "Caller not current active visual voicemail package[null]");
8086 }
8087 String vvmPackage = componentName.getPackageName();
8088 if (!callingPackage.equals(vvmPackage)) {
8089 throw new SecurityException("Caller not current active visual voicemail package["
8090 + vvmPackage + "]");
8091 }
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008094 }
8095 }
8096
8097 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008098 * Return the application ID for the app type.
8099 *
8100 * @param subId the subscription ID that this request applies to.
8101 * @param appType the uicc app type.
8102 * @return Application ID for specificied app type, or null if no uicc.
8103 */
8104 @Override
8105 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008106 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008107 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108
8109 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008110 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 if (phone == null) {
8112 return null;
8113 }
8114 String aid = null;
8115 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008116 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 .getApplicationByType(appType).getAid();
8118 } catch (Exception e) {
8119 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8120 }
8121 return aid;
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008124 }
Youhan Wange64578a2016-05-02 15:32:42 -07008125 }
8126
Youhan Wang4001d252016-05-11 10:29:41 -07008127 /**
8128 * Return the Electronic Serial Number.
8129 *
8130 * @param subId the subscription ID that this request applies to.
8131 * @return ESN or null if error.
8132 */
8133 @Override
8134 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008135 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008136 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137
8138 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008139 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008140 if (phone == null) {
8141 return null;
8142 }
8143 String esn = null;
8144 try {
8145 esn = phone.getEsn();
8146 } catch (Exception e) {
8147 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8148 }
8149 return esn;
8150 } finally {
8151 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008152 }
Youhan Wang4001d252016-05-11 10:29:41 -07008153 }
8154
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008155 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008156 * Return the Preferred Roaming List Version.
8157 *
8158 * @param subId the subscription ID that this request applies to.
8159 * @return PRLVersion or null if error.
8160 */
8161 @Override
8162 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008163 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008164 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165
8166 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008167 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168 if (phone == null) {
8169 return null;
8170 }
8171 String cdmaPrlVersion = null;
8172 try {
8173 cdmaPrlVersion = phone.getCdmaPrlVersion();
8174 } catch (Exception e) {
8175 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8176 }
8177 return cdmaPrlVersion;
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008180 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008181 }
8182
8183 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008184 * Get snapshot of Telephony histograms
8185 * @return List of Telephony histograms
8186 * @hide
8187 */
8188 @Override
8189 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8191 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192
8193 final long identity = Binder.clearCallingIdentity();
8194 try {
8195 return RIL.getTelephonyRILTimingHistograms();
8196 } finally {
8197 Binder.restoreCallingIdentity(identity);
8198 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008199 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008200
8201 /**
8202 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008203 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8204 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008205 * Require system privileges. In the future we may add this to carrier APIs.
8206 *
Michele Berionne482f8202018-11-27 18:57:59 -08008207 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008208 */
8209 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008210 @TelephonyManager.SetCarrierRestrictionResult
8211 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008212 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008214
Michele Berionne482f8202018-11-27 18:57:59 -08008215 if (carrierRestrictionRules == null) {
8216 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008217 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 final long identity = Binder.clearCallingIdentity();
8220 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008221 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008222 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 } finally {
8224 Binder.restoreCallingIdentity(identity);
8225 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008226 }
8227
8228 /**
8229 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008230 * Get the allowed carrier list and the excluded carrier list, including the priority between
8231 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008232 * Require system privileges. In the future we may add this to carrier APIs.
8233 *
Michele Berionne482f8202018-11-27 18:57:59 -08008234 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008235 */
8236 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008237 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008238 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008239 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240
8241 final long identity = Binder.clearCallingIdentity();
8242 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008243 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8244 if (response instanceof CarrierRestrictionRules) {
8245 return (CarrierRestrictionRules) response;
8246 }
8247 // Response is an Exception of some kind,
8248 // which is signalled to the user as a NULL retval
8249 return null;
8250 } catch (Exception e) {
8251 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8252 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 } finally {
8254 Binder.restoreCallingIdentity(identity);
8255 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256 }
8257
fionaxu59545b42016-05-25 15:53:37 -07008258 /**
fionaxu59545b42016-05-25 15:53:37 -07008259 * Action set from carrier signalling broadcast receivers to enable/disable radio
8260 * @param subId the subscription ID that this action applies to.
8261 * @param enabled control enable or disable radio.
8262 * {@hide}
8263 */
8264 @Override
8265 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8266 enforceModifyPermission();
8267 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268
8269 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008270 if (phone == null) {
8271 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8272 return;
8273 }
8274 try {
8275 phone.carrierActionSetRadioEnabled(enabled);
8276 } catch (Exception e) {
8277 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008280 }
8281 }
8282
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008283 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008284 * Enable or disable Voice over NR (VoNR)
8285 * @param subId the subscription ID that this action applies to.
8286 * @param enabled enable or disable VoNR.
8287 * @return operation result.
8288 */
8289 @Override
8290 public int setVoNrEnabled(int subId, boolean enabled) {
8291 enforceModifyPermission();
8292 final Phone phone = getPhone(subId);
8293
8294 final long identity = Binder.clearCallingIdentity();
8295 if (phone == null) {
8296 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8297 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8298 }
8299
8300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8301 try {
8302 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8303 workSource);
8304 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008305
8306 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8307 if (DBG) {
8308 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8309 }
8310 SubscriptionManager.setSubscriptionProperty(
8311 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8312 (enabled ? "1" : "0"));
8313 }
8314
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008315 return result;
8316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
8319 }
8320
8321 /**
8322 * Is voice over NR enabled
8323 * @return true if VoNR is enabled else false
8324 */
8325 @Override
8326 public boolean isVoNrEnabled(int subId) {
8327 enforceReadPrivilegedPermission("isVoNrEnabled");
8328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8332 null, subId, workSource);
8333 if (DBG) log("isVoNrEnabled: " + isEnabled);
8334 return isEnabled;
8335 } finally {
8336 Binder.restoreCallingIdentity(identity);
8337 }
8338 }
8339
8340 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008341 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8342 * network status based on which carrier apps could apply actions accordingly,
8343 * enable/disable default url handler for example.
8344 *
8345 * @param subId the subscription ID that this action applies to.
8346 * @param report control start/stop reporting the default network status.
8347 * {@hide}
8348 */
8349 @Override
8350 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8351 enforceModifyPermission();
8352 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353
8354 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008355 if (phone == null) {
8356 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8357 return;
8358 }
8359 try {
8360 phone.carrierActionReportDefaultNetworkStatus(report);
8361 } catch (Exception e) {
8362 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363 } finally {
8364 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008365 }
8366 }
8367
8368 /**
fionaxud9622282017-07-17 17:51:30 -07008369 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8370 * @param subId the subscription ID that this action applies to.
8371 * {@hide}
8372 */
8373 @Override
8374 public void carrierActionResetAll(int subId) {
8375 enforceModifyPermission();
8376 final Phone phone = getPhone(subId);
8377 if (phone == null) {
8378 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8379 return;
8380 }
8381 try {
8382 phone.carrierActionResetAll();
8383 } catch (Exception e) {
8384 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8385 }
8386 }
8387
8388 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008389 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8390 * bug report is being generated.
8391 */
8392 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008393 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008394 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8395 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008396 writer.println("Permission Denial: can't dump Phone from pid="
8397 + Binder.getCallingPid()
8398 + ", uid=" + Binder.getCallingUid()
8399 + "without permission "
8400 + android.Manifest.permission.DUMP);
8401 return;
8402 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008403 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008404 }
Jack Yueb89b242016-06-22 13:27:47 -07008405
Brad Ebingerdac2f002018-04-03 15:17:52 -07008406 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008407 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8408 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8409 @NonNull String[] args) {
8410 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8411 this, in.getFileDescriptor(), out.getFileDescriptor(),
8412 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008413 }
8414
Jack Yueb89b242016-06-22 13:27:47 -07008415 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008416 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008417 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008418 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008419 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008420 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008421 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008422 */
8423 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008424 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008425 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008426 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8427 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8428 try {
8429 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008430 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008431 } catch (SecurityException se) {
8432 enforceModifyPermission();
8433 }
8434 } else {
8435 enforceModifyPermission();
8436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437
8438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 Phone phone = getPhone(subId);
8441 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008442 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8443 phone.carrierActionSetMeteredApnsEnabled(enabled);
8444 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008445 if (phone.isUsingNewDataStack()) {
Sarah Chinecc78c42022-03-31 21:16:48 -07008446 phone.getDataSettingsManager().setDataEnabled(
8447 reason, enabled, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08008448 } else {
8449 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8450 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008452 }
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008455 }
8456 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008457
8458 /**
8459 * Get Client request stats
8460 * @return List of Client Request Stats
8461 * @hide
8462 */
8463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008464 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8465 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008467 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008468 return null;
8469 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008470 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 if (phone != null) {
8475 return phone.getClientRequestStats();
8476 }
8477
8478 return null;
8479 } finally {
8480 Binder.restoreCallingIdentity(identity);
8481 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008482 }
8483
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008484 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008485 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008486 if (uid == Process.ROOT_UID && packageName == null) {
8487 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8488 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8489 // exception. ROOT_UID seems not to have a valid package name returned by
8490 // PackageManager, so just fake it here to avoid issues when running telephony shell
8491 // commands that plumb through the RIL as root, like so:
8492 // $ adb root
8493 // $ adb shell cmd phone ...
8494 packageName = "root";
8495 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008496 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008497 }
Jack Yueb4124c2017-02-16 15:32:43 -08008498
8499 /**
Grace Chen70990072017-03-24 17:21:30 -07008500 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008501 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008502 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008503 * @param state State of SIM (power down, power up, pass through)
8504 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8505 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8506 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008507 *
8508 **/
8509 @Override
Grace Chen70990072017-03-24 17:21:30 -07008510 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008511 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008512 Phone phone = PhoneFactory.getPhone(slotIndex);
8513
vagdeviaf9a5b92018-08-15 16:01:53 -07008514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516 final long identity = Binder.clearCallingIdentity();
8517 try {
8518 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008519 phone.setSimPowerState(state, null, workSource);
8520 }
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
8523 }
8524 }
8525
8526 /**
8527 * Set SIM card power state.
8528 *
8529 * @param slotIndex SIM slot id.
8530 * @param state State of SIM (power down, power up, pass through)
8531 * @param callback callback to trigger after success or failure
8532 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8533 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8534 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8535 *
8536 **/
8537 @Override
8538 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8539 IIntegerConsumer callback) {
8540 enforceModifyPermission();
8541 Phone phone = PhoneFactory.getPhone(slotIndex);
8542
8543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8544
8545 final long identity = Binder.clearCallingIdentity();
8546 try {
8547 if (phone != null) {
8548 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8549 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550 }
8551 } finally {
8552 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008553 }
8554 }
Shuo Qiandd210312017-04-12 22:11:33 +00008555
Tyler Gunn65d45c22017-06-05 11:22:26 -07008556 private boolean isUssdApiAllowed(int subId) {
8557 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008558 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008559 if (configManager == null) {
8560 return false;
8561 }
8562 PersistableBundle pb = configManager.getConfigForSubId(subId);
8563 if (pb == null) {
8564 return false;
8565 }
8566 return pb.getBoolean(
8567 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8568 }
8569
Shuo Qiandd210312017-04-12 22:11:33 +00008570 /**
8571 * Check if phone is in emergency callback mode
8572 * @return true if phone is in emergency callback mode
8573 * @param subId sub id
8574 */
goneil9c5f4872017-12-05 14:07:56 -08008575 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008576 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008577 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008578 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579
8580 final long identity = Binder.clearCallingIdentity();
8581 try {
8582 if (phone != null) {
8583 return phone.isInEcm();
8584 } else {
8585 return false;
8586 }
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008589 }
8590 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008591
8592 /**
8593 * Get the current signal strength information for the given subscription.
8594 * Because this information is not updated when the device is in a low power state
8595 * it should not be relied-upon to be current.
8596 * @param subId Subscription index
8597 * @return the most recent cached signal strength info from the modem
8598 */
8599 @Override
8600 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 final long identity = Binder.clearCallingIdentity();
8602 try {
8603 Phone p = getPhone(subId);
8604 if (p == null) {
8605 return null;
8606 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608 return p.getSignalStrength();
8609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008612 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008613
Pengquan Meng77b7f132018-08-22 14:49:57 -07008614 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008615 * Get the current modem radio state for the given slot.
8616 * @param slotIndex slot index.
8617 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008619 * @return the current radio power state from the modem
8620 */
8621 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008622 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008623 Phone phone = PhoneFactory.getPhone(slotIndex);
8624 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8626 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008627 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8628 }
8629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 return phone.getRadioPowerState();
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
8636 }
8637 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8638 }
8639
8640 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008641 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8642 *
8643 * <p>Requires one of the following permissions:
8644 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008645 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008646 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8647 * privileges.
8648 *
8649 * @param subId subscription id
8650 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8651 * {@code false}.
8652 */
8653 @Override
8654 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008655 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008656 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008657 try {
8658 mApp.enforceCallingOrSelfPermission(
8659 android.Manifest.permission.ACCESS_NETWORK_STATE,
8660 functionName);
8661 } catch (Exception e) {
8662 mApp.enforceCallingOrSelfPermission(
8663 permission.READ_BASIC_PHONE_STATE, functionName);
8664 }
Shuo Qian093013d2020-08-13 15:42:55 -07008665 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008666 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008667 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008668 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008669
Pengquan Menga1bb6272018-09-06 09:59:22 -07008670 boolean isEnabled = false;
8671 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008672 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008673 Phone phone = getPhone(subId);
8674 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008675 } finally {
8676 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008678 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008679 }
8680
8681
8682 /**
8683 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8684 *
8685 * <p> Requires permission:
8686 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8687 * privileges.
8688 *
8689 * @param subId subscription id
8690 * @param isEnabled {@code true} means enable, {@code false} means disable.
8691 */
8692 @Override
8693 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8695 mApp, subId, "setDataRoamingEnabled");
8696
Pengquan Menga1bb6272018-09-06 09:59:22 -07008697 final long identity = Binder.clearCallingIdentity();
8698 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008699 Phone phone = getPhone(subId);
8700 if (phone != null) {
8701 phone.setDataRoamingEnabled(isEnabled);
8702 }
8703 } finally {
8704 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008705 }
8706 }
8707
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008708 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008709 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008710 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008711 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008712 mApp, subId, "isManualNetworkSelectionAllowed");
8713
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008714 boolean isAllowed = true;
8715 final long identity = Binder.clearCallingIdentity();
8716 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008717 Phone phone = getPhone(subId);
8718 if (phone != null) {
8719 isAllowed = phone.isCspPlmnEnabled();
8720 }
8721 } finally {
8722 Binder.restoreCallingIdentity(identity);
8723 }
8724 return isAllowed;
8725 }
8726
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008727 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8728 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008729 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008730 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008731 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008732 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8733 if (phone == null) {
8734 return false;
8735 }
8736 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8737 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8738 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008739 }
8740
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008741 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008742 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008743 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008744 mApp.getSystemService(AppOpsManager.class)
8745 .checkPackage(Binder.getCallingUid(), callingPackage);
8746
Jordan Liu1e142fc2019-04-22 15:10:43 -07008747 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008748 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008749 try {
8750 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008751 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008752 } catch (SecurityException e) {
8753 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8754 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008755 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008756 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008757 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008758 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008759 }
sandeepjsb6c87872021-09-27 15:34:44 +00008760 // checking compatibility, if calling app's target SDK is T and beyond.
8761 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8762 Binder.getCallingUid())) {
8763 isIccIdAccessRestricted = true;
8764 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008765 final long identity = Binder.clearCallingIdentity();
8766 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008767 UiccController uiccController = UiccController.getInstance();
8768 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008769 if (hasReadPermission) {
8770 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008771 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008772
8773 // Remove private info if the caller doesn't have access
8774 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8775 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008776 //setting the value after compatibility check
8777 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008778 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8779 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008780 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008781 if (card == null) {
8782 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008783 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008784 continue;
8785 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008786 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8787 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008788 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008789 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008790 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008791 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8792 for (UiccPortInfo portInfo : portInfos) {
8793 UiccPort port = uiccController.getUiccPortForSlot(
8794 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8795 if (port == null) {
8796 // assume no access if port is null
8797 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8798 continue;
8799 }
8800 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8801 uiccPortInfos.add(portInfo);
8802 } else {
8803 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8804 }
8805 }
8806 filteredInfos.add(new UiccCardInfo(
8807 cardInfo.isEuicc(),
8808 cardInfo.getCardId(),
8809 null,
8810 cardInfo.getPhysicalSlotIndex(),
8811 cardInfo.isRemovable(),
8812 cardInfo.isMultipleEnabledProfilesSupported(),
8813 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008814 }
8815 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008816 } finally {
8817 Binder.restoreCallingIdentity(identity);
8818 }
8819 }
8820
sandeepjsb6c87872021-09-27 15:34:44 +00008821 /**
8822 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8823 * generally private and require carrier privileges to view.
8824 *
8825 * @hide
8826 */
8827 @NonNull
8828 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8829 List<UiccPortInfo> portinfo = new ArrayList<>();
8830 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8831 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8832 }
8833 return new UiccCardInfo(
8834 cardInfo.isEuicc(),
8835 cardInfo.getCardId(),
8836 null,
8837 cardInfo.getPhysicalSlotIndex(),
8838 cardInfo.isRemovable(),
8839 cardInfo.isMultipleEnabledProfilesSupported(),
8840 portinfo
8841 );
8842 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008843
sandeepjsb6c87872021-09-27 15:34:44 +00008844 /**
8845 * @hide
8846 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8847 * These values are generally private and require carrier privileges to view.
8848 */
8849 @NonNull
8850 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8851 return new UiccPortInfo(
8852 UiccPortInfo.ICCID_REDACTED,
8853 portInfo.getPortIndex(),
8854 portInfo.getLogicalSlotIndex(),
8855 portInfo.isActive()
8856 );
8857 }
8858 @Override
8859 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008860 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008861 mApp.getSystemService(AppOpsManager.class)
8862 .checkPackage(Binder.getCallingUid(), callingPackage);
8863
sandeepjsb6c87872021-09-27 15:34:44 +00008864 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008865
Aman Guptaf3c90b32022-03-17 04:54:16 +00008866 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8867 // we are reading iccId which is PII data.
8868 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008869
8870 // checking compatibility, if calling app's target SDK is T and beyond.
8871 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8872 Binder.getCallingUid())) {
8873 isLogicalSlotAccessRestricted = true;
8874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008875 final long identity = Binder.clearCallingIdentity();
8876 try {
8877 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008878 if (slots == null || slots.length == 0) {
8879 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008880 return null;
8881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008882 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8883 for (int i = 0; i < slots.length; i++) {
8884 UiccSlot slot = slots[i];
8885 if (slot == null) {
8886 continue;
8887 }
8888
Jordan Liu7be7e652019-05-06 18:55:02 +00008889 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008890 UiccCard card = slot.getUiccCard();
8891 if (card != null) {
8892 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008893 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008894 cardId = slot.getEid();
8895 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008896 // If cardId is null, use iccId of default port as cardId.
8897 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008899 }
8900
Jordan Liu857451f2019-05-09 16:35:35 -07008901 if (cardId != null) {
8902 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8903 // if cardId is an EID, it's all digits so this is fine
8904 cardId = IccUtils.stripTrailingFs(cardId);
8905 }
8906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008907 int cardState = 0;
8908 switch (slot.getCardState()) {
8909 case CARDSTATE_ABSENT:
8910 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8911 break;
8912 case CARDSTATE_PRESENT:
8913 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8914 break;
8915 case CARDSTATE_ERROR:
8916 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8917 break;
8918 case CARDSTATE_RESTRICTED:
8919 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8920 break;
8921 default:
8922 break;
8923
8924 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008925 List<UiccPortInfo> portInfos = new ArrayList<>();
8926 int[] portIndexes = slot.getPortList();
8927 for (int portIdx : portIndexes) {
8928 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008929 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008930 portInfos.add(new UiccPortInfo(iccId, portIdx,
8931 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008934 slot.isEuicc(),
8935 cardId,
8936 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008937 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008938 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008939 //setting the value after compatibility check
8940 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008941 }
8942 return infos;
8943 } finally {
8944 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008945 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008946 }
8947
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008948 /* Returns null if doesn't have read permission or carrier privilege access. */
8949 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8950 boolean hasReadPermission) {
8951 String iccId = slot.getIccId(portIndex);
8952 if (hasReadPermission) { // if has read permission
8953 return iccId;
8954 } else {
8955 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8956 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8957 // if no read permission, checking carrier privilege access
8958 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8959 return iccId;
8960 }
8961 }
8962 }
8963 // No read permission or carrier privilege access.
8964 return UiccPortInfo.ICCID_REDACTED;
8965 }
8966
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008967 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008968 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008969 public boolean switchSlots(int[] physicalSlots) {
8970 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008971
8972 final long identity = Binder.clearCallingIdentity();
8973 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008974 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8975 for (int i = 0; i < physicalSlots.length; i++) {
8976 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8977 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8978 physicalSlots[i], i));
8979 }
8980 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008984 }
Jack Yu4c988042018-02-27 15:30:01 -08008985
8986 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008987 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8988 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8989 enforceModifyPermission();
8990
8991 final long identity = Binder.clearCallingIdentity();
8992 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008993 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
8998
8999 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009000 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009001 final long identity = Binder.clearCallingIdentity();
9002 try {
9003 return UiccController.getInstance().getCardIdForDefaultEuicc();
9004 } finally {
9005 Binder.restoreCallingIdentity(identity);
9006 }
9007 }
9008
Pengquan Meng85728fb2018-03-12 16:31:21 -07009009 /**
goneil47ffb6e2018-04-06 15:40:58 -07009010 * A test API to reload the UICC profile.
9011 *
9012 * <p>Requires that the calling app has permission
9013 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9014 * @hide
9015 */
9016 @Override
9017 public void refreshUiccProfile(int subId) {
9018 enforceModifyPermission();
9019
9020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 Phone phone = getPhone(subId);
9023 if (phone == null) {
9024 return;
9025 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009026 UiccPort uiccPort = phone.getUiccPort();
9027 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009028 return;
9029 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009030 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009031 if (uiccProfile == null) {
9032 return;
9033 }
9034 uiccProfile.refresh();
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
9039
9040 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009041 * Returns false if the mobile data is disabled by default, otherwise return true.
9042 */
9043 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009044 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009045 }
9046
9047 /**
9048 * Returns true if the data roaming is enabled by default, i.e the system property
9049 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9050 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9051 */
9052 private boolean getDefaultDataRoamingEnabled(int subId) {
9053 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009054 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009055 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009056 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9057 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9058 return isDataRoamingEnabled;
9059 }
9060
9061 /**
9062 * Returns the default network type for the given {@code subId}, if the default network type is
9063 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9064 */
9065 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009066 List<Integer> list = TelephonyProperties.default_network();
9067 int phoneId = mSubscriptionController.getPhoneId(subId);
9068 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9069 return list.get(phoneId);
9070 }
9071 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009072 }
fionaxua13278b2018-03-21 00:08:13 -07009073
9074 @Override
9075 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009076 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009077 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009078
9079 final long identity = Binder.clearCallingIdentity();
9080 try {
9081 final Phone phone = getPhone(subId);
9082 if (phone == null) {
9083 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9084 return;
9085 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009086 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9087 if (cpt != null) {
9088 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9089 }
9090 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009091 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9092 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009093 if (carrierPrivilegeRules == null) {
9094 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9095 } else {
9096 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9097 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098 } finally {
9099 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009100 }
fionaxua13278b2018-03-21 00:08:13 -07009101 }
9102
9103 @Override
9104 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009105 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009106
9107 final long identity = Binder.clearCallingIdentity();
9108 try {
9109 final Phone phone = getPhone(subId);
9110 if (phone == null) {
9111 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9112 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9113 }
9114 return phone.getCarrierIdListVersion();
9115 } finally {
9116 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009117 }
fionaxua13278b2018-03-21 00:08:13 -07009118 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009119
9120 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009121 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9122 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009124 mApp, subId, callingPackage, callingFeatureId,
9125 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009126 return -1;
9127 }
9128
9129 final long identity = Binder.clearCallingIdentity();
9130 try {
9131 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009136
9137 @Override
9138 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009139 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009140 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009141 mApp, subId, "getCdmaRoamingMode");
9142
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
9148 }
9149 }
9150
9151 @Override
9152 public boolean setCdmaRoamingMode(int subId, int mode) {
9153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9154 mApp, subId, "setCdmaRoamingMode");
9155
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
9162 }
9163
9164 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009165 public int getCdmaSubscriptionMode(int subId) {
9166 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009167 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009168 mApp, subId, "getCdmaSubscriptionMode");
9169
9170 final long identity = Binder.clearCallingIdentity();
9171 try {
9172 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9173 } finally {
9174 Binder.restoreCallingIdentity(identity);
9175 }
9176 }
9177
9178 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009179 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9181 mApp, subId, "setCdmaSubscriptionMode");
9182
9183 final long identity = Binder.clearCallingIdentity();
9184 try {
9185 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
9189 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009190
sqianc5eccab2018-10-19 18:46:41 -07009191 @Override
sqian8c685422019-02-22 15:55:18 -08009192 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009193 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009195 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9196 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009197 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9198 }
9199 final long identity = Binder.clearCallingIdentity();
9200 try {
sqian854d44b2018-12-12 16:48:18 -08009201 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9202 for (Phone phone: PhoneFactory.getPhones()) {
9203 if (phone.getEmergencyNumberTracker() != null
9204 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9205 emergencyNumberListInternal.put(
9206 phone.getSubId(),
9207 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9208 }
sqian11b7a0e2018-12-05 18:48:28 -08009209 }
sqian854d44b2018-12-12 16:48:18 -08009210 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
sqianc5eccab2018-10-19 18:46:41 -07009214 }
9215
9216 @Override
sqian8c685422019-02-22 15:55:18 -08009217 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009218 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009219 if (!exactMatch) {
9220 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009221 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009222 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009223 }
9224 final long identity = Binder.clearCallingIdentity();
9225 try {
sqian854d44b2018-12-12 16:48:18 -08009226 for (Phone phone: PhoneFactory.getPhones()) {
9227 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009228 && phone.getEmergencyNumberTracker()
9229 .isEmergencyNumber(number, exactMatch)) {
9230 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009231 }
sqian11b7a0e2018-12-05 18:48:28 -08009232 }
9233 return false;
9234 } finally {
9235 Binder.restoreCallingIdentity(identity);
9236 }
9237 }
9238
sqianf4ca7ed2019-01-15 18:32:07 -08009239 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009240 * Start emergency callback mode for GsmCdmaPhone for testing.
9241 */
9242 @Override
9243 public void startEmergencyCallbackMode() {
9244 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9245 "startEmergencyCallbackMode");
9246 enforceModifyPermission();
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 for (Phone phone : PhoneFactory.getPhones()) {
9250 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9251 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9252 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9253 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9254 gsmCdmaPhone.obtainMessage(
9255 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9256 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9257 }
9258 }
9259 } finally {
9260 Binder.restoreCallingIdentity(identity);
9261 }
9262 }
9263
9264 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009265 * Update emergency number list for test mode.
9266 */
9267 @Override
9268 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9270 "updateEmergencyNumberListTestMode");
9271
9272 final long identity = Binder.clearCallingIdentity();
9273 try {
9274 for (Phone phone: PhoneFactory.getPhones()) {
9275 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9276 if (tracker != null) {
9277 tracker.executeEmergencyNumberTestModeCommand(action, num);
9278 }
9279 }
9280 } finally {
9281 Binder.restoreCallingIdentity(identity);
9282 }
9283 }
9284
9285 /**
9286 * Get the full emergency number list for test mode.
9287 */
9288 @Override
9289 public List<String> getEmergencyNumberListTestMode() {
9290 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9291 "getEmergencyNumberListTestMode");
9292
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 Set<String> emergencyNumbers = new HashSet<>();
9296 for (Phone phone: PhoneFactory.getPhones()) {
9297 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9298 if (tracker != null) {
9299 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9300 emergencyNumbers.add(num.getNumber());
9301 }
9302 }
9303 }
9304 return new ArrayList<>(emergencyNumbers);
9305 } finally {
9306 Binder.restoreCallingIdentity(identity);
9307 }
9308 }
9309
chen xud6b45bd2018-10-30 22:27:10 -07009310 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009311 public int getEmergencyNumberDbVersion(int subId) {
9312 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9313
9314 final long identity = Binder.clearCallingIdentity();
9315 try {
9316 final Phone phone = getPhone(subId);
9317 if (phone == null) {
9318 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9319 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9320 }
9321 return phone.getEmergencyNumberDbVersion();
9322 } finally {
9323 Binder.restoreCallingIdentity(identity);
9324 }
9325 }
9326
9327 @Override
9328 public void notifyOtaEmergencyNumberDbInstalled() {
9329 enforceModifyPermission();
9330
9331 final long identity = Binder.clearCallingIdentity();
9332 try {
9333 for (Phone phone: PhoneFactory.getPhones()) {
9334 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9335 if (tracker != null) {
9336 tracker.updateOtaEmergencyNumberDatabase();
9337 }
9338 }
9339 } finally {
9340 Binder.restoreCallingIdentity(identity);
9341 }
9342 }
9343
9344 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009345 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009346 enforceActiveEmergencySessionPermission();
9347
9348 final long identity = Binder.clearCallingIdentity();
9349 try {
9350 for (Phone phone: PhoneFactory.getPhones()) {
9351 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9352 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009353 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9354 }
9355 }
9356 } finally {
9357 Binder.restoreCallingIdentity(identity);
9358 }
9359 }
9360
9361 @Override
9362 public void resetOtaEmergencyNumberDbFilePath() {
9363 enforceActiveEmergencySessionPermission();
9364
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
9367 for (Phone phone: PhoneFactory.getPhones()) {
9368 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9369 if (tracker != null) {
9370 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009371 }
9372 }
9373 } finally {
9374 Binder.restoreCallingIdentity(identity);
9375 }
9376 }
9377
9378 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009379 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9380 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9381 Phone phone = getPhone(subId);
9382 if (phone == null) {
9383 return null;
9384 }
9385 final long identity = Binder.clearCallingIdentity();
9386 try {
9387 UiccProfile profile = UiccController.getInstance()
9388 .getUiccProfileForPhone(phone.getPhoneId());
9389 if (profile != null) {
9390 return profile.getCertsFromCarrierPrivilegeAccessRules();
9391 }
9392 } finally {
9393 Binder.restoreCallingIdentity(identity);
9394 }
9395 return null;
9396 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009397
9398 /**
9399 * Enable or disable a modem stack.
9400 */
9401 @Override
9402 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9403 enforceModifyPermission();
9404
9405 final long identity = Binder.clearCallingIdentity();
9406 try {
9407 Phone phone = PhoneFactory.getPhone(slotIndex);
9408 if (phone == null) {
9409 return false;
9410 } else {
9411 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9412 }
9413 } finally {
9414 Binder.restoreCallingIdentity(identity);
9415 }
9416 }
Michelecea4cf22018-12-21 15:00:11 -08009417
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009418 /**
9419 * Whether a modem stack is enabled or not.
9420 */
9421 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009422 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9423 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009424 Phone phone = PhoneFactory.getPhone(slotIndex);
9425 if (phone == null) return false;
9426
9427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009428 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9429 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009430 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9431 }
9432
9433 final long identity = Binder.clearCallingIdentity();
9434 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009435 try {
9436 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9437 } catch (NoSuchElementException ex) {
9438 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9439 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009440 } finally {
9441 Binder.restoreCallingIdentity(identity);
9442 }
9443 }
9444
Michelecea4cf22018-12-21 15:00:11 -08009445 @Override
Michele0ea7d782019-03-19 14:58:42 -07009446 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009447 enforceModifyPermission();
9448
9449 final long identity = Binder.clearCallingIdentity();
9450 try {
9451 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009452 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009453 .commit();
9454 } finally {
9455 Binder.restoreCallingIdentity(identity);
9456 }
9457 }
9458
9459 @Override
Michele0ea7d782019-03-19 14:58:42 -07009460 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009461 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009463 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9464 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009465 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009466 }
Michelecea4cf22018-12-21 15:00:11 -08009467
9468 final long identity = Binder.clearCallingIdentity();
9469 try {
Michele0ea7d782019-03-19 14:58:42 -07009470 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009471 } finally {
9472 Binder.restoreCallingIdentity(identity);
9473 }
9474 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009475
Michele0ea7d782019-03-19 14:58:42 -07009476 @TelephonyManager.IsMultiSimSupportedResult
9477 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009478 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9479 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9480 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009481 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9482 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009483 }
9484 // Check if the hardware supports multisim functionality. If usage of multisim is not
9485 // supported by the modem, indicate that it is restricted.
9486 PhoneCapability staticCapability =
9487 mPhoneConfigurationManager.getStaticPhoneCapability();
9488 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009489 loge("isMultiSimSupportedInternal: no static configuration available");
9490 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009491 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009492 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009493 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9494 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009495 }
9496 // Check if support of multiple SIMs is restricted by carrier
9497 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009498 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009499 }
9500
Michele0ea7d782019-03-19 14:58:42 -07009501 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009502 }
9503
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009504 /**
9505 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009506 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9507 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9508 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009509 * @param numOfSims number of active sims we want to switch to
9510 */
9511 @Override
9512 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009513 if (numOfSims == 1) {
9514 enforceModifyPermission();
9515 } else {
9516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9517 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9518 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009519 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009520
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009521 try {
Michele30b57b22019-03-01 12:01:14 -08009522 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009523 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009524 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9525 return;
9526 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009527 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9528 } finally {
9529 Binder.restoreCallingIdentity(identity);
9530 }
9531 }
9532
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009533 @Override
9534 public boolean isApplicationOnUicc(int subId, int appType) {
9535 enforceReadPrivilegedPermission("isApplicationOnUicc");
9536 Phone phone = getPhone(subId);
9537 if (phone == null) {
9538 return false;
9539 }
9540 final long identity = Binder.clearCallingIdentity();
9541 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009542 UiccPort uiccPort = phone.getUiccPort();
9543 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009544 return false;
9545 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009546 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009547 if (uiccProfile == null) {
9548 return false;
9549 }
9550 if (TelephonyManager.APPTYPE_SIM <= appType
9551 && appType <= TelephonyManager.APPTYPE_ISIM) {
9552 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9553 }
9554 return false;
9555 } finally {
9556 Binder.restoreCallingIdentity(identity);
9557 }
9558 }
9559
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009560 /**
chen xub4baa772019-04-03 10:23:41 -07009561 * Get whether making changes to modem configurations will trigger reboot.
9562 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009563 */
9564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009565 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9566 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009568 mApp, subId, callingPackage, callingFeatureId,
9569 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009570 return false;
9571 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009572 final long identity = Binder.clearCallingIdentity();
9573 try {
9574 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
9579
Nathan Harold29f5f052019-02-15 13:41:57 -08009580 private void updateModemStateMetrics() {
9581 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9582 // TODO: check the state for each modem if the api is ready.
9583 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9584 }
9585
Pengquan Meng3889a572019-01-23 11:16:29 -08009586 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009587 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009588 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009589 // Verify that the callingPackage belongs to the calling UID
9590 mApp.getSystemService(AppOpsManager.class)
9591 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009592 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009593 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009594 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009595 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9596 if (slotInfos != null) {
9597 for (int i = 0; i < slotInfos.length; i++) {
9598 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9599 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9600 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9601 portInfo.getLogicalSlotIndex()));
9602 }
9603 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009604 }
9605 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009606 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
9610 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009611
9612 /**
9613 * Get the IRadio HAL Version
9614 */
9615 @Override
9616 public int getRadioHalVersion() {
9617 Phone phone = getDefaultPhone();
9618 if (phone == null) return -1;
9619 HalVersion hv = phone.getHalVersion();
9620 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9621 return hv.major * 100 + hv.minor;
9622 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009623
9624 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009625 * Get the current calling package name.
9626 * @return the current calling package name
9627 */
9628 @Override
9629 public String getCurrentPackageName() {
9630 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9631 }
9632
9633 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009634 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9635 * corresponding network requests on a subId.
9636 *
9637 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009638 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009639 * 2) APN is un-metered for this subscription, or
9640 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009641 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009642 *
9643 * @return whether data is allowed for a apn type.
9644 *
9645 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009646 */
9647 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009648 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009649 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9650 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009651
9652 // Now that all security checks passes, perform the operation as ourselves.
9653 final long identity = Binder.clearCallingIdentity();
9654 try {
9655 Phone phone = getPhone(subId);
9656 if (phone == null) return false;
9657
Jack Yu27422a52022-03-21 10:38:05 -07009658 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009659 boolean isDataEnabled;
9660 if (phone.isUsingNewDataStack()) {
Jack Yu27422a52022-03-21 10:38:05 -07009661 isMetered = phone.getDataNetworkController().getDataConfigManager()
9662 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9663 phone.getServiceState().getDataRoaming());
Jack Yu99e87332021-12-17 23:14:15 -08009664 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9665 } else {
Jack Yu27422a52022-03-21 10:38:05 -07009666 isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009667 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9668 }
9669 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
9674
9675 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009676 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009677 enforceReadPrivilegedPermission("isApnMetered");
9678
9679 // Now that all security checks passes, perform the operation as ourselves.
9680 final long identity = Binder.clearCallingIdentity();
9681 try {
9682 Phone phone = getPhone(subId);
9683 if (phone == null) return true; // By default return true.
Jack Yu27422a52022-03-21 10:38:05 -07009684 if (phone.isUsingNewDataStack()) {
9685 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9686 DataUtils.apnTypeToNetworkCapability(apnType),
9687 phone.getServiceState().getDataRoaming());
9688 }
Malcolm Chene5ad5792019-04-18 13:51:02 -07009689
Jack Yu41407ee2019-05-13 16:54:09 -07009690 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009691 } finally {
9692 Binder.restoreCallingIdentity(identity);
9693 }
9694 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009695
9696 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009697 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9698 int subscriptionId, IBooleanConsumer resultCallback) {
9699 enforceModifyPermission();
9700 long token = Binder.clearCallingIdentity();
9701 try {
9702 Phone phone = getPhone(subscriptionId);
9703 if (phone == null) {
9704 try {
9705 if (resultCallback != null) {
9706 resultCallback.accept(false);
9707 }
9708 } catch (RemoteException e) {
9709 // ignore
9710 }
9711 return;
9712 }
9713 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9714 Pair.create(specifiers, (x) -> {
9715 try {
9716 if (resultCallback != null) {
9717 resultCallback.accept(x);
9718 }
9719 } catch (RemoteException e) {
9720 // ignore
9721 }
9722 });
9723 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9724 } finally {
9725 Binder.restoreCallingIdentity(token);
9726 }
9727 }
9728
9729 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009730 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9731 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009732 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009733 mApp, subId, "getSystemSelectionChannels");
9734 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9735 final long identity = Binder.clearCallingIdentity();
9736 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009737 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9738 if (result instanceof IllegalStateException) {
9739 throw (IllegalStateException) result;
9740 }
9741 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009742 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9743 return specifiers;
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748
9749 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009750 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009751 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009752 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009753 }
9754
9755 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009756 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9757 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009758 if (callingPackage == null) {
9759 callingPackage = getCurrentPackageName();
9760 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009761 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9762 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009763 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9764 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009765 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9766 }
9767 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9768 Intent intent = new Intent();
9769 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9770 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9771 // Bring up choose default SMS subscription dialog right now
9772 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9773 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9774 mApp.startActivity(intent);
9775 }
chen xud5ca2d52019-05-28 15:20:57 -07009776
9777 @Override
9778 public String getMmsUAProfUrl(int subId) {
9779 //TODO investigate if this API should require proper permission check in R b/133791609
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009782 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9783 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9784 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9785 return carrierUAProfUrl;
9786 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009787 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9788 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009789 } finally {
9790 Binder.restoreCallingIdentity(identity);
9791 }
9792 }
9793
9794 @Override
9795 public String getMmsUserAgent(int subId) {
9796 //TODO investigate if this API should require proper permission check in R b/133791609
9797 final long identity = Binder.clearCallingIdentity();
9798 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009799 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9800 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9801 if (!TextUtils.isEmpty(carrierUserAgent)) {
9802 return carrierUserAgent;
9803 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009804 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9805 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009806 } finally {
9807 Binder.restoreCallingIdentity(identity);
9808 }
9809 }
Jack Yub07d4972019-05-28 16:12:25 -07009810
9811 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009812 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9813 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009814
Jack Yub07d4972019-05-28 16:12:25 -07009815 final long identity = Binder.clearCallingIdentity();
9816 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009817 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009818 if (phone == null) return false;
9819
Hall Liua62f5da2020-09-25 10:42:19 -07009820 switch (policy) {
9821 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009822 if (phone.isUsingNewDataStack()) {
9823 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9824 } else {
9825 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9826 }
Hall Liua62f5da2020-09-25 10:42:19 -07009827 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009828 if (phone.isUsingNewDataStack()) {
9829 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9830 } else {
9831 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9832 }
Hall Liua62f5da2020-09-25 10:42:19 -07009833 default:
9834 throw new IllegalArgumentException(policy + " is not a valid policy");
9835 }
Jack Yub07d4972019-05-28 16:12:25 -07009836 } finally {
9837 Binder.restoreCallingIdentity(identity);
9838 }
9839 }
9840
9841 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009842 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009843 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009844 enforceModifyPermission();
9845
changbettyd5c246e2019-12-24 15:40:37 +08009846 final long identity = Binder.clearCallingIdentity();
9847 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009848 Phone phone = getPhone(subscriptionId);
9849 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009850
Hall Liua62f5da2020-09-25 10:42:19 -07009851 switch (policy) {
9852 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009853 if (phone.isUsingNewDataStack()) {
9854 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9855 } else {
9856 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9857 }
Hall Liua62f5da2020-09-25 10:42:19 -07009858 break;
9859 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009860 if (phone.isUsingNewDataStack()) {
9861 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9862 } else {
9863 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9864 }
Hall Liua62f5da2020-09-25 10:42:19 -07009865 break;
9866 default:
9867 throw new IllegalArgumentException(policy + " is not a valid policy");
9868 }
changbettyd5c246e2019-12-24 15:40:37 +08009869 } finally {
9870 Binder.restoreCallingIdentity(identity);
9871 }
9872 }
9873
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009874 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009875 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009876 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9877 * otherwise.
9878 */
9879 @Override
9880 public void setCepEnabled(boolean isCepEnabled) {
9881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9882
9883 final long identity = Binder.clearCallingIdentity();
9884 try {
9885 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9886 for (Phone phone : PhoneFactory.getPhones()) {
9887 Phone defaultPhone = phone.getImsPhone();
9888 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9889 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9890 ImsPhoneCallTracker imsPhoneCallTracker =
9891 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9892 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9893 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9894 + imsPhone.getMsisdn());
9895 }
9896 }
9897 } finally {
9898 Binder.restoreCallingIdentity(identity);
9899 }
9900 }
allenwtsu46dcc572020-01-08 18:24:03 +08009901
9902 /**
9903 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9904 *
9905 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9906 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9907 * before being read.
9908 */
9909 @Override
9910 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9911 isCompressed) {
9912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9913 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9915 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9916 }
9917 if (!isImsAvailableOnDevice()) {
9918 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9919 "IMS not available on device.");
9920 }
9921
9922 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009923 try {
Hui Wang761a6682020-10-31 05:12:53 +00009924 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9925 } finally {
9926 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009927 }
9928 }
zoey chene02881a2019-12-30 16:11:23 +08009929
9930 @Override
9931 public boolean isIccLockEnabled(int subId) {
9932 enforceReadPrivilegedPermission("isIccLockEnabled");
9933
9934 // Now that all security checks passes, perform the operation as ourselves.
9935 final long identity = Binder.clearCallingIdentity();
9936 try {
9937 Phone phone = getPhone(subId);
9938 if (phone != null && phone.getIccCard() != null) {
9939 return phone.getIccCard().getIccLockEnabled();
9940 } else {
9941 return false;
9942 }
9943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 }
9947
9948 /**
9949 * Set the ICC pin lock enabled or disabled.
9950 *
9951 * @return an integer representing the status of IccLock enabled or disabled in the following
9952 * three cases:
9953 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9954 * successfully.
9955 * - Positive number and zero for remaining password attempts.
9956 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9957 *
9958 */
9959 @Override
9960 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9961 enforceModifyPermission();
9962
9963 Phone phone = getPhone(subId);
9964 if (phone == null) {
9965 return 0;
9966 }
9967 // Now that all security checks passes, perform the operation as ourselves.
9968 final long identity = Binder.clearCallingIdentity();
9969 try {
9970 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9971 new Pair<Boolean, String>(enabled, password), phone, null);
9972 return attemptsRemaining;
9973
9974 } catch (Exception e) {
9975 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 return 0;
9980 }
9981
9982 /**
9983 * Change the ICC password used in ICC pin lock.
9984 *
9985 * @return an integer representing the status of IccLock changed in the following three cases:
9986 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9987 * - Positive number and zero for remaining password attempts.
9988 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9989 *
9990 */
9991 @Override
9992 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9993 enforceModifyPermission();
9994
9995 Phone phone = getPhone(subId);
9996 if (phone == null) {
9997 return 0;
9998 }
9999 // Now that all security checks passes, perform the operation as ourselves.
10000 final long identity = Binder.clearCallingIdentity();
10001 try {
10002 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10003 new Pair<String, String>(oldPassword, newPassword), phone, null);
10004 return attemptsRemaining;
10005
10006 } catch (Exception e) {
10007 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10008 } finally {
10009 Binder.restoreCallingIdentity(identity);
10010 }
10011 return 0;
10012 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010013
10014 /**
10015 * Request for receiving user activity notification
10016 */
10017 @Override
10018 public void requestUserActivityNotification() {
10019 if (!mNotifyUserActivity.get()
10020 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10021 mNotifyUserActivity.set(true);
10022 }
10023 }
10024
10025 /**
10026 * Called when userActivity is signalled in the power manager.
10027 * This is safe to call from any thread, with any window manager locks held or not.
10028 */
10029 @Override
10030 public void userActivity() {
10031 // ***************************************
10032 // * Inherited from PhoneWindowManager *
10033 // ***************************************
10034 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10035 // WITH ITS LOCKS HELD.
10036 //
10037 // This code must be VERY careful about the locks
10038 // it acquires.
10039 // In fact, the current code acquires way too many,
10040 // and probably has lurking deadlocks.
10041
10042 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10043 throw new SecurityException("Only the OS may call notifyUserActivity()");
10044 }
10045
10046 if (mNotifyUserActivity.getAndSet(false)) {
10047 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10048 USER_ACTIVITY_NOTIFICATION_DELAY);
10049 }
10050 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010051
10052 @Override
10053 public boolean canConnectTo5GInDsdsMode() {
10054 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10055 }
Jack Yud10cdd42020-09-28 20:28:01 -070010056
10057 @Override
10058 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10059 String callingFeatureId) {
10060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10061 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10062 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10063 }
10064
10065 Phone phone = getPhone(subId);
10066 if (phone == null) {
10067 throw new RuntimeException("phone is not available");
10068 }
10069 // Now that all security checks passes, perform the operation as ourselves.
10070 final long identity = Binder.clearCallingIdentity();
10071 try {
10072 return phone.getEquivalentHomePlmns();
10073 } finally {
10074 Binder.restoreCallingIdentity(identity);
10075 }
10076 }
Daniel Bright59e67312020-11-13 11:49:37 -080010077
10078 @Override
10079 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010080 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10081 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010082 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010083 if (radioInterfaceCapabilities == null) {
10084 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010085 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010086 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010087 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010088
Hui Wang641e81c2020-10-12 12:14:23 -070010089 @Override
10090 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10091 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010092 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10093 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10094 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10095 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10096 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010097 if (DBG) {
10098 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10099 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10100 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10101 }
10102
10103 if (!SubscriptionManager.isValidSubscriptionId(subId)
10104 || appType < TelephonyManager.APPTYPE_UNKNOWN
10105 || appType > TelephonyManager.APPTYPE_ISIM
10106 || nafUrl == null || securityProtocol == null || callback == null) {
10107 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10108 if (callback != null) {
10109 try {
10110 callback.onAuthenticationFailure(
10111 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10112 } catch (RemoteException exception) {
10113 log("Fail to notify onAuthenticationFailure due to " + exception);
10114 }
10115 return;
10116 }
10117 }
10118
10119 final long token = Binder.clearCallingIdentity();
10120 try {
10121 getGbaManager(subId).bootstrapAuthenticationRequest(
10122 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10123 forceBootStrapping, callback));
10124 } finally {
10125 Binder.restoreCallingIdentity(token);
10126 }
10127 }
10128
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010129 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010130 * Attempts to set the radio power state for all phones for thermal reason.
10131 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010132 * requested radio power state will actually be set. See {@link
10133 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10134 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010135 * @param enable {@code true} if trying to turn radio on.
10136 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10137 * false}.
10138 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010139 private boolean setRadioPowerForThermal(boolean enable) {
10140 boolean isPhoneAvailable = false;
10141 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10142 Phone phone = PhoneFactory.getPhone(i);
10143 if (phone != null) {
10144 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10145 isPhoneAvailable = true;
10146 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010147 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010148
10149 // return true if successfully informed the phone object about the thermal radio power
10150 // request.
10151 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010152 }
10153
10154 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010155 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010156 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10157 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10158 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10159 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10160 throw new IllegalArgumentException("modem does not support data throttling");
10161 }
10162
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010163 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10164 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010165 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010166 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10167 }
10168
Sarah Chinecc78c42022-03-31 21:16:48 -070010169 setDataEnabledForReason(
10170 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010171
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010172 if (isDataThrottlingSupported) {
10173 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010174 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010175 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10176 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10177 } else if (thermalMitigationResult
10178 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010179 log("Modem likely does not support data throttling on secondary carrier. Data " +
10180 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10181 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010182 }
10183 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010184 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010185
10186 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010187 }
10188
Jack Nudelman644b91a2021-03-12 14:09:48 -080010189 private static List<String> getThermalMitigationAllowlist(Context context) {
10190 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10191 for (String pckg : context.getResources()
10192 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10193 sThermalMitigationAllowlistedPackages.add(pckg);
10194 }
10195 }
10196
10197 return sThermalMitigationAllowlistedPackages;
10198 }
10199
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010200 private boolean isAnyPhoneInEmergencyState() {
10201 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10202 if (tm.isInEmergencyCall()) {
10203 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10204 return true;
10205 }
10206 for (Phone phone : PhoneFactory.getPhones()) {
10207 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10208 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10209 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10210 + phone.isInEcm());
10211 return true;
10212 }
10213 }
10214
10215 return false;
10216 }
10217
Jack Nudelman644b91a2021-03-12 14:09:48 -080010218 /**
10219 * Used by shell commands to add an authorized package name for thermal mitigation.
10220 * @param packageName name of package to be allowlisted
10221 * @param context
10222 */
10223 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10224 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10225 sThermalMitigationAllowlistedPackages.add(packageName);
10226 }
10227
10228 /**
10229 * Used by shell commands to remove an authorized package name for thermal mitigation.
10230 * @param packageName name of package to remove from allowlist
10231 * @param context
10232 */
10233 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10234 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10235 sThermalMitigationAllowlistedPackages.remove(packageName);
10236 }
10237
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010238 /**
10239 * Thermal mitigation request to control functionalities at modem.
10240 *
10241 * @param subId the id of the subscription.
10242 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010243 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010244 *
10245 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10246 */
10247 @Override
10248 @ThermalMitigationResult
10249 public int sendThermalMitigationRequest(
10250 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010251 ThermalMitigationRequest thermalMitigationRequest,
10252 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010253 enforceModifyPermission();
10254
Jack Nudelman644b91a2021-03-12 14:09:48 -080010255 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10256 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10257 .contains(callingPackage)) {
10258 throw new SecurityException("Calling package must be configured in the device config. "
10259 + "calling package: " + callingPackage);
10260 }
10261
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010262 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10263 final long identity = Binder.clearCallingIdentity();
10264
10265 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10266 try {
10267 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10268 switch (thermalMitigationAction) {
10269 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10270 thermalMitigationResult =
10271 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010272 thermalMitigationRequest.getDataThrottlingRequest(),
10273 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010274 break;
10275 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10276 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10277 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10278 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10279 }
10280
10281 // Ensure that radio is on. If not able to power on due to phone being
10282 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010283 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010284 thermalMitigationResult =
10285 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10286 break;
10287 }
10288
10289 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010290 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010291 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10292 break;
10293 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10294 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10295 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10296 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10297 }
10298
10299 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10300 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010301 Phone phone = getPhone(subId);
10302 if (phone == null) {
10303 thermalMitigationResult =
10304 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10305 break;
10306 }
10307
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010308 TelephonyConnectionService service =
10309 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010310 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010311 Log.e(LOG_TAG, "An emergency call is pending");
10312 thermalMitigationResult =
10313 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10314 break;
10315 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010316 thermalMitigationResult =
10317 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10318 break;
10319 }
10320 } else {
10321 thermalMitigationResult =
10322 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10323 break;
10324 }
10325
10326 // Turn radio off. If not able to power off due to phone being unavailable,
10327 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010328 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010329 thermalMitigationResult =
10330 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10331 break;
10332 }
10333 thermalMitigationResult =
10334 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10335 break;
10336 default:
10337 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10338 + "not exist. Requested action: " + thermalMitigationAction);
10339 }
10340 } catch (IllegalArgumentException e) {
10341 throw e;
10342 } catch (Exception e) {
10343 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10344 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10345 } finally {
10346 Binder.restoreCallingIdentity(identity);
10347 }
10348
10349 if (DBG) {
10350 log("thermalMitigationRequest returning with thermalMitigationResult: "
10351 + thermalMitigationResult);
10352 }
10353
10354 return thermalMitigationResult;
10355 }
Hui Wang641e81c2020-10-12 12:14:23 -070010356
10357 /**
10358 * Set the GbaService Package Name that Telephony will bind to.
10359 *
10360 * @param subId The sim that the GbaService is associated with.
10361 * @param packageName The name of the package to be replaced with.
10362 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10363 */
10364 @Override
10365 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10366 enforceModifyPermission();
10367
10368 final long identity = Binder.clearCallingIdentity();
10369 try {
10370 return getGbaManager(subId).overrideServicePackage(packageName);
10371 } finally {
10372 Binder.restoreCallingIdentity(identity);
10373 }
10374 }
10375
10376 /**
10377 * Return the package name of the currently bound GbaService.
10378 *
10379 * @param subId The sim that the GbaService is associated with.
10380 * @return the package name of the GbaService configuration, null if GBA is not supported.
10381 */
10382 @Override
10383 public String getBoundGbaService(int subId) {
10384 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10385
10386 final long identity = Binder.clearCallingIdentity();
10387 try {
10388 return getGbaManager(subId).getServicePackage();
10389 } finally {
10390 Binder.restoreCallingIdentity(identity);
10391 }
10392 }
10393
10394 /**
10395 * Set the release time for telephony to unbind GbaService.
10396 *
10397 * @param subId The sim that the GbaService is associated with.
10398 * @param interval The release time to unbind GbaService by millisecond.
10399 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10400 */
10401 @Override
10402 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10403 enforceModifyPermission();
10404
10405 final long identity = Binder.clearCallingIdentity();
10406 try {
10407 return getGbaManager(subId).overrideReleaseTime(interval);
10408 } finally {
10409 Binder.restoreCallingIdentity(identity);
10410 }
10411 }
10412
10413 /**
10414 * Return the release time for telephony to unbind GbaService.
10415 *
10416 * @param subId The sim that the GbaService is associated with.
10417 * @return The release time to unbind GbaService by millisecond.
10418 */
10419 @Override
10420 public int getGbaReleaseTime(int subId) {
10421 enforceReadPrivilegedPermission("getGbaReleaseTime");
10422
10423 final long identity = Binder.clearCallingIdentity();
10424 try {
10425 return getGbaManager(subId).getReleaseTime();
10426 } finally {
10427 Binder.restoreCallingIdentity(identity);
10428 }
10429 }
10430
10431 private GbaManager getGbaManager(int subId) {
10432 GbaManager instance = GbaManager.getInstance(subId);
10433 if (instance == null) {
10434 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10435 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10436 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10437 }
10438 return instance;
10439 }
Hui Wang761a6682020-10-31 05:12:53 +000010440
10441 /**
10442 * indicate whether the device and the carrier can support
10443 * RCS VoLTE single registration.
10444 */
10445 @Override
10446 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010447 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10448 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10449 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10450 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010451
10452 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10453 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10454 }
10455
10456 final long identity = Binder.clearCallingIdentity();
10457 try {
10458 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10459 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010460 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10461 if (isCapable != null) {
10462 return isCapable;
10463 }
Hui Wang761a6682020-10-31 05:12:53 +000010464 }
Hui Wang67af90e2021-06-04 16:57:15 -070010465 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10466 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010467 } finally {
10468 Binder.restoreCallingIdentity(identity);
10469 }
10470 }
10471
10472 /**
10473 * Register RCS provisioning callback.
10474 */
10475 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010476 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010477 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010478 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010479 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010480 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10481 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010482
10483 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10484 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10485 }
10486 if (!isImsAvailableOnDevice()) {
10487 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10488 "IMS not available on device.");
10489 }
10490
10491 final long identity = Binder.clearCallingIdentity();
10492 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010493 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010494 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010495 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10496 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010497 }
Hui Wang761a6682020-10-31 05:12:53 +000010498 } finally {
10499 Binder.restoreCallingIdentity(identity);
10500 }
10501 }
10502
10503 /**
10504 * Unregister RCS provisioning callback.
10505 */
10506 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010507 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010508 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010509 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010510 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010511 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10512 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010513
10514 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10515 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10516 }
10517 if (!isImsAvailableOnDevice()) {
10518 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10519 "IMS not available on device.");
10520 }
10521
10522 final long identity = Binder.clearCallingIdentity();
10523 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010524 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010525 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010526 } finally {
10527 Binder.restoreCallingIdentity(identity);
10528 }
10529 }
10530
10531 /**
10532 * trigger RCS reconfiguration.
10533 */
10534 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010535 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10536 "triggerRcsReconfiguration",
10537 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010538
10539 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10540 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10541 }
10542 if (!isImsAvailableOnDevice()) {
10543 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10544 "IMS not available on device.");
10545 }
10546
10547 final long identity = Binder.clearCallingIdentity();
10548 try {
10549 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10550 } finally {
10551 Binder.restoreCallingIdentity(identity);
10552 }
10553 }
10554
10555 /**
10556 * Provide the client configuration parameters of the RCS application.
10557 */
10558 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010559 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10560 "setRcsClientConfiguration",
10561 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010562
10563 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10564 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10565 }
10566 if (!isImsAvailableOnDevice()) {
10567 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10568 "IMS not available on device.");
10569 }
10570
10571 final long identity = Binder.clearCallingIdentity();
10572
10573 try {
10574 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10575 if (configBinder == null) {
10576 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010577 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10578 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010579 } else {
10580 configBinder.setRcsClientConfiguration(rcc);
10581 }
joonhunshin3e154242021-09-17 06:33:39 +000010582
10583 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10584 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010585 } catch (RemoteException e) {
10586 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010587 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10588 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010589 } finally {
10590 Binder.restoreCallingIdentity(identity);
10591 }
10592 }
10593
10594 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010595 * Enables or disables the test mode for RCS VoLTE single registration.
10596 */
10597 @Override
10598 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10599 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10600 "setRcsSingleRegistrationTestModeEnabled");
10601
10602 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10603 }
10604
10605 /**
10606 * Gets the test mode for RCS VoLTE single registration.
10607 */
10608 @Override
10609 public boolean getRcsSingleRegistrationTestModeEnabled() {
10610 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10611 "getRcsSingleRegistrationTestModeEnabled");
10612
10613 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10614 }
10615
10616 /**
Hui Wang761a6682020-10-31 05:12:53 +000010617 * Overrides the config of RCS VoLTE single registration enabled for the device.
10618 */
10619 @Override
10620 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10621 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10622 "setDeviceSingleRegistrationEnabledOverride");
10623 enforceModifyPermission();
10624
10625 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10626 : Boolean.parseBoolean(enabledStr);
10627 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010628 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010629 }
10630
10631 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010632 * Sends a device to device communication message. Only usable via shell.
10633 * @param message message to send.
10634 * @param value message value.
10635 */
10636 @Override
10637 public void sendDeviceToDeviceMessage(int message, int value) {
10638 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010639 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010640 enforceModifyPermission();
10641
10642 final long identity = Binder.clearCallingIdentity();
10643 try {
10644 TelephonyConnectionService service =
10645 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10646 if (service == null) {
10647 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10648 return;
10649 }
10650 service.sendTestDeviceToDeviceMessage(message, value);
10651 } finally {
10652 Binder.restoreCallingIdentity(identity);
10653 }
10654 }
10655
Tyler Gunnbabbda02021-02-10 11:05:02 -080010656 /**
10657 * Sets the specified device to device transport active.
10658 * @param transport The transport to set active.
10659 */
10660 @Override
10661 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10663 "setActiveDeviceToDeviceTransport");
10664 enforceModifyPermission();
10665
10666 final long identity = Binder.clearCallingIdentity();
10667 try {
10668 TelephonyConnectionService service =
10669 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10670 if (service == null) {
10671 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10672 return;
10673 }
10674 service.setActiveDeviceToDeviceTransport(transport);
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
Tyler Gunn92479152021-01-20 16:30:10 -080010679
Tyler Gunnd4339262021-05-03 14:46:49 -070010680 @Override
10681 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10682 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10683 "setDeviceToDeviceForceEnabled");
10684
10685 final long identity = Binder.clearCallingIdentity();
10686 try {
10687 Arrays.stream(PhoneFactory.getPhones()).forEach(
10688 p -> {
10689 Phone thePhone = p.getImsPhone();
10690 if (thePhone != null && thePhone instanceof ImsPhone) {
10691 ImsPhone imsPhone = (ImsPhone) thePhone;
10692 CallTracker tracker = imsPhone.getCallTracker();
10693 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10694 ImsPhoneCallTracker imsPhoneCallTracker =
10695 (ImsPhoneCallTracker) tracker;
10696 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10697 }
10698 }
10699 }
10700 );
10701 } finally {
10702 Binder.restoreCallingIdentity(identity);
10703 }
10704 }
10705
Tyler Gunn92479152021-01-20 16:30:10 -080010706 /**
Hui Wang761a6682020-10-31 05:12:53 +000010707 * Gets the config of RCS VoLTE single registration enabled for the device.
10708 */
10709 @Override
10710 public boolean getDeviceSingleRegistrationEnabled() {
10711 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10712 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10713 }
10714
10715 /**
10716 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10717 */
10718 @Override
10719 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10720 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10721 "setCarrierSingleRegistrationEnabledOverride");
10722 enforceModifyPermission();
10723
10724 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10725 : Boolean.parseBoolean(enabledStr);
10726 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10727 subId, enabled);
10728 }
10729
10730 /**
10731 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10732 */
10733 @Override
10734 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10735 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10736 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10737 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010738
10739 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010740 * Overrides the ims feature validation result
10741 */
10742 @Override
10743 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10745 "setImsFeatureValidationOverride");
10746
10747 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10748 : Boolean.parseBoolean(enabledStr);
10749 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10750 subId, enabled);
10751 }
10752
10753 /**
10754 * Gets the ims feature validation override value
10755 */
10756 @Override
10757 public boolean getImsFeatureValidationOverride(int subId) {
10758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10759 "getImsFeatureValidationOverride");
10760 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10761 }
10762
10763 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010764 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10765 * their mobile plan.
10766 */
10767 @Override
10768 public String getMobileProvisioningUrl() {
10769 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10770 final long identity = Binder.clearCallingIdentity();
10771 try {
10772 return getDefaultPhone().getMobileProvisioningUrl();
10773 } finally {
10774 Binder.restoreCallingIdentity(identity);
10775 }
10776 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010777
James.cf Linbcdf8b32021-01-14 16:44:13 +080010778 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010779 * Get the EAB contact from the EAB database.
10780 */
10781 @Override
10782 public String getContactFromEab(String contact) {
10783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10784 enforceModifyPermission();
10785 final long identity = Binder.clearCallingIdentity();
10786 try {
10787 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10788 } finally {
10789 Binder.restoreCallingIdentity(identity);
10790 }
10791 }
10792
10793 /**
Calvin Pana1434322021-07-01 19:27:01 +080010794 * Get the EAB capability from the EAB database.
10795 */
10796 @Override
10797 public String getCapabilityFromEab(String contact) {
10798 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10799 enforceModifyPermission();
10800 final long identity = Binder.clearCallingIdentity();
10801 try {
10802 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10803 } finally {
10804 Binder.restoreCallingIdentity(identity);
10805 }
10806 }
10807
10808 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010809 * Remove the EAB contacts from the EAB database.
10810 */
10811 @Override
10812 public int removeContactFromEab(int subId, String contacts) {
10813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10814 enforceModifyPermission();
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10818 } finally {
10819 Binder.restoreCallingIdentity(identity);
10820 }
10821 }
10822
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010823 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010824 public boolean getDeviceUceEnabled() {
10825 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10826 final long identity = Binder.clearCallingIdentity();
10827 try {
10828 return mApp.getDeviceUceEnabled();
10829 } finally {
10830 Binder.restoreCallingIdentity(identity);
10831 }
10832 }
10833
10834 @Override
10835 public void setDeviceUceEnabled(boolean isEnabled) {
10836 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10837 final long identity = Binder.clearCallingIdentity();
10838 try {
10839 mApp.setDeviceUceEnabled(isEnabled);
10840 } finally {
10841 Binder.restoreCallingIdentity(identity);
10842 }
10843 }
10844
Brad Ebinger14d467f2021-02-12 06:18:28 +000010845 /**
10846 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10847 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10848 */
10849 // Used for SHELL command only right now.
10850 @Override
10851 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10852 List<String> featureTags) {
10853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10854 "addUceRegistrationOverrideShell");
10855 final long identity = Binder.clearCallingIdentity();
10856 try {
10857 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10858 new ArraySet<>(featureTags));
10859 } catch (ImsException e) {
10860 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10861 } finally {
10862 Binder.restoreCallingIdentity(identity);
10863 }
10864 }
10865
10866 /**
10867 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10868 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10869 */
10870 // Used for SHELL command only right now.
10871 @Override
10872 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10873 List<String> featureTags) {
10874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10875 "removeUceRegistrationOverrideShell");
10876 final long identity = Binder.clearCallingIdentity();
10877 try {
10878 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10879 new ArraySet<>(featureTags));
10880 } catch (ImsException e) {
10881 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10882 } finally {
10883 Binder.restoreCallingIdentity(identity);
10884 }
10885 }
10886
10887 /**
10888 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10889 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10890 */
10891 // Used for SHELL command only right now.
10892 @Override
10893 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10895 "clearUceRegistrationOverrideShell");
10896 final long identity = Binder.clearCallingIdentity();
10897 try {
10898 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10899 } catch (ImsException e) {
10900 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10901 } finally {
10902 Binder.restoreCallingIdentity(identity);
10903 }
10904 }
10905
10906 /**
10907 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10908 */
10909 // Used for SHELL command only right now.
10910 @Override
10911 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10913 "getLatestRcsContactUceCapabilityShell");
10914 final long identity = Binder.clearCallingIdentity();
10915 try {
10916 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10917 } catch (ImsException e) {
10918 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10919 } finally {
10920 Binder.restoreCallingIdentity(identity);
10921 }
10922 }
10923
10924 /**
10925 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10926 * device does not have an active PUBLISH.
10927 */
10928 // Used for SHELL command only right now.
10929 @Override
10930 public String getLastUcePidfXmlShell(int subId) {
10931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10932 final long identity = Binder.clearCallingIdentity();
10933 try {
10934 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10935 } catch (ImsException e) {
10936 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10937 } finally {
10938 Binder.restoreCallingIdentity(identity);
10939 }
10940 }
10941
James.cf Line8713a42021-04-29 16:04:26 +080010942 /**
10943 * Remove UCE requests cannot be sent to the network status.
10944 */
10945 // Used for SHELL command only right now.
10946 @Override
10947 public boolean removeUceRequestDisallowedStatus(int subId) {
10948 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10949 final long identity = Binder.clearCallingIdentity();
10950 try {
10951 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10952 } catch (ImsException e) {
10953 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10954 } finally {
10955 Binder.restoreCallingIdentity(identity);
10956 }
10957 }
10958
James.cf Lin18bb9002021-05-25 01:37:38 +080010959 /**
10960 * Remove UCE requests cannot be sent to the network status.
10961 */
10962 // Used for SHELL command only.
10963 @Override
10964 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10966 final long identity = Binder.clearCallingIdentity();
10967 try {
10968 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10969 } catch (ImsException e) {
10970 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10971 } finally {
10972 Binder.restoreCallingIdentity(identity);
10973 }
10974 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010975
James.cf Lin4b784aa2021-01-31 03:25:15 +080010976 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010977 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10978 String callingPackage) {
10979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10980 mApp, subId, "setSignalStrengthUpdateRequest");
10981
10982 final int callingUid = Binder.getCallingUid();
10983 // Verify that tha callingPackage belongs to the calling UID
10984 mApp.getSystemService(AppOpsManager.class)
10985 .checkPackage(callingUid, callingPackage);
10986
Rambo Wang3607f502021-02-01 21:51:40 -080010987 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010988
10989 final long identity = Binder.clearCallingIdentity();
10990 try {
10991 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10992 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10993
10994 if (result instanceof IllegalStateException) {
10995 throw (IllegalStateException) result;
10996 }
10997 } finally {
10998 Binder.restoreCallingIdentity(identity);
10999 }
11000 }
11001
11002 @Override
11003 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11004 String callingPackage) {
11005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11006 mApp, subId, "clearSignalStrengthUpdateRequest");
11007
11008 final int callingUid = Binder.getCallingUid();
11009 // Verify that tha callingPackage belongs to the calling UID
11010 mApp.getSystemService(AppOpsManager.class)
11011 .checkPackage(callingUid, callingPackage);
11012
11013 final long identity = Binder.clearCallingIdentity();
11014 try {
11015 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11016 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11017
11018 if (result instanceof IllegalStateException) {
11019 throw (IllegalStateException) result;
11020 }
11021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
11025
Rambo Wang3607f502021-02-01 21:51:40 -080011026 private static void validateSignalStrengthUpdateRequest(Context context,
11027 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011028 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11029 // phone/system process do not have further restriction on request
11030 return;
11031 }
11032
11033 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011034 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011035 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011036 context.enforceCallingOrSelfPermission(
11037 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11038 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011039 }
11040
11041 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11042 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11043 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11044 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11045 || info.isEnabled()) {
11046 throw new IllegalArgumentException(
11047 "Only system can set hide fields in SignalThresholdInfo");
11048 }
11049
11050 // Thresholds length for each RAN need in range. This has been validated in
11051 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11052 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11053 final int[] thresholds = info.getThresholds();
11054 Objects.requireNonNull(thresholds);
11055 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11056 || thresholds.length
11057 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11058 throw new IllegalArgumentException(
11059 "thresholds length is out of range: " + thresholds.length);
11060 }
11061 }
11062 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011063
11064 /**
11065 * Gets the current phone capability.
11066 *
11067 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11068 * @return the PhoneCapability which describes the data connection capability of modem.
11069 * It's used to evaluate possible phone config change, for example from single
11070 * SIM device to multi-SIM device.
11071 */
11072 @Override
11073 public PhoneCapability getPhoneCapability() {
11074 enforceReadPrivilegedPermission("getPhoneCapability");
11075 final long identity = Binder.clearCallingIdentity();
11076 try {
11077 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11078 } finally {
11079 Binder.restoreCallingIdentity(identity);
11080 }
11081 }
Michele Berionne5e411512020-11-13 02:36:59 +000011082
11083 /**
11084 * Prepare TelephonyManager for an unattended reboot. The reboot is
11085 * required to be done shortly after the API is invoked.
11086 */
11087 @Override
11088 @TelephonyManager.PrepareUnattendedRebootResult
11089 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011091 enforceRebootPermission();
11092
11093 final long identity = Binder.clearCallingIdentity();
11094 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011095 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011096 } finally {
11097 Binder.restoreCallingIdentity(identity);
11098 }
11099 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011100
11101 /**
11102 * Request to get the current slicing configuration including URSP rules and
11103 * NSSAIs (configured, allowed and rejected).
11104 *
11105 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11106 */
11107 @Override
11108 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011109 TelephonyPermissions
11110 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11111 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011112
11113 final long identity = Binder.clearCallingIdentity();
11114 try {
11115 Phone phone = getDefaultPhone();
11116 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11117 } finally {
11118 Binder.restoreCallingIdentity(identity);
11119 }
11120 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011121
11122 /**
11123 * Register an IMS connection state callback
11124 */
11125 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011126 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11127 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011128 if (feature == ImsFeature.FEATURE_MMTEL) {
11129 // ImsMmTelManager
11130 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11131 TelephonyPermissions
11132 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11133 mApp, subId, "registerImsStateCallback");
11134 } else if (feature == ImsFeature.FEATURE_RCS) {
11135 // ImsRcsManager or SipDelegateManager
11136 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11137 Binder.getCallingUid(), "registerImsStateCallback",
11138 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11139 Manifest.permission.READ_PRECISE_PHONE_STATE,
11140 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11141 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11142 }
11143
11144 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11145 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11146 "IMS not available on device.");
11147 }
11148
11149 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11150 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11151 }
11152
11153 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11154 if (controller == null) {
11155 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11156 "IMS not available on device.");
11157 }
11158
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011159 if (callingPackage == null) {
11160 callingPackage = getCurrentPackageName();
11161 }
11162
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011163 final long token = Binder.clearCallingIdentity();
11164 try {
11165 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011166 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011167 } catch (ImsException e) {
11168 throw new ServiceSpecificException(e.getCode());
11169 } finally {
11170 Binder.restoreCallingIdentity(token);
11171 }
11172 }
11173
11174 /**
11175 * Unregister an IMS connection state callback
11176 */
11177 @Override
11178 public void unregisterImsStateCallback(IImsStateCallback cb) {
11179 final long token = Binder.clearCallingIdentity();
11180 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11181 if (controller == null) {
11182 return;
11183 }
11184 try {
11185 controller.unregisterImsStateCallback(cb);
11186 } finally {
11187 Binder.restoreCallingIdentity(token);
11188 }
11189 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011190
11191 /**
11192 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11193 *
11194 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11195 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11196 * SecurityException.
11197 * If there is current registered network this value will be same as the registered cell
11198 * identity. If the device goes out of service the previous cell identity is cached and
11199 * will be returned. If the cache age of the Cell identity is more than 24 hours
11200 * it will be cleared and null will be returned.
11201 *
11202 */
11203 @Override
11204 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11205 String callingFeatureId) {
11206 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11207 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11208 LocationAccessPolicy.checkLocationPermission(mApp,
11209 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11210 .setCallingPackage(callingPackage)
11211 .setCallingFeatureId(callingFeatureId)
11212 .setCallingPid(Binder.getCallingPid())
11213 .setCallingUid(Binder.getCallingUid())
11214 .setMethod("getLastKnownCellIdentity")
11215 .setLogAsInfo(true)
11216 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11217 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11218 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11219 .build());
11220
11221 boolean hasFinePermission =
11222 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11223 if (!hasFinePermission
11224 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11225 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11226 + "and BIND_CONNECTION_SERVICE permission.");
11227 }
11228
11229 final long identity = Binder.clearCallingIdentity();
11230 try {
11231 Phone phone = getPhone(subId);
11232 if (phone == null) return null;
11233 ServiceStateTracker sst = phone.getServiceStateTracker();
11234 if (sst == null) return null;
11235 return sst.getLastKnownCellIdentity();
11236 } finally {
11237 Binder.restoreCallingIdentity(identity);
11238 }
11239 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011240
11241 @Override
11242 public boolean isUsingNewDataStack() {
11243 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11244 return getDefaultPhone().isUsingNewDataStack();
11245 }
jimsun3b9ccac2021-10-26 15:01:23 +080011246
11247 /**
11248 * Sets the modem service class Name that Telephony will bind to.
11249 *
11250 * @param serviceName The class name of the modem service.
11251 * @return true if the operation is succeed, otherwise false.
11252 */
11253 public boolean setModemService(String serviceName) {
11254 Log.d(LOG_TAG, "setModemService - " + serviceName);
11255 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11257 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11258 "setModemService");
11259 return mPhoneConfigurationManager.setModemService(serviceName);
11260 }
11261
11262 /**
11263 * Return the class name of the currently bounded modem service.
11264 *
11265 * @return the class name of the modem service.
11266 */
11267 public String getModemService() {
11268 String result;
11269 Log.d(LOG_TAG, "getModemService");
11270 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11271 TelephonyPermissions
11272 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11273 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11274 "getModemService");
11275 result = mPhoneConfigurationManager.getModemService();
11276 Log.d(LOG_TAG, "result = " + result);
11277 return result;
11278 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011279
11280 @Override
11281 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11282 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11283 mApp.enforceCallingOrSelfPermission(
11284 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11285 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11286
11287 final long identity = Binder.clearCallingIdentity();
11288 try {
11289 Phone phone = getPhone(subId);
11290 if (phone == null) return;
11291 phone.setVoiceServiceStateOverride(hasService);
11292 } finally {
11293 Binder.restoreCallingIdentity(identity);
11294 }
11295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011296}