blob: 058251fa9a0c5c3bcdf840c963463e9608bb0c35 [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;
Jack Yuf745f972022-08-15 19:53:50 +0000187import 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);
Rambo Wange53e07d2022-05-10 13:01:13 -0700754 if (uiccPort == null) {
755 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
756 } else {
757 IccLogicalChannelRequest channelRequest =
758 (IccLogicalChannelRequest) request.argument;
759 channelRequest.channel = channelId;
760 uiccPort.onLogicalChannelOpened(channelRequest);
761 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 if (ar.result == null) {
764 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 if (ar.exception != null) {
767 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
768 }
769
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700770 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700771 if (ar.exception instanceof CommandException) {
772 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800773 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700774 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700775 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700776 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700777 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700778 }
779 }
780 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800781 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700783 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
787 case CMD_CLOSE_CHANNEL:
788 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000789 uiccPort = getUiccPortFromRequest(request);
790 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700791 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800792 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800793 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800794 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700795 } else {
796 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 break;
800
801 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 if (ar.exception == null) {
805 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800806 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700807 if (uiccPort == null) {
808 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
809 } else {
810 final int channelId = (Integer) request.argument;
811 uiccPort.onLogicalChannelClosed(channelId);
812 }
Chen Xu540470b2021-12-14 17:15:47 -0800813 } else {
814 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800815 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800816 if (ar.exception instanceof CommandException) {
817 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800820 if (error == CommandException.Error.INVALID_ARGUMENTS) {
821 // should only throw exceptions from the binder threads.
822 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800823 "iccCloseLogicalChannel: invalid argument ");
824 }
825 } else {
826 loge("iccCloseLogicalChannel: Unknown exception");
827 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800828 request.result = (exception != null) ? exception :
829 new IllegalStateException(
830 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800831 }
832 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800833 break;
834
835 case CMD_NV_READ_ITEM:
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800838 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
839 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800840 break;
841
842 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800845 if (ar.exception == null && ar.result != null) {
846 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800848 request.result = "";
849 if (ar.result == null) {
850 loge("nvReadItem: Empty response");
851 } else if (ar.exception instanceof CommandException) {
852 loge("nvReadItem: CommandException: " +
853 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800855 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700856 }
857 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700858 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 break;
860
Jake Hambye994d462014-02-03 13:10:13 -0800861 case CMD_NV_WRITE_ITEM:
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
864 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800865 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700866 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800867 break;
868
869 case EVENT_NV_WRITE_ITEM_DONE:
870 handleNullReturnEvent(msg, "nvWriteItem");
871 break;
872
873 case CMD_NV_WRITE_CDMA_PRL:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800876 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800877 break;
878
879 case EVENT_NV_WRITE_CDMA_PRL_DONE:
880 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
881 break;
882
chen xu6dac5ab2018-10-26 17:39:23 -0700883 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800884 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700885 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
chen xu6dac5ab2018-10-26 17:39:23 -0700889 case EVENT_RESET_MODEM_CONFIG_DONE:
890 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
Sooraj Sasindran37444802020-08-11 10:40:43 -0700893 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
896 request);
897 Phone phone = getPhoneFromRequest(request);
898 if (phone != null) {
899 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
900 } else {
901 loge("isNRDualConnectivityEnabled: No phone object");
902 request.result = false;
903 notifyRequester(request);
904 }
905 break;
906 }
907
908 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 // request.result must be set to something non-null
915 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700916 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 request.result = ar.result;
918 } else {
919 request.result = false;
920 }
921 if (ar.result == null) {
922 loge("isNRDualConnectivityEnabled: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("isNRDualConnectivityEnabled: CommandException: "
925 + ar.exception);
926 } else {
927 loge("isNRDualConnectivityEnabled: Unknown exception");
928 }
929 }
930 notifyRequester(request);
931 break;
932
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700933 case CMD_IS_VONR_ENABLED: {
934 request = (MainThreadRequest) msg.obj;
935 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
936 request);
937 Phone phone = getPhoneFromRequest(request);
938 if (phone != null) {
939 phone.isVoNrEnabled(onCompleted, request.workSource);
940 } else {
941 loge("isVoNrEnabled: No phone object");
942 request.result = false;
943 notifyRequester(request);
944 }
945 break;
946 }
947
948 case EVENT_IS_VONR_ENABLED_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null && ar.result != null) {
952 request.result = ar.result;
953 } else {
954 // request.result must be set to something non-null
955 // for the calling thread to unblock
956 if (ar.result != null) {
957 request.result = ar.result;
958 } else {
959 request.result = false;
960 }
961 if (ar.result == null) {
962 loge("isVoNrEnabled: Empty response");
963 } else if (ar.exception instanceof CommandException) {
964 loge("isVoNrEnabled: CommandException: "
965 + ar.exception);
966 } else {
967 loge("isVoNrEnabled: Unknown exception");
968 }
969 }
970 notifyRequester(request);
971 break;
972
Sooraj Sasindran37444802020-08-11 10:40:43 -0700973 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
976 Phone phone = getPhoneFromRequest(request);
977 if (phone != null) {
978 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
979 request.workSource);
980 } else {
981 loge("enableNrDualConnectivity: No phone object");
982 request.result =
983 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
984 notifyRequester(request);
985 }
986 break;
987 }
988
989 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 if (ar.exception == null) {
993 request.result =
994 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
995 } else {
996 request.result =
997 TelephonyManager
998 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
999 if (ar.exception instanceof CommandException) {
1000 CommandException.Error error =
1001 ((CommandException) (ar.exception)).getCommandError();
1002 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1003 request.result =
1004 TelephonyManager
1005 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001006 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1007 request.result =
1008 TelephonyManager
1009 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001010 }
1011 loge("enableNrDualConnectivity" + ": CommandException: "
1012 + ar.exception);
1013 } else {
1014 loge("enableNrDualConnectivity" + ": Unknown exception");
1015 }
1016 }
1017 notifyRequester(request);
1018 break;
1019 }
1020
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001021 case CMD_ENABLE_VONR: {
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1024 Phone phone = getPhoneFromRequest(request);
1025 if (phone != null) {
1026 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1027 request.workSource);
1028 } else {
1029 loge("setVoNrEnabled: No phone object");
1030 request.result =
1031 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1032 notifyRequester(request);
1033 }
1034 break;
1035 }
1036
1037 case EVENT_ENABLE_VONR_DONE: {
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 if (ar.exception == null) {
1041 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1042 } else {
1043 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1044 if (ar.exception instanceof CommandException) {
1045 CommandException.Error error =
1046 ((CommandException) (ar.exception)).getCommandError();
1047 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1048 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1049 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1050 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1051 } else {
1052 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1053 }
1054 loge("setVoNrEnabled" + ": CommandException: "
1055 + ar.exception);
1056 } else {
1057 loge("setVoNrEnabled" + ": Unknown exception");
1058 }
1059 }
1060 notifyRequester(request);
1061 break;
1062 }
1063
SongFerngWang3ef3e072020-12-21 16:41:52 +08001064 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001065 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1067 request);
1068 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001069 break;
1070
SongFerngWang3ef3e072020-12-21 16:41:52 +08001071 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
1074 if (ar.exception == null && ar.result != null) {
1075 request.result = ar.result; // Integer
1076 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301077 // request.result must be set to something non-null
1078 // for the calling thread to unblock
1079 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001080 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001081 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001083 loge("getAllowedNetworkTypesBitmask: CommandException: "
1084 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 }
1088 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001089 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 break;
1091
SongFerngWang3ef3e072020-12-21 16:41:52 +08001092 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001094 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1095 request);
1096 Pair<Integer, Long> reasonWithNetworkTypes =
1097 (Pair<Integer, Long>) request.argument;
1098 getPhoneFromRequest(request).setAllowedNetworkTypes(
1099 reasonWithNetworkTypes.first,
1100 reasonWithNetworkTypes.second,
1101 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 break;
1103
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1105 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 break;
1107
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001108 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1109 request = (MainThreadRequest)msg.obj;
1110 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001111 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001112 break;
1113
1114 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1115 ar = (AsyncResult)msg.obj;
1116 request = (MainThreadRequest)ar.userObj;
1117 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001118 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001119 break;
1120
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001121 case CMD_SET_VOICEMAIL_NUMBER:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1124 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001125 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1126 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001127 break;
1128
1129 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1130 handleNullReturnEvent(msg, "setVoicemailNumber");
1131 break;
1132
Stuart Scott54788802015-03-30 13:18:01 -07001133 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1134 request = (MainThreadRequest) msg.obj;
1135 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1136 request);
1137 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1138 break;
1139
1140 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1141 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1142 break;
1143
Shishir Agrawal302c8692015-06-19 13:49:39 -07001144 case CMD_PERFORM_NETWORK_SCAN:
1145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1147 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1148 break;
1149
Hall Liu27d24262020-09-18 19:04:59 -07001150 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001151 request = (MainThreadRequest) msg.obj;
1152 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001153 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1154 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1155 request.argument;
1156 int callForwardingReason = args.first;
1157 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001158 break;
Hall Liu27d24262020-09-18 19:04:59 -07001159 }
1160 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001163 TelephonyManager.CallForwardingInfoCallback callback =
1164 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1165 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001166 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001167 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001168 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1169 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1170 // Service Class is a bit mask per 3gpp 27.007. Search for
1171 // any service for voice call.
1172 if ((callForwardInfo.serviceClass
1173 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001174 callForwardingInfo = new CallForwardingInfo(
1175 callForwardInfo.status
1176 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001177 callForwardInfo.reason,
1178 callForwardInfo.number,
1179 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
1181 }
1182 }
1183 // Didn't find a call forward info for voice call.
1184 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001185 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1186 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001187 }
Hall Liu27d24262020-09-18 19:04:59 -07001188 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001189 } else {
1190 if (ar.result == null) {
1191 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1192 }
1193 if (ar.exception != null) {
1194 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1195 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001196 int errorCode = TelephonyManager
1197 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 if (ar.exception instanceof CommandException) {
1199 CommandException.Error error =
1200 ((CommandException) (ar.exception)).getCommandError();
1201 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001202 errorCode = TelephonyManager
1203 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001205 errorCode = TelephonyManager
1206 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 }
1208 }
Hall Liu27d24262020-09-18 19:04:59 -07001209 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
Shuo Qian4a594052020-01-23 11:59:30 -08001211 break;
Hall Liu27d24262020-09-18 19:04:59 -07001212 }
Shuo Qian4a594052020-01-23 11:59:30 -08001213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001217 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001219 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1220 request.argument).first;
1221 request.phone.setCallForwardingOption(
1222 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001223 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001224 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001225 callForwardingInfoToSet.getReason(),
1226 callForwardingInfoToSet.getNumber(),
1227 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1228 break;
Hall Liu27d24262020-09-18 19:04:59 -07001229 }
Shuo Qian4a594052020-01-23 11:59:30 -08001230
Hall Liu27d24262020-09-18 19:04:59 -07001231 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 ar = (AsyncResult) msg.obj;
1233 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001234 Consumer<Integer> callback =
1235 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1236 request.argument).second;
1237 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 int errorCode = TelephonyManager.CallForwardingInfoCallback
1240 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001241 if (ar.exception instanceof CommandException) {
1242 CommandException.Error error =
1243 ((CommandException) (ar.exception)).getCommandError();
1244 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001245 errorCode = TelephonyManager.CallForwardingInfoCallback
1246 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001247 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 errorCode = TelephonyManager.CallForwardingInfoCallback
1249 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
1251 }
1252 callback.accept(errorCode);
1253 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001254 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 }
Shuo Qian4a594052020-01-23 11:59:30 -08001256 break;
Hall Liu27d24262020-09-18 19:04:59 -07001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258
Hall Liu27d24262020-09-18 19:04:59 -07001259 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 request = (MainThreadRequest) msg.obj;
1261 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1262 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1263 break;
Hall Liu27d24262020-09-18 19:04:59 -07001264 }
Shuo Qian4a594052020-01-23 11:59:30 -08001265
Hall Liu27d24262020-09-18 19:04:59 -07001266 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001269 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001270 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001271 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001272 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 // Service Class is a bit mask per 3gpp 27.007.
1274 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001275 if (callForwardResults.length > 1
1276 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001277 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001278 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001279 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1280 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001282 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001283 }
1284 } else {
1285 if (ar.result == null) {
1286 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1287 }
1288 if (ar.exception != null) {
1289 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1290 }
1291 if (ar.exception instanceof CommandException) {
1292 CommandException.Error error =
1293 ((CommandException) (ar.exception)).getCommandError();
1294 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001296 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001297 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1298 callWaitingStatus =
1299 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001300 }
1301 }
1302 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 request = (MainThreadRequest) msg.obj;
1309 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001310 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1311 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001312 break;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314
Hall Liu27d24262020-09-18 19:04:59 -07001315 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001318 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1319 Consumer<Integer> callback =
1320 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1321 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001322 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001323 if (ar.exception instanceof CommandException) {
1324 CommandException.Error error =
1325 ((CommandException) (ar.exception)).getCommandError();
1326 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1329 callback.accept(
1330 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001331 } else {
1332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1333 }
1334 } else {
1335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1336 }
1337 } else {
1338 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1339 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001340 }
Shuo Qian4a594052020-01-23 11:59:30 -08001341 break;
Hall Liu27d24262020-09-18 19:04:59 -07001342 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001343 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1344 ar = (AsyncResult) msg.obj;
1345 request = (MainThreadRequest) ar.userObj;
1346 CellNetworkScanResult cellScanResult;
1347 if (ar.exception == null && ar.result != null) {
1348 cellScanResult = new CellNetworkScanResult(
1349 CellNetworkScanResult.STATUS_SUCCESS,
1350 (List<OperatorInfo>) ar.result);
1351 } else {
1352 if (ar.result == null) {
1353 loge("getCellNetworkScanResults: Empty response");
1354 }
1355 if (ar.exception != null) {
1356 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1357 }
1358 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1359 if (ar.exception instanceof CommandException) {
1360 CommandException.Error error =
1361 ((CommandException) (ar.exception)).getCommandError();
1362 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1363 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1364 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1365 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1366 }
1367 }
1368 cellScanResult = new CellNetworkScanResult(errorCode, null);
1369 }
1370 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001371 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001372 break;
1373
1374 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1375 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001376 ManualNetworkSelectionArgument selArg =
1377 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001378 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1379 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001380 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1381 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001382 break;
1383
1384 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 if (ar.exception == null) {
1388 request.result = true;
1389 } else {
1390 request.result = false;
1391 loge("setNetworkSelectionModeManual " + ar.exception);
1392 }
1393 notifyRequester(request);
1394 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001395 break;
1396
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001397 case CMD_GET_MODEM_ACTIVITY_INFO:
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001400 if (defaultPhone != null) {
1401 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001402 } else {
1403 ResultReceiver result = (ResultReceiver) request.argument;
1404 Bundle bundle = new Bundle();
1405 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001406 new ModemActivityInfo(0, 0, 0,
1407 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001409 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410 break;
1411
Hall Liud0f208c2020-10-14 16:54:44 -07001412 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001415 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001416 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001417 if (mLastModemActivityInfo == null) {
1418 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1419 mLastModemActivitySpecificInfo[0] =
1420 new ActivityStatsTechSpecificInfo(
1421 0,
1422 0,
1423 new int[ModemActivityInfo.getNumTxPowerLevels()],
1424 0);
1425 mLastModemActivityInfo =
1426 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1427 }
1428
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001429 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001430 // Update the last modem activity info and the result of the request.
1431 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1432 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001433 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001434 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001435 mLastModemActivityInfo =
1436 new ModemActivityInfo(
1437 mLastModemActivityInfo.getTimestampMillis(),
1438 mLastModemActivityInfo.getSleepTimeMillis(),
1439 mLastModemActivityInfo.getIdleTimeMillis(),
1440 mLastModemActivitySpecificInfo);
1441
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 } else {
1443 if (ar.result == null) {
1444 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001448 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001449 error = TelephonyManager.ModemActivityInfoException
1450 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 } else {
1452 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001453 error = TelephonyManager.ModemActivityInfoException
1454 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 }
1456 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001458 if (mLastModemActivityInfo != null) {
1459 bundle.putParcelable(
1460 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1461 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001462 } else {
1463 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1464 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001466 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001468 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469
Meng Wang1a7c35a2016-05-05 20:56:15 -07001470 case CMD_SET_ALLOWED_CARRIERS:
1471 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001472 CarrierRestrictionRules argument =
1473 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001474 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001475 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001476 break;
1477
1478 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 if (ar.exception == null && ar.result != null) {
1482 request.result = ar.result;
1483 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001484 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1485 if (ar.exception instanceof CommandException) {
1486 loge("setAllowedCarriers: CommandException: " + ar.exception);
1487 CommandException.Error error =
1488 ((CommandException) (ar.exception)).getCommandError();
1489 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1490 request.result =
1491 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1492 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 } else {
1494 loge("setAllowedCarriers: Unknown exception");
1495 }
1496 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001497 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 break;
1499
1500 case CMD_GET_ALLOWED_CARRIERS:
1501 request = (MainThreadRequest) msg.obj;
1502 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001503 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 break;
1505
1506 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1507 ar = (AsyncResult) msg.obj;
1508 request = (MainThreadRequest) ar.userObj;
1509 if (ar.exception == null && ar.result != null) {
1510 request.result = ar.result;
1511 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001512 request.result = new IllegalStateException(
1513 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 if (ar.result == null) {
1515 loge("getAllowedCarriers: Empty response");
1516 } else if (ar.exception instanceof CommandException) {
1517 loge("getAllowedCarriers: CommandException: " +
1518 ar.exception);
1519 } else {
1520 loge("getAllowedCarriers: Unknown exception");
1521 }
1522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524 break;
1525
Nathan Haroldb3014052017-01-25 15:57:32 -08001526 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1527 ar = (AsyncResult) msg.obj;
1528 request = (MainThreadRequest) ar.userObj;
1529 if (ar.exception == null && ar.result != null) {
1530 request.result = ar.result;
1531 } else {
1532 request.result = new IllegalArgumentException(
1533 "Failed to retrieve Forbidden Plmns");
1534 if (ar.result == null) {
1535 loge("getForbiddenPlmns: Empty response");
1536 } else {
1537 loge("getForbiddenPlmns: Unknown exception");
1538 }
1539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001541 break;
1542
1543 case CMD_GET_FORBIDDEN_PLMNS:
1544 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001545 uiccPort = getUiccPortFromRequest(request);
1546 if (uiccPort == null) {
1547 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001549 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001550 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001551 break;
1552 }
1553 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001554 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001555 if (uiccApp == null) {
1556 loge("getForbiddenPlmns() no app with specified type -- "
1557 + appType);
1558 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001559 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001560 break;
1561 } else {
1562 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1563 + " specified type -- " + appType);
1564 }
1565 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1566 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1567 onCompleted);
1568 break;
1569
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001570 case CMD_SWITCH_SLOTS:
1571 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001572 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001573 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001574 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001575 break;
1576
1577 case EVENT_SWITCH_SLOTS_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
1582 break;
1583 case CMD_GET_NETWORK_SELECTION_MODE:
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1586 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1587 break;
1588
1589 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1590 ar = (AsyncResult) msg.obj;
1591 request = (MainThreadRequest) ar.userObj;
1592 if (ar.exception != null) {
1593 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1594 } else {
1595 int mode = ((int[]) ar.result)[0];
1596 if (mode == 0) {
1597 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1598 } else {
1599 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1600 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001601 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001602 notifyRequester(request);
1603 break;
1604 case CMD_GET_CDMA_ROAMING_MODE:
1605 request = (MainThreadRequest) msg.obj;
1606 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1607 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1608 break;
1609 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
1612 if (ar.exception != null) {
1613 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1614 } else {
1615 request.result = ((int[]) ar.result)[0];
1616 }
1617 notifyRequester(request);
1618 break;
1619 case CMD_SET_CDMA_ROAMING_MODE:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1622 int mode = (int) request.argument;
1623 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1624 break;
1625 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 request.result = ar.exception == null;
1629 notifyRequester(request);
1630 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001631 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1632 request = (MainThreadRequest) msg.obj;
1633 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1634 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1635 break;
1636 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1637 ar = (AsyncResult) msg.obj;
1638 request = (MainThreadRequest) ar.userObj;
1639 if (ar.exception != null) {
1640 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1641 } else {
1642 request.result = ((int[]) ar.result)[0];
1643 }
1644 notifyRequester(request);
1645 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1647 request = (MainThreadRequest) msg.obj;
1648 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1649 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001650 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1651 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001652 break;
1653 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 request.result = ar.exception == null;
1657 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001658 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 case CMD_GET_ALL_CELL_INFO:
1660 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001661 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001662 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001663 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 case EVENT_GET_ALL_CELL_INFO_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001667 // If a timeout occurs, the response will be null
1668 request.result = (ar.exception == null && ar.result != null)
1669 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001670 synchronized (request) {
1671 request.notifyAll();
1672 }
1673 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001674 case CMD_REQUEST_CELL_INFO_UPDATE:
1675 request = (MainThreadRequest) msg.obj;
1676 request.phone.requestCellInfoUpdate(request.workSource,
1677 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1678 break;
1679 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1680 ar = (AsyncResult) msg.obj;
1681 request = (MainThreadRequest) ar.userObj;
1682 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1683 try {
1684 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001686 cb.onError(
1687 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1688 ar.exception.getClass().getName(),
1689 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001690 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001692 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001693 } else {
1694 // use the result as returned
1695 cb.onCellInfo((List<CellInfo>) ar.result);
1696 }
1697 } catch (RemoteException re) {
1698 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1699 }
1700 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001701 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001702 request = (MainThreadRequest) msg.obj;
1703 WorkSource ws = (WorkSource) request.argument;
1704 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001705 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001706 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001707 }
1708 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = ar.result;
1713 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001714 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001715 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001716 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001717 }
1718
1719 synchronized (request) {
1720 request.notifyAll();
1721 }
1722 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001723 }
chen xu6dac5ab2018-10-26 17:39:23 -07001724 case CMD_MODEM_REBOOT:
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001727 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001728 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001729 case EVENT_CMD_MODEM_REBOOT_DONE:
1730 handleNullReturnEvent(msg, "rebootModem");
1731 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001732 case CMD_REQUEST_ENABLE_MODEM:
1733 request = (MainThreadRequest) msg.obj;
1734 boolean enable = (boolean) request.argument;
1735 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001736 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001737 PhoneConfigurationManager.getInstance()
1738 .enablePhone(request.phone, enable, onCompleted);
1739 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001740 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001744 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001745 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001746 if ((boolean) request.result) {
1747 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1748 updateModemStateMetrics();
1749 } else {
1750 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1751 + ar.exception);
1752 }
1753 notifyRequester(request);
1754 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001755 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001756 case CMD_GET_MODEM_STATUS:
1757 request = (MainThreadRequest) msg.obj;
1758 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1759 PhoneConfigurationManager.getInstance()
1760 .getPhoneStatusFromModem(request.phone, onCompleted);
1761 break;
1762 case EVENT_GET_MODEM_STATUS_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 int id = request.phone.getPhoneId();
1766 if (ar.exception == null && ar.result != null) {
1767 request.result = ar.result;
1768 //update the cache as modem status has changed
1769 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1770 (boolean) request.result);
1771 } else {
1772 // Return true if modem status cannot be retrieved. For most cases,
1773 // modem status is on. And for older version modems, GET_MODEM_STATUS
1774 // and disable modem are not supported. Modem is always on.
1775 // TODO: this should be fixed in R to support a third
1776 // status UNKNOWN b/131631629
1777 request.result = true;
1778 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1779 + ar.exception);
1780 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001781 notifyRequester(request);
1782 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001783 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1784 request = (MainThreadRequest) msg.obj;
1785 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1786 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1787 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1788 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1789 break;
1790 }
1791 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1792 ar = (AsyncResult) msg.obj;
1793 request = (MainThreadRequest) ar.userObj;
1794 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1795 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1796 args.second.accept(ar.exception == null);
1797 notifyRequester(request);
1798 break;
1799 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1801 request = (MainThreadRequest) msg.obj;
1802 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1803 Phone phone = getPhoneFromRequest(request);
1804 if (phone != null) {
1805 phone.getSystemSelectionChannels(onCompleted);
1806 } else {
1807 loge("getSystemSelectionChannels: No phone object");
1808 request.result = new ArrayList<RadioAccessSpecifier>();
1809 notifyRequester(request);
1810 }
1811 break;
1812 }
1813 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 if (ar.exception == null && ar.result != null) {
1817 request.result = ar.result;
1818 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001819 request.result = new IllegalStateException(
1820 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001821 if (ar.result == null) {
1822 loge("getSystemSelectionChannels: Empty response");
1823 } else {
1824 loge("getSystemSelectionChannels: Unknown exception");
1825 }
1826 }
1827 notifyRequester(request);
1828 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001829 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 if (ar.exception == null && ar.result != null) {
1833 request.result = ar.result;
1834 } else {
1835 request.result = -1;
1836 loge("Failed to set Forbidden Plmns");
1837 if (ar.result == null) {
1838 loge("setForbidenPlmns: Empty response");
1839 } else if (ar.exception != null) {
1840 loge("setForbiddenPlmns: Exception: " + ar.exception);
1841 request.result = -1;
1842 } else {
1843 loge("setForbiddenPlmns: Unknown exception");
1844 }
1845 }
1846 notifyRequester(request);
1847 break;
1848 case CMD_SET_FORBIDDEN_PLMNS:
1849 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001850 uiccPort = getUiccPortFromRequest(request);
1851 if (uiccPort == null) {
1852 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001853 request.result = -1;
1854 notifyRequester(request);
1855 break;
1856 }
1857 Pair<Integer, List<String>> setFplmnsArgs =
1858 (Pair<Integer, List<String>>) request.argument;
1859 appType = setFplmnsArgs.first;
1860 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001861 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001862 if (uiccApp == null) {
1863 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1864 request.result = -1;
1865 loge("Failed to get UICC App");
1866 notifyRequester(request);
1867 } else {
1868 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1869 ((SIMRecords) uiccApp.getIccRecords())
1870 .setForbiddenPlmns(onCompleted, fplmns);
1871 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001872 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001873 case CMD_ERASE_MODEM_CONFIG:
1874 request = (MainThreadRequest) msg.obj;
1875 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1876 defaultPhone.eraseModemConfig(onCompleted);
1877 break;
1878 case EVENT_ERASE_MODEM_CONFIG_DONE:
1879 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001880 break;
zoey chene02881a2019-12-30 16:11:23 +08001881
Kai Shif70f46f2021-03-03 13:59:46 -08001882 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1883 request = (MainThreadRequest) msg.obj;
1884 request.result = defaultPhone.eraseDataInSharedPreferences();
1885 notifyRequester(request);
1886 break;
1887
zoey chene02881a2019-12-30 16:11:23 +08001888 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1891 Pair<String, String> changed = (Pair<String, String>) request.argument;
1892 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1893 changed.first, changed.second, onCompleted);
1894 break;
1895 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 if (ar.exception == null) {
1899 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001900 // If the operation is successful, update the PIN storage
1901 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1902 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001903 UiccController.getInstance().getPinStorage()
1904 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001905 } else {
1906 request.result = msg.arg1;
1907 }
1908 notifyRequester(request);
1909 break;
1910
Michele Berionne5e411512020-11-13 02:36:59 +00001911 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001912 request = (MainThreadRequest) msg.obj;
1913 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1914 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1915 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1916 enabled.first, enabled.second, onCompleted);
1917 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001918 }
zoey chene02881a2019-12-30 16:11:23 +08001919 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1920 ar = (AsyncResult) msg.obj;
1921 request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null) {
1923 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001924 // If the operation is successful, update the PIN storage
1925 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1926 int phoneId = getPhoneFromRequest(request).getPhoneId();
1927 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001928 UiccController.getInstance().getPinStorage()
1929 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001930 } else {
1931 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1932 }
zoey chene02881a2019-12-30 16:11:23 +08001933 } else {
1934 request.result = msg.arg1;
1935 }
Michele Berionne5e411512020-11-13 02:36:59 +00001936
1937
zoey chene02881a2019-12-30 16:11:23 +08001938 notifyRequester(request);
1939 break;
1940
Peter Wangdafb9ac2020-01-15 14:13:38 -08001941 case MSG_NOTIFY_USER_ACTIVITY:
1942 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001943 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001944 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1945 getDefaultPhone().getContext().sendBroadcastAsUser(
1946 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1947 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001948
1949 case CMD_SET_DATA_THROTTLING: {
1950 request = (MainThreadRequest) msg.obj;
1951 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1952 DataThrottlingRequest dataThrottlingRequest =
1953 (DataThrottlingRequest) request.argument;
1954 Phone phone = getPhoneFromRequest(request);
1955 if (phone != null) {
1956 phone.setDataThrottling(onCompleted,
1957 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1958 dataThrottlingRequest.getCompletionDurationMillis());
1959 } else {
1960 loge("setDataThrottling: No phone object");
1961 request.result =
1962 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1963 notifyRequester(request);
1964 }
1965
1966 break;
1967 }
1968 case EVENT_SET_DATA_THROTTLING_DONE:
1969 ar = (AsyncResult) msg.obj;
1970 request = (MainThreadRequest) ar.userObj;
1971
1972 if (ar.exception == null) {
1973 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1974 } else if (ar.exception instanceof CommandException) {
1975 loge("setDataThrottling: CommandException: " + ar.exception);
1976 CommandException.Error error =
1977 ((CommandException) (ar.exception)).getCommandError();
1978
1979 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1980 request.result = TelephonyManager
1981 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1982 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1983 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001984 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1985 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001986 } else {
1987 request.result =
1988 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1989 }
1990 } else {
1991 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1992 }
1993 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1994 notifyRequester(request);
1995 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001996
1997 case CMD_SET_SIM_POWER: {
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2000 request = (MainThreadRequest) msg.obj;
2001 int stateToSet =
2002 ((Pair<Integer, IIntegerConsumer>)
2003 request.argument).first;
2004 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2005 break;
2006 }
2007 case EVENT_SET_SIM_POWER_DONE: {
2008 ar = (AsyncResult) msg.obj;
2009 request = (MainThreadRequest) ar.userObj;
2010 IIntegerConsumer callback =
2011 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2012 if (ar.exception != null) {
2013 loge("setSimPower exception: " + ar.exception);
2014 int errorCode = TelephonyManager.CallForwardingInfoCallback
2015 .RESULT_ERROR_UNKNOWN;
2016 if (ar.exception instanceof CommandException) {
2017 CommandException.Error error =
2018 ((CommandException) (ar.exception)).getCommandError();
2019 if (error == CommandException.Error.SIM_ERR) {
2020 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2021 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2022 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2023 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2024 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2025 } else {
2026 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2027 }
2028 }
2029 try {
2030 callback.accept(errorCode);
2031 } catch (RemoteException e) {
2032 // Ignore if the remote process is no longer available to call back.
2033 Log.w(LOG_TAG, "setSimPower: callback not available.");
2034 }
2035 } else {
2036 try {
2037 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2038 } catch (RemoteException e) {
2039 // Ignore if the remote process is no longer available to call back.
2040 Log.w(LOG_TAG, "setSimPower: callback not available.");
2041 }
2042 }
2043 break;
2044 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002045 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2046 request = (MainThreadRequest) msg.obj;
2047
2048 final Phone phone = getPhoneFromRequest(request);
2049 if (phone == null || phone.getServiceStateTracker() == null) {
2050 request.result = new IllegalStateException("Phone or SST is null");
2051 notifyRequester(request);
2052 break;
2053 }
2054
2055 Pair<Integer, SignalStrengthUpdateRequest> pair =
2056 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2057 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2058 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002059 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002060 request.subId, pair.first /*callingUid*/,
2061 pair.second /*request*/, onCompleted);
2062 break;
2063 }
2064 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2065 ar = (AsyncResult) msg.obj;
2066 request = (MainThreadRequest) ar.userObj;
2067 // request.result will be the exception of ar if present, true otherwise.
2068 // Be cautious not to leave result null which will wait() forever
2069 request.result = ar.exception != null ? ar.exception : true;
2070 notifyRequester(request);
2071 break;
2072 }
2073 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2074 request = (MainThreadRequest) msg.obj;
2075
2076 Phone phone = getPhoneFromRequest(request);
2077 if (phone == null || phone.getServiceStateTracker() == null) {
2078 request.result = new IllegalStateException("Phone or SST is null");
2079 notifyRequester(request);
2080 break;
2081 }
2082
2083 Pair<Integer, SignalStrengthUpdateRequest> pair =
2084 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2085 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2086 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002087 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002088 request.subId, pair.first /*callingUid*/,
2089 pair.second /*request*/, onCompleted);
2090 break;
2091 }
2092 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095 request.result = ar.exception != null ? ar.exception : true;
2096 notifyRequester(request);
2097 break;
2098 }
Jordan Liu109698e2020-11-24 14:50:34 -08002099
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 case CMD_GET_SLICING_CONFIG: {
2101 request = (MainThreadRequest) msg.obj;
2102 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2103 request.phone.getSlicingConfig(onCompleted);
2104 break;
2105 }
2106 case EVENT_GET_SLICING_CONFIG_DONE: {
2107 ar = (AsyncResult) msg.obj;
2108 request = (MainThreadRequest) ar.userObj;
2109 ResultReceiver result = (ResultReceiver) request.argument;
2110
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002112 Bundle bundle = new Bundle();
2113 int resultCode = 0;
2114 if (ar.exception != null) {
2115 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2116 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002117 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002118 } else if (ar.result == null) {
2119 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002120 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 } else {
2122 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2124 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002125 }
2126
2127 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002128 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002129 }
2130 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2131 result.send(resultCode, bundle);
2132 notifyRequester(request);
2133 break;
2134 }
2135
Michele Berionne5e411512020-11-13 02:36:59 +00002136 case CMD_PREPARE_UNATTENDED_REBOOT:
2137 request = (MainThreadRequest) msg.obj;
2138 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002139 UiccController.getInstance().getPinStorage()
2140 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002141 notifyRequester(request);
2142 break;
2143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 default:
2145 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2146 break;
2147 }
2148 }
Jake Hambye994d462014-02-03 13:10:13 -08002149
Pengquan Menga1bb6272018-09-06 09:59:22 -07002150 private void notifyRequester(MainThreadRequest request) {
2151 synchronized (request) {
2152 request.notifyAll();
2153 }
2154 }
2155
Jake Hambye994d462014-02-03 13:10:13 -08002156 private void handleNullReturnEvent(Message msg, String command) {
2157 AsyncResult ar = (AsyncResult) msg.obj;
2158 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2159 if (ar.exception == null) {
2160 request.result = true;
2161 } else {
2162 request.result = false;
2163 if (ar.exception instanceof CommandException) {
2164 loge(command + ": CommandException: " + ar.exception);
2165 } else {
2166 loge(command + ": Unknown exception");
2167 }
2168 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002169 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 }
2172
2173 /**
2174 * Posts the specified command to be executed on the main thread,
2175 * waits for the request to complete, and returns the result.
2176 * @see #sendRequestAsync
2177 */
2178 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2180 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002181 }
2182
2183 /**
2184 * Posts the specified command to be executed on the main thread,
2185 * waits for the request to complete, and returns the result.
2186 * @see #sendRequestAsync
2187 */
2188 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2189 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002190 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002191 }
2192
2193 /**
2194 * Posts the specified command to be executed on the main thread,
2195 * waits for the request to complete, and returns the result.
2196 * @see #sendRequestAsync
2197 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002198 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2200 }
2201
2202 /**
2203 * Posts the specified command to be executed on the main thread,
2204 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2205 * if not timeout or null otherwise.
2206 * @see #sendRequestAsync
2207 */
2208 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2209 long timeoutInMs) {
2210 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002211 }
2212
2213 /**
2214 * Posts the specified command to be executed on the main thread,
2215 * waits for the request to complete, and returns the result.
2216 * @see #sendRequestAsync
2217 */
Nathan Harold92bed182018-10-12 18:16:49 -07002218 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002219 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002220 }
2221
2222 /**
2223 * Posts the specified command to be executed on the main thread,
2224 * waits for the request to complete, and returns the result.
2225 * @see #sendRequestAsync
2226 */
2227 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002228 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2229 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002230 }
2231
2232 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2234 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2235 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002236 * @see #sendRequestAsync
2237 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002238 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2239 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2241 throw new RuntimeException("This method will deadlock if called from the main thread.");
2242 }
2243
Nathan Harold92bed182018-10-12 18:16:49 -07002244 MainThreadRequest request = null;
2245 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2246 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2247 } else if (phone != null) {
2248 request = new MainThreadRequest(argument, phone, workSource);
2249 } else {
2250 request = new MainThreadRequest(argument, subId, workSource);
2251 }
2252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 Message msg = mMainThreadHandler.obtainMessage(command, request);
2254 msg.sendToTarget();
2255
Rambo Wang0f050d82021-02-12 11:43:36 -08002256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002258 if (timeoutInMs >= 0) {
2259 // Wait for at least timeoutInMs before returning null request result
2260 long now = SystemClock.elapsedRealtime();
2261 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002262 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002263 try {
2264 request.wait(deadline - now);
2265 } catch (InterruptedException e) {
2266 // Do nothing, go back and check if request is completed or timeout
2267 } finally {
2268 now = SystemClock.elapsedRealtime();
2269 }
2270 }
2271 } else {
2272 // Wait for the request to complete
2273 while (request.result == null) {
2274 try {
2275 request.wait();
2276 } catch (InterruptedException e) {
2277 // Do nothing, go back and wait until the request is complete
2278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280 }
2281 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002282 if (request.result == null) {
2283 Log.wtf(LOG_TAG,
2284 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 return request.result;
2287 }
2288
2289 /**
2290 * Asynchronous ("fire and forget") version of sendRequest():
2291 * Posts the specified command to be executed on the main thread, and
2292 * returns immediately.
2293 * @see #sendRequest
2294 */
2295 private void sendRequestAsync(int command) {
2296 mMainThreadHandler.sendEmptyMessage(command);
2297 }
2298
2299 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002300 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002301 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002302 */
2303 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002304 sendRequestAsync(command, argument, null, null);
2305 }
2306
2307 /**
2308 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2309 * @see {@link #sendRequest(int,Object)}
2310 */
2311 private void sendRequestAsync(
2312 int command, Object argument, Phone phone, WorkSource workSource) {
2313 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002314 Message msg = mMainThreadHandler.obtainMessage(command, request);
2315 msg.sendToTarget();
2316 }
2317
2318 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 * Initialize the singleton PhoneInterfaceManager instance.
2320 * This is only done once, at startup, from PhoneApp.onCreate().
2321 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002322 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 synchronized (PhoneInterfaceManager.class) {
2324 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002325 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 } else {
2327 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2328 }
2329 return sInstance;
2330 }
2331 }
2332
2333 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002334 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002337 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002338 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002340 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002342 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002343 mTelephonySharedPreferences =
2344 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002345 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002346 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002347 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002348 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002349 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 publish();
2351 }
2352
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002353 private Phone getDefaultPhone() {
2354 Phone thePhone = getPhone(getDefaultSubscription());
2355 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2356 }
2357
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 private void publish() {
2359 if (DBG) log("publish: " + this);
2360
Peter Wangc035ce42020-01-08 21:00:22 -08002361 TelephonyFrameworkInitializer
2362 .getTelephonyServiceManager()
2363 .getTelephonyServiceRegisterer()
2364 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 }
2366
Stuart Scott584921c2015-01-15 17:10:34 -08002367 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002368 if (request.phone != null) {
2369 return request.phone;
2370 } else {
2371 return getPhoneFromSubId(request.subId);
2372 }
2373 }
2374
2375 private Phone getPhoneFromSubId(int subId) {
2376 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2377 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002378 }
2379
Rambo Wange53e07d2022-05-10 13:01:13 -07002380 @Nullable
2381 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002382 Phone phone = getPhoneFromRequest(request);
2383 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002384 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002385 }
2386
Wink Saville36469e72014-06-11 15:17:00 -07002387 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002388 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002389 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391
Kai Shif70f46f2021-03-03 13:59:46 -08002392 private void sendEraseModemConfig(@NonNull Phone phone) {
2393 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2394 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2395 }
2396
2397 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2398 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2399 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002400 }
2401
Peter Wang44b186e2020-01-13 23:33:09 -08002402 private boolean isImsAvailableOnDevice() {
2403 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2404 if (pm == null) {
2405 // For some reason package manger is not available.. This will fail internally anyway,
2406 // so do not throw error and allow.
2407 return true;
2408 }
2409 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2410 }
2411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002413 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002414 }
2415
Wink Savilleb564aae2014-10-23 10:18:09 -07002416 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 if (DBG) log("dial: " + number);
2418 // No permission check needed here: This is just a wrapper around the
2419 // ACTION_DIAL intent, which is available to any app since it puts up
2420 // the UI before it does anything.
2421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 String url = createTelUrl(number);
2425 if (url == null) {
2426 return;
2427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 // PENDING: should we just silently fail if phone is offhook or ringing?
2430 PhoneConstants.State state = mCM.getState(subId);
2431 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2432 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2433 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2434 mApp.startActivity(intent);
2435 }
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 }
2439 }
2440
2441 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002442 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002443 }
2444
Wink Savilleb564aae2014-10-23 10:18:09 -07002445 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 if (DBG) log("call: " + number);
2447
2448 // This is just a wrapper around the ACTION_CALL intent, but we still
2449 // need to do a permission check since we're calling startActivity()
2450 // from the context of the phone app.
2451 enforceCallPermission();
2452
Jordan Liu1617b712019-07-10 15:06:26 -07002453 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 != AppOpsManager.MODE_ALLOWED) {
2455 return;
2456 }
2457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458 final long identity = Binder.clearCallingIdentity();
2459 try {
2460 String url = createTelUrl(number);
2461 if (url == null) {
2462 return;
2463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 boolean isValid = false;
2466 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2467 if (slist != null) {
2468 for (SubscriptionInfo subInfoRecord : slist) {
2469 if (subInfoRecord.getSubscriptionId() == subId) {
2470 isValid = true;
2471 break;
2472 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002473 }
Wink Saville08874612014-08-31 19:19:58 -07002474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475 if (!isValid) {
2476 return;
2477 }
Wink Saville08874612014-08-31 19:19:58 -07002478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2480 intent.putExtra(SUBSCRIPTION_KEY, subId);
2481 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2482 mApp.startActivity(intent);
2483 } finally {
2484 Binder.restoreCallingIdentity(identity);
2485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 }
2487
Wink Savilleb564aae2014-10-23 10:18:09 -07002488 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002489 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002490 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2491 }
2492
Wink Savilleb564aae2014-10-23 10:18:09 -07002493 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002494 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002495 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2496 }
2497
Wink Savilleb564aae2014-10-23 10:18:09 -07002498 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002503 Phone phone = getPhone(subId);
2504 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 checkSimPin.start();
2506 return checkSimPin.unlockSim(null, pin);
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
2509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
2511
Wink Savilleb564aae2014-10-23 10:18:09 -07002512 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002517 Phone phone = getPhone(subId);
2518 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 checkSimPuk.start();
2520 return checkSimPuk.unlockSim(puk, pin);
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
2523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
2526 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002527 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 * a synchronous one.
2529 */
2530 private static class UnlockSim extends Thread {
2531
2532 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002533 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534
2535 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002536 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2537 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538
2539 // For replies from SimCard interface
2540 private Handler mHandler;
2541
2542 // For async handler to identify request type
2543 private static final int SUPPLY_PIN_COMPLETE = 100;
2544
Michele Berionne5e411512020-11-13 02:36:59 +00002545 UnlockSim(int phoneId, IccCard simCard) {
2546 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 mSimCard = simCard;
2548 }
2549
2550 @Override
2551 public void run() {
2552 Looper.prepare();
2553 synchronized (UnlockSim.this) {
2554 mHandler = new Handler() {
2555 @Override
2556 public void handleMessage(Message msg) {
2557 AsyncResult ar = (AsyncResult) msg.obj;
2558 switch (msg.what) {
2559 case SUPPLY_PIN_COMPLETE:
2560 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2561 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002562 mRetryCount = msg.arg1;
2563 if (ar.exception != null) {
2564 if (ar.exception instanceof CommandException &&
2565 ((CommandException)(ar.exception)).getCommandError()
2566 == CommandException.Error.PASSWORD_INCORRECT) {
2567 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002568 } //When UiccCardApp dispose,handle message and return exception
2569 else if (ar.exception instanceof CommandException &&
2570 ((CommandException) (ar.exception)).getCommandError()
2571 == CommandException.Error.ABORTED) {
2572 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002573 } else {
2574 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2575 }
2576 } else {
2577 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 mDone = true;
2580 UnlockSim.this.notifyAll();
2581 }
2582 break;
2583 }
2584 }
2585 };
2586 UnlockSim.this.notifyAll();
2587 }
2588 Looper.loop();
2589 }
2590
2591 /*
2592 * Use PIN or PUK to unlock SIM card
2593 *
2594 * If PUK is null, unlock SIM card with PIN
2595 *
2596 * If PUK is not null, unlock SIM card with PUK and set PIN code
2597 */
Wink Saville9de0f752013-10-22 19:04:03 -07002598 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599
2600 while (mHandler == null) {
2601 try {
2602 wait();
2603 } catch (InterruptedException e) {
2604 Thread.currentThread().interrupt();
2605 }
2606 }
2607 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2608
2609 if (puk == null) {
2610 mSimCard.supplyPin(pin, callback);
2611 } else {
2612 mSimCard.supplyPuk(puk, pin, callback);
2613 }
2614
2615 while (!mDone) {
2616 try {
2617 Log.d(LOG_TAG, "wait for done");
2618 wait();
2619 } catch (InterruptedException e) {
2620 // Restore the interrupted status
2621 Thread.currentThread().interrupt();
2622 }
2623 }
2624 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002625 int[] resultArray = new int[2];
2626 resultArray[0] = mResult;
2627 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002628
2629 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002630 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002631 }
2632
Wink Saville9de0f752013-10-22 19:04:03 -07002633 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635 }
2636
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002637 /**
2638 * This method has been removed due to privacy and stability concerns.
2639 */
2640 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002642 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2643 return;
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Nathan Harold1f889d82020-06-04 17:05:26 -07002646 @Override
2647 public void updateServiceLocationWithPackageName(String callingPackage) {
2648 mApp.getSystemService(AppOpsManager.class)
2649 .checkPackage(Binder.getCallingUid(), callingPackage);
2650
Nathan Haroldf096d982020-11-18 17:18:06 -08002651 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002652 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2653 // Callers targeting S have no business invoking this method.
2654 return;
2655 }
2656
2657 LocationAccessPolicy.LocationPermissionResult locationResult =
2658 LocationAccessPolicy.checkLocationPermission(mApp,
2659 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2660 .setCallingPackage(callingPackage)
2661 .setCallingFeatureId(null)
2662 .setCallingPid(Binder.getCallingPid())
2663 .setCallingUid(Binder.getCallingUid())
2664 .setMethod("updateServiceLocation")
2665 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2666 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2667 .build());
2668 // Apps that lack location permission have no business calling this method;
2669 // however, because no permission was declared in the public API, denials must
2670 // all be "soft".
2671 switch (locationResult) {
2672 case DENIED_HARD: /* fall through */
2673 case DENIED_SOFT:
2674 return;
2675 }
2676
2677 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002680 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002682 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 }
2688
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002689 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002690 @Override
2691 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002692 return isRadioOnWithFeature(callingPackage, null);
2693 }
2694
2695
2696 @Override
2697 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2698 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2699 callingFeatureId);
2700 }
2701
2702 @Deprecated
2703 @Override
2704 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2705 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002706 }
2707
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002709 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2710 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002712 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002713 return false;
2714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715
2716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 return isRadioOnForSubscriber(subId);
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
2721 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002722 }
2723
2724 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 final Phone phone = getPhone(subId);
2728 if (phone != null) {
2729 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2730 } else {
2731 return false;
2732 }
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 }
2737
2738 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002739 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 }
Wink Saville36469e72014-06-11 15:17:00 -07002741
Wink Savilleb564aae2014-10-23 10:18:09 -07002742 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 final Phone phone = getPhone(subId);
2748 if (phone != null) {
2749 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 }
Wink Saville36469e72014-06-11 15:17:00 -07002754 }
2755
2756 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002757 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002758 }
2759
Wink Savilleb564aae2014-10-23 10:18:09 -07002760 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 final Phone phone = getPhone(subId);
2766 if (phone == null) {
2767 return false;
2768 }
2769 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2770 toggleRadioOnOffForSubscriber(subId);
2771 }
2772 return true;
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 }
Wink Saville36469e72014-06-11 15:17:00 -07002777
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002778 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002779 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002780 /*
2781 * If any of the Radios are available, it will need to be
2782 * shutdown. So return true if any Radio is available.
2783 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2787 Phone phone = PhoneFactory.getPhone(i);
2788 if (phone != null && phone.isRadioAvailable()) return true;
2789 }
2790 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2791 return false;
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002794 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002795 }
2796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002798 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 enforceModifyPermission();
2800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2804 logv("Shutting down Phone " + i);
2805 shutdownRadioUsingPhoneId(i);
2806 }
2807 } finally {
2808 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002809 }
2810 }
2811
2812 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002813 Phone phone = PhoneFactory.getPhone(phoneId);
2814 if (phone != null && phone.isRadioAvailable()) {
2815 phone.shutdownRadio();
2816 }
2817 }
2818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2825 if (defaultPhone != null) {
2826 defaultPhone.setRadioPower(turnOn);
2827 return true;
2828 } else {
2829 loge("There's no default phone.");
2830 return false;
2831 }
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002834 }
Wink Saville36469e72014-06-11 15:17:00 -07002835 }
2836
Wink Savilleb564aae2014-10-23 10:18:09 -07002837 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839
2840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 final Phone phone = getPhone(subId);
2843 if (phone != null) {
2844 phone.setRadioPower(turnOn);
2845 return true;
2846 } else {
2847 return false;
2848 }
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 }
2853
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002854 /**
2855 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2856 * no reason to power it off. When any of the voters want to power it off, it will be turned
2857 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2858 * powering it off, and these radio off votes will be cleared.
2859 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2860 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2861 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2862 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2863 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2864 * check its vote.
2865 *
2866 * @param subId The subscription ID.
2867 * @param reason The reason for powering off radio.
2868 * @return true on success and false on failure.
2869 */
2870 public boolean requestRadioPowerOffForReason(int subId,
2871 @TelephonyManager.RadioPowerReason int reason) {
2872 enforceModifyPermission();
2873
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 final Phone phone = getPhone(subId);
2877 if (phone != null) {
2878 phone.setRadioPowerForReason(false, reason);
2879 return true;
2880 } else {
2881 return false;
2882 }
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
2886 }
2887
2888 /**
2889 * Remove the vote on powering off the radio for a reason, as requested by
2890 * {@link requestRadioPowerOffForReason}.
2891 *
2892 * @param subId The subscription ID.
2893 * @param reason The reason for powering off radio.
2894 * @return true on success and false on failure.
2895 */
2896 public boolean clearRadioPowerOffForReason(int subId,
2897 @TelephonyManager.RadioPowerReason int reason) {
2898 enforceModifyPermission();
2899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 if (phone != null) {
2904 phone.setRadioPowerForReason(true, reason);
2905 return true;
2906 } else {
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
2912 }
2913
2914 /**
2915 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2916 *
2917 * @param subId The subscription ID.
2918 * @param callingPackage The package making the call.
2919 * @param callingFeatureId The feature in the package.
2920 * @return List of reasons for powering off radio.
2921 */
2922 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2923 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2924
2925 final long identity = Binder.clearCallingIdentity();
2926 List result = new ArrayList();
2927 try {
2928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2929 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2930 return result;
2931 }
2932
2933 final Phone phone = getPhone(subId);
2934 if (phone != null) {
2935 result.addAll(phone.getRadioPowerOffReasons());
2936 }
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 return result;
2941 }
2942
Wink Saville36469e72014-06-11 15:17:00 -07002943 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002945 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 int subId = mSubscriptionController.getDefaultDataSubId();
2951 final Phone phone = getPhone(subId);
2952 if (phone != null) {
Jack Yuf745f972022-08-15 19:53:50 +00002953 if (phone.isUsingNewDataStack()) {
2954 phone.getDataSettingsManager().setDataEnabled(
2955 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
2956 } else {
2957 phone.getDataEnabledSettings().setDataEnabled(
2958 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 return true;
2961 } else {
2962 return false;
2963 }
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967 }
2968
Wink Saville36469e72014-06-11 15:17:00 -07002969 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002970 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002971 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 int subId = mSubscriptionController.getDefaultDataSubId();
2977 final Phone phone = getPhone(subId);
2978 if (phone != null) {
Jack Yuf745f972022-08-15 19:53:50 +00002979 if (phone.isUsingNewDataStack()) {
2980 phone.getDataSettingsManager().setDataEnabled(
2981 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
2982 } else {
2983 phone.getDataEnabledSettings().setDataEnabled(
2984 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 return true;
2987 } else {
2988 return false;
2989 }
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 }
2994
Sanket Padawe356d7632015-06-22 14:03:32 -07002995 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002996 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 final Phone phone = getPhone(subId);
3000 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003001 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 } else {
3003 return false;
3004 }
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 }
3009
3010 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003011 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003012 }
3013
pkanwarae03a6b2016-11-06 20:37:09 -08003014 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 enforceCallPermission();
3016
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3020 return;
3021 }
3022 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3023 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
pkanwar32d516d2016-10-14 19:37:38 -07003027 };
3028
Wink Savilleb564aae2014-10-23 10:18:09 -07003029 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3035 return false;
3036 }
3037 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 }
3042
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003043 /**
3044 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3045 * tag on getCallState Binder call.
3046 */
3047 @Deprecated
3048 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003050 if (CompatChanges.isChangeEnabled(
3051 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3052 Binder.getCallingUid())) {
3053 // Do not allow this API to be called on API version 31+, it should only be
3054 // called on old apps using this Binder call directly.
3055 throw new SecurityException("This method can only be used for applications "
3056 + "targeting API version 30 or less.");
3057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003058 final long identity = Binder.clearCallingIdentity();
3059 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003060 Phone phone = getPhone(getDefaultSubscription());
3061 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3062 PhoneConstantConversions.convertCallState(phone.getState());
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
3066 }
3067
3068 @Override
3069 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3070 if (CompatChanges.isChangeEnabled(
3071 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3072 Binder.getCallingUid())) {
3073 // Check READ_PHONE_STATE for API version 31+
3074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3075 featureId, "getCallStateForSubscription")) {
3076 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3077 + "targeting API level 31+.");
3078 }
3079 }
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3084 PhoneConstantConversions.convertCallState(phone.getState());
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 }
3089
Sanket Padawe356d7632015-06-22 14:03:32 -07003090 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003091 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003092 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3093 }
3094
3095 @Override
3096 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097 final long identity = Binder.clearCallingIdentity();
3098 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003099 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003100 if (phone != null) {
Jack Yuf745f972022-08-15 19:53:50 +00003101 if (phone.isUsingNewDataStack()) {
3102 return phone.getDataNetworkController().getInternetDataNetworkState();
3103 }
3104 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 } else {
3106 return PhoneConstantConversions.convertDataState(
3107 PhoneConstants.DataState.DISCONNECTED);
3108 }
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 }
3113
Sanket Padawe356d7632015-06-22 14:03:32 -07003114 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003115 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003116 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3117 }
3118
3119 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003120 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121 final long identity = Binder.clearCallingIdentity();
3122 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003123 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003125 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126 } else {
3127 return TelephonyManager.DATA_ACTIVITY_NONE;
3128 }
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
3134 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003135 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003136 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003137 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003138
3139 LocationAccessPolicy.LocationPermissionResult locationResult =
3140 LocationAccessPolicy.checkLocationPermission(mApp,
3141 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3142 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003143 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003144 .setCallingPid(Binder.getCallingPid())
3145 .setCallingUid(Binder.getCallingUid())
3146 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003147 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003148 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3149 .build());
3150 switch (locationResult) {
3151 case DENIED_HARD:
3152 throw new SecurityException("Not allowed to access cell location");
3153 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003154 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3155 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003158 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003162 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003163 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 } finally {
3165 Binder.restoreCallingIdentity(identity);
3166 }
Svetoslav64fad262015-04-14 14:35:21 -07003167 }
3168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003170 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003171 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3172 // registered cell info, so return a NULL country instead.
3173 final long identity = Binder.clearCallingIdentity();
3174 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003175 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3176 // Get default phone in this case.
3177 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3178 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003179 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003181 if (phone == null) return "";
3182 ServiceStateTracker sst = phone.getServiceStateTracker();
3183 if (sst == null) return "";
3184 LocaleTracker lt = sst.getLocaleTracker();
3185 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003186 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003190 }
3191
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003192 /**
3193 * This method was removed due to potential issues caused by performing partial
3194 * updates of service state, and lack of a credible use case.
3195 *
3196 * This has the ability to break the telephony implementation by disabling notification of
3197 * changes in device connectivity. DO NOT USE THIS!
3198 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003199 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 public void enableLocationUpdates() {
3201 mApp.enforceCallingOrSelfPermission(
3202 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003205 /**
3206 * This method was removed due to potential issues caused by performing partial
3207 * updates of service state, and lack of a credible use case.
3208 *
3209 * This has the ability to break the telephony implementation by disabling notification of
3210 * changes in device connectivity. DO NOT USE THIS!
3211 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 @Override
3213 public void disableLocationUpdates() {
3214 mApp.enforceCallingOrSelfPermission(
3215 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 }
3217
3218 @Override
3219 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003220 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3221 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003222 try {
3223 mApp.getSystemService(AppOpsManager.class)
3224 .checkPackage(Binder.getCallingUid(), callingPackage);
3225 } catch (SecurityException e) {
3226 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3227 throw e;
3228 }
3229
Nathan Haroldf096d982020-11-18 17:18:06 -08003230 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003231 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3232 throw new SecurityException(
3233 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3234 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003235
Jordan Liu1617b712019-07-10 15:06:26 -07003236 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3238 return null;
3239 }
Svetoslav64fad262015-04-14 14:35:21 -07003240
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003241 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003242
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003243 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003244 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245
Nathan Haroldf180aac2018-06-01 18:43:55 -07003246 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3247 for (CellInfo ci : info) {
3248 if (ci instanceof CellInfoGsm) {
3249 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3250 } else if (ci instanceof CellInfoWcdma) {
3251 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003254 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003255 }
3256
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003257 private List<CellInfo> getCachedCellInfo() {
3258 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3259 for (Phone phone : PhoneFactory.getPhones()) {
3260 List<CellInfo> info = phone.getAllCellInfo();
3261 if (info != null) cellInfos.addAll(info);
3262 }
3263 return cellInfos;
3264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265
3266 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003267 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003268 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003269 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003270
3271 LocationAccessPolicy.LocationPermissionResult locationResult =
3272 LocationAccessPolicy.checkLocationPermission(mApp,
3273 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3274 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003275 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003276 .setCallingPid(Binder.getCallingPid())
3277 .setCallingUid(Binder.getCallingUid())
3278 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003279 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003280 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3281 .build());
3282 switch (locationResult) {
3283 case DENIED_HARD:
3284 throw new SecurityException("Not allowed to access cell info");
3285 case DENIED_SOFT:
3286 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287 }
3288
Nathan Haroldf096d982020-11-18 17:18:06 -08003289 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003290 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3291 return getCachedCellInfo();
3292 }
3293
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003294 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003295 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3299 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003300 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003301 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003302 if (info != null) cellInfos.addAll(info);
3303 }
3304 return cellInfos;
3305 } finally {
3306 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 }
3308 }
3309
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003310 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003311 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3312 String callingFeatureId) {
3313 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3314 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003315 }
3316
3317 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003318 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3319 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003320 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003321 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003322 }
3323
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003324 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3325 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003326 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003327 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003328
3329 LocationAccessPolicy.LocationPermissionResult locationResult =
3330 LocationAccessPolicy.checkLocationPermission(mApp,
3331 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3332 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003333 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003334 .setCallingPid(Binder.getCallingPid())
3335 .setCallingUid(Binder.getCallingUid())
3336 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003337 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3338 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003339 .build());
3340 switch (locationResult) {
3341 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003342 if (TelephonyPermissions
3343 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003344 // Safetynet logging for b/154934934
3345 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3346 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003347 throw new SecurityException("Not allowed to access cell info");
3348 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003349 if (TelephonyPermissions
3350 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003351 // Safetynet logging for b/154934934
3352 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3353 }
Nathan Harold5320c422019-05-09 10:26:08 -07003354 try {
3355 cb.onCellInfo(new ArrayList<CellInfo>());
3356 } catch (RemoteException re) {
3357 // Drop without consequences
3358 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003359 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003360 }
3361
Nathan Harolda939a962019-05-09 10:13:47 -07003362
3363 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003364 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3365
3366 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3367 }
3368
3369 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003370 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003371 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003372 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003376 Phone phone = getPhone(subId);
3377 if (phone == null) {
3378 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3379 } else {
3380 phone.setCellInfoListRate(rateInMillis, workSource);
3381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003385 }
3386
Shishir Agrawala9f32182016-04-12 12:00:16 -07003387 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003388 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003389 Phone phone = PhoneFactory.getPhone(slotIndex);
3390 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003391 return null;
3392 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003393 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003394 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003395 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003396 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003397 return null;
3398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399
3400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 return phone.getImei();
3403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003406 }
3407
3408 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003409 public String getTypeAllocationCodeForSlot(int slotIndex) {
3410 Phone phone = PhoneFactory.getPhone(slotIndex);
3411 String tac = null;
3412 if (phone != null) {
3413 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003414 try {
3415 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3416 } catch (IndexOutOfBoundsException e) {
3417 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3418 return null;
3419 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003420 }
3421 return tac;
3422 }
3423
3424 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003425 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003426 try {
3427 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3428 } catch (SecurityException se) {
3429 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3430 throw new SecurityException("Package " + callingPackage + " does not belong to "
3431 + Binder.getCallingUid());
3432 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003433 Phone phone = PhoneFactory.getPhone(slotIndex);
3434 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003435 return null;
3436 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003437
Jeff Davidson913390f2018-02-23 17:11:49 -08003438 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003439 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003440 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003441 return null;
3442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 return phone.getMeid();
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
Jack Yu2af8d712017-03-15 17:14:14 -07003450 }
3451
3452 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003453 public String getManufacturerCodeForSlot(int slotIndex) {
3454 Phone phone = PhoneFactory.getPhone(slotIndex);
3455 String manufacturerCode = null;
3456 if (phone != null) {
3457 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003458 try {
3459 manufacturerCode =
3460 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3461 } catch (IndexOutOfBoundsException e) {
3462 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3463 return null;
3464 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003465 }
3466 return manufacturerCode;
3467 }
3468
3469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003470 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3471 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003472 Phone phone = PhoneFactory.getPhone(slotIndex);
3473 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003474 return null;
3475 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003476 int subId = phone.getSubId();
3477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003478 mApp, subId, callingPackage, callingFeatureId,
3479 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003480 return null;
3481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 return phone.getDeviceSvn();
3486 } finally {
3487 Binder.restoreCallingIdentity(identity);
3488 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003489 }
3490
fionaxu43304da2017-11-27 22:51:16 -08003491 @Override
3492 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 final Phone phone = getPhone(subId);
3496 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
fionaxu43304da2017-11-27 22:51:16 -08003500 }
3501
3502 @Override
3503 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 final Phone phone = getPhone(subId);
3507 return phone == null ? null : phone.getCarrierName();
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
fionaxu43304da2017-11-27 22:51:16 -08003511 }
3512
calvinpanffe225e2018-11-01 19:43:06 +08003513 @Override
chen xu0026ca62019-03-06 15:28:50 -08003514 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 final Phone phone = getPhone(subId);
3518 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003519 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003520 } finally {
3521 Binder.restoreCallingIdentity(identity);
3522 }
3523 }
3524
3525 @Override
chen xu0026ca62019-03-06 15:28:50 -08003526 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003530 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
3534 }
3535
chen xu651eec72018-11-11 19:03:44 -08003536 @Override
chen xu864e11c2018-12-06 22:10:03 -08003537 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3538 if (!isSubscriptionMccMnc) {
3539 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3540 }
chen xu651eec72018-11-11 19:03:44 -08003541 final Phone phone = PhoneFactory.getPhone(slotIndex);
3542 if (phone == null) {
3543 return TelephonyManager.UNKNOWN_CARRIER_ID;
3544 }
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
3551 }
3552
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003553 //
3554 // Internal helper methods.
3555 //
3556
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003557 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003558 * Make sure the caller is the calling package itself
3559 *
3560 * @throws SecurityException if the caller is not the calling package
3561 */
3562 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3563 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003564 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3565 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003566 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003567 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003568 } catch (PackageManager.NameNotFoundException e) {
3569 // packageUid is -1
3570 }
3571 if (packageUid != callingUid) {
3572 throw new SecurityException(message + ": Package " + callingPackage
3573 + " does not belong to " + callingUid);
3574 }
3575 }
3576
3577 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003578 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3579 *
3580 * @throws SecurityException if the caller does not have the required permission
3581 */
3582 private void enforceModifyPermission() {
3583 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3584 }
3585
Shuo Qian3b6ee772019-11-13 17:43:31 -08003586 private void enforceActiveEmergencySessionPermission() {
3587 mApp.enforceCallingOrSelfPermission(
3588 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3589 }
3590
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003591 /**
3592 * Make sure the caller has the CALL_PHONE permission.
3593 *
3594 * @throws SecurityException if the caller does not have the required permission
3595 */
3596 private void enforceCallPermission() {
3597 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3598 }
3599
paulhu5a773602019-08-23 19:17:33 +08003600 private void enforceSettingsPermission() {
3601 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003602 }
3603
Michele Berionne5e411512020-11-13 02:36:59 +00003604 private void enforceRebootPermission() {
3605 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3606 }
3607
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003608 private String createTelUrl(String number) {
3609 if (TextUtils.isEmpty(number)) {
3610 return null;
3611 }
3612
Jake Hambye994d462014-02-03 13:10:13 -08003613 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003614 }
3615
Ihab Awadf9e92732013-12-05 18:02:52 -08003616 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003617 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3618 }
3619
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003620 private static void logv(String msg) {
3621 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3622 }
3623
Ihab Awadf9e92732013-12-05 18:02:52 -08003624 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003625 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3626 }
3627
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003628 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003629 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003630 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003631 }
3632
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003634 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 final Phone phone = PhoneFactory.getPhone(slotIndex);
3638 if (phone == null) {
3639 return PhoneConstants.PHONE_TYPE_NONE;
3640 } else {
3641 return phone.getPhoneType();
3642 }
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 }
3647
3648 /**
3649 * Returns the CDMA ERI icon index to display
3650 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003651 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003652 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3653 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3654 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003655 }
3656
Sanket Padawe356d7632015-06-22 14:03:32 -07003657 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003658 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3659 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003661 mApp, subId, callingPackage, callingFeatureId,
3662 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003663 return -1;
3664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 final Phone phone = getPhone(subId);
3669 if (phone != null) {
3670 return phone.getCdmaEriIconIndex();
3671 } else {
3672 return -1;
3673 }
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003677 }
3678
3679 /**
3680 * Returns the CDMA ERI icon mode,
3681 * 0 - ON
3682 * 1 - FLASHING
3683 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003685 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3686 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3687 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003688 }
3689
Sanket Padawe356d7632015-06-22 14:03:32 -07003690 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003691 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3692 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003694 mApp, subId, callingPackage, callingFeatureId,
3695 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003696 return -1;
3697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698
3699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 final Phone phone = getPhone(subId);
3702 if (phone != null) {
3703 return phone.getCdmaEriIconMode();
3704 } else {
3705 return -1;
3706 }
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003710 }
3711
3712 /**
3713 * Returns the CDMA ERI text,
3714 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003716 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3717 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3718 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003719 }
3720
Sanket Padawe356d7632015-06-22 14:03:32 -07003721 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003722 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3723 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003725 mApp, subId, callingPackage, callingFeatureId,
3726 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003727 return null;
3728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 final Phone phone = getPhone(subId);
3733 if (phone != null) {
3734 return phone.getCdmaEriText();
3735 } else {
3736 return null;
3737 }
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003741 }
3742
3743 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003744 * Returns the CDMA MDN.
3745 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003746 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003747 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3749 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 return phone.getLine1Number();
3756 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 return null;
3759 }
3760 } finally {
3761 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003762 }
3763 }
3764
3765 /**
3766 * Returns the CDMA MIN.
3767 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003768 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003769 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3771 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
3773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 final Phone phone = getPhone(subId);
3776 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3777 return phone.getCdmaMin();
3778 } else {
3779 return null;
3780 }
3781 } finally {
3782 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003783 }
3784 }
3785
Hall Liud892bec2018-11-30 14:51:45 -08003786 @Override
3787 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3788 INumberVerificationCallback callback, String callingPackage) {
3789 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3790 != PERMISSION_GRANTED) {
3791 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3792 }
3793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3794
3795 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3796 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003797 throw new SecurityException("Calling package must be configured in the device config: "
3798 + "calling package: " + callingPackage
3799 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003800 }
3801
3802 if (range == null) {
3803 throw new NullPointerException("Range must be non-null");
3804 }
3805
3806 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003807 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003808
3809 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3810 }
3811
Junda Liuca05d5d2014-08-14 22:36:34 -07003812 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003813 * Returns true if CDMA provisioning needs to run.
3814 */
3815 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 final long identity = Binder.clearCallingIdentity();
3817 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003818 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819 } finally {
3820 Binder.restoreCallingIdentity(identity);
3821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003822 }
3823
3824 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003825 * Sets the voice mail number of a given subId.
3826 */
3827 @Override
3828 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003829 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3830 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831
3832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3835 new Pair<String, String>(alphaTag, number), new Integer(subId));
3836 return success;
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
3839 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003840 }
3841
Ta-wei Yen87c49842016-05-13 21:19:52 -07003842 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003843 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3844 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003845 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3846 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003847 if (!TextUtils.equals(callingPackage, systemDialer)) {
3848 throw new SecurityException("caller must be system dialer");
3849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850
3851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3854 if (phoneAccountHandle == null) {
3855 return null;
3856 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003857 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003858 } finally {
3859 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003860 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003861 }
3862
3863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003864 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3865 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003866 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003867 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003868 mApp, subId, callingPackage, callingFeatureId,
3869 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003870 return null;
3871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003873 final long identity = Binder.clearCallingIdentity();
3874 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003875 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003879 }
3880
3881 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003882 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3883 VisualVoicemailSmsFilterSettings settings) {
3884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885
3886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003889 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 } finally {
3891 Binder.restoreCallingIdentity(identity);
3892 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003893 }
3894
3895 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003896 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3897 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003902 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003906 }
3907
3908 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003909 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3910 String callingPackage, int subId) {
3911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912
3913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003916 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003920 }
3921
3922 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003923 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003924 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925
3926 final long identity = Binder.clearCallingIdentity();
3927 try {
3928 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003929 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003930 } finally {
3931 Binder.restoreCallingIdentity(identity);
3932 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003933 }
3934
3935 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003936 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3937 String callingAttributionTag, int subId, String number, int port, String text,
3938 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003939 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003940 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003941 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003942 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003943 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3944 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003945 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003946
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003947 /**
fionaxu0152e512016-11-14 13:36:14 -08003948 * Sets the voice activation state of a given subId.
3949 */
3950 @Override
3951 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3953 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 final Phone phone = getPhone(subId);
3958 if (phone != null) {
3959 phone.setVoiceActivationState(activationState);
3960 } else {
3961 loge("setVoiceActivationState fails with invalid subId: " + subId);
3962 }
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003965 }
3966 }
3967
3968 /**
3969 * Sets the data activation state of a given subId.
3970 */
3971 @Override
3972 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3974 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975
3976 final long identity = Binder.clearCallingIdentity();
3977 try {
3978 final Phone phone = getPhone(subId);
3979 if (phone != null) {
3980 phone.setDataActivationState(activationState);
3981 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003982 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983 }
3984 } finally {
3985 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003986 }
3987 }
3988
3989 /**
3990 * Returns the voice activation state of a given subId.
3991 */
3992 @Override
3993 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995
fionaxu0152e512016-11-14 13:36:14 -08003996 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 if (phone != null) {
4000 return phone.getVoiceActivationState();
4001 } else {
4002 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4003 }
4004 } finally {
4005 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004006 }
4007 }
4008
4009 /**
4010 * Returns the data activation state of a given subId.
4011 */
4012 @Override
4013 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015
fionaxu0152e512016-11-14 13:36:14 -08004016 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 if (phone != null) {
4020 return phone.getDataActivationState();
4021 } else {
4022 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4023 }
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004026 }
4027 }
4028
4029 /**
Wink Saville36469e72014-06-11 15:17:00 -07004030 * Returns the unread count of voicemails for a subId
4031 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004032 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004033 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4034 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004036 mApp, subId, callingPackage, callingFeatureId,
4037 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004038 return 0;
4039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 final Phone phone = getPhone(subId);
4043 if (phone != null) {
4044 return phone.getVoiceMessageCount();
4045 } else {
4046 return 0;
4047 }
4048 } finally {
4049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004051 }
4052
4053 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004054 * returns true, if the device is in a state where both voice and data
4055 * are supported simultaneously. This can change based on location or network condition.
4056 */
4057 @Override
4058 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 final Phone phone = getPhone(subId);
4062 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4063 } finally {
4064 Binder.restoreCallingIdentity(identity);
4065 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004066 }
4067
4068 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004069 * Send the dialer code if called from the current default dialer or the caller has
4070 * carrier privilege.
4071 * @param inputCode The dialer code to send
4072 */
4073 @Override
4074 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004075 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004076 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004077 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4078 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004079 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004080 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004081 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004086 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
fionaxu235cc5e2017-03-06 22:25:57 -08004090 }
4091
Pengquan Menga1bb6272018-09-06 09:59:22 -07004092 @Override
4093 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004094 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004095 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004096 mApp, subId, "getNetworkSelectionMode");
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 if (!isActiveSubscription(subId)) {
4100 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4101 }
4102 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004105 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004106 }
4107
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004109 public boolean isInEmergencySmsMode() {
4110 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 for (Phone phone : PhoneFactory.getPhones()) {
4114 if (phone.isInEmergencySmsMode()) {
4115 return true;
4116 }
4117 }
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
4121 return false;
4122 }
4123
shilu366312e2019-12-17 09:28:10 -08004124 /**
4125 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4126 * @param subId The subscription to use to check the configuration.
4127 * @param c The callback that will be used to send the result.
4128 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004129 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004130 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4131 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004132 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004133 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004134
4135 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4136 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4137 "IMS not available on device.");
4138 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 final long token = Binder.clearCallingIdentity();
4140 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004141 int slotId = getSlotIndexOrException(subId);
4142 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004143
4144 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4145 if (controller != null) {
4146 ImsManager imsManager = controller.getImsManager(subId);
4147 if (imsManager != null) {
4148 imsManager.addRegistrationCallbackForSubscription(c, subId);
4149 } else {
4150 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4151 }
4152 } else {
4153 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4154 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004155 } catch (ImsException e) {
4156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 } finally {
4158 Binder.restoreCallingIdentity(token);
4159 }
4160 }
4161
shilu366312e2019-12-17 09:28:10 -08004162 /**
4163 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4164 * @param subId The subscription to use to check the configuration.
4165 * @param c The callback that will be used to send the result.
4166 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004168 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004169 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004170 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004171 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4172 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4173 }
Meng Wangafbc5852019-09-19 17:37:13 -07004174 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004175
Meng Wangafbc5852019-09-19 17:37:13 -07004176 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004177 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4178 if (controller != null) {
4179 ImsManager imsManager = controller.getImsManager(subId);
4180 if (imsManager != null) {
4181 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4182 } else {
4183 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4184 + "is inactive, ignoring unregister.");
4185 // If the ImsManager is not valid, just return, since the callback
4186 // will already have been removed internally.
4187 }
4188 }
Meng Wangafbc5852019-09-19 17:37:13 -07004189 } finally {
4190 Binder.restoreCallingIdentity(token);
4191 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 }
4193
Brad Ebingera34a6c22019-10-22 17:36:18 -07004194 /**
4195 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4196 */
4197 @Override
4198 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4199 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4200 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4201 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4202 "IMS not available on device.");
4203 }
4204 final long token = Binder.clearCallingIdentity();
4205 try {
4206 Phone phone = getPhone(subId);
4207 if (phone == null) {
4208 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4209 + subId + "'");
4210 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4211 }
4212 phone.getImsRegistrationState(regState -> {
4213 try {
4214 consumer.accept((regState == null)
4215 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4216 } catch (RemoteException e) {
4217 // Ignore if the remote process is no longer available to call back.
4218 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4219 }
4220 });
4221 } finally {
4222 Binder.restoreCallingIdentity(token);
4223 }
4224 }
4225
4226 /**
4227 * Get the transport type for the IMS service registration state.
4228 */
4229 @Override
4230 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004231 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004232 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004233 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4234 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4235 "IMS not available on device.");
4236 }
4237 final long token = Binder.clearCallingIdentity();
4238 try {
4239 Phone phone = getPhone(subId);
4240 if (phone == null) {
4241 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4242 + subId + "'");
4243 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4244 }
4245 phone.getImsRegistrationTech(regTech -> {
4246 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4247 int regTechConverted = (regTech == null)
4248 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4249 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4250 regTechConverted);
4251 try {
4252 consumer.accept(regTechConverted);
4253 } catch (RemoteException e) {
4254 // Ignore if the remote process is no longer available to call back.
4255 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4256 }
4257 });
4258 } finally {
4259 Binder.restoreCallingIdentity(token);
4260 }
4261 }
4262
shilu366312e2019-12-17 09:28:10 -08004263 /**
4264 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4265 * @param subId The subscription to use to check the configuration.
4266 * @param c The callback that will be used to send the result.
4267 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004269 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4270 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004271 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004272 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004273 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4274 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4275 "IMS not available on device.");
4276 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 final long token = Binder.clearCallingIdentity();
4278 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004279 int slotId = getSlotIndexOrException(subId);
4280 verifyImsMmTelConfiguredOrThrow(slotId);
4281 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004282 } catch (ImsException e) {
4283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 } finally {
4285 Binder.restoreCallingIdentity(token);
4286 }
4287 }
4288
shilu366312e2019-12-17 09:28:10 -08004289 /**
4290 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4291 * @param subId The subscription to use to check the configuration.
4292 * @param c The callback that will be used to send the result.
4293 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004295 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004296 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004297 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004298 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4299 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4300 }
Meng Wangafbc5852019-09-19 17:37:13 -07004301
4302 final long token = Binder.clearCallingIdentity();
4303 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004304 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004305 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004306 } catch (ImsException e) {
4307 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4308 + "is inactive, ignoring unregister.");
4309 // If the subscription is no longer active, just return, since the callback
4310 // will already have been removed internally.
4311 } finally {
4312 Binder.restoreCallingIdentity(token);
4313 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 }
4315
4316 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004317 public boolean isCapable(int subId, int capability, int regTech) {
4318 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 final long token = Binder.clearCallingIdentity();
4320 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004321 int slotId = getSlotIndexOrException(subId);
4322 verifyImsMmTelConfiguredOrThrow(slotId);
4323 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4324 } catch (com.android.ims.ImsException e) {
4325 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4326 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004327 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004328 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4329 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 } finally {
4331 Binder.restoreCallingIdentity(token);
4332 }
4333 }
4334
4335 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004336 public boolean isAvailable(int subId, int capability, int regTech) {
4337 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 final long token = Binder.clearCallingIdentity();
4339 try {
4340 Phone phone = getPhone(subId);
4341 if (phone == null) return false;
4342 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004343 } catch (com.android.ims.ImsException e) {
4344 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4345 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 } finally {
4347 Binder.restoreCallingIdentity(token);
4348 }
4349 }
4350
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004351 /**
4352 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4353 * subscription.
4354 * @param subId The subscription to use to check the configuration.
4355 * @param callback The callback that will be used to send the result.
4356 * @param capability The MmTelFeature capability that will be used to send the result.
4357 * @param transportType The transport type of the MmTelFeature capability.
4358 */
4359 @Override
4360 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4361 int transportType) {
4362 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004363 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4364 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4365 "IMS not available on device.");
4366 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004367 final long token = Binder.clearCallingIdentity();
4368 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004369 int slotId = getSlotIndex(subId);
4370 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4371 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4372 + subId + "'");
4373 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4374 }
4375 verifyImsMmTelConfiguredOrThrow(slotId);
4376 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4377 transportType, aBoolean -> {
4378 try {
4379 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4380 } catch (RemoteException e) {
4381 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4382 + "running. Ignore");
4383 }
4384 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004385 } catch (ImsException e) {
4386 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004387 } finally {
4388 Binder.restoreCallingIdentity(token);
4389 }
4390 }
4391
shilu366312e2019-12-17 09:28:10 -08004392 /**
4393 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4394 * @param subId The subscription to use to check the configuration.
4395 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 @Override
4397 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004398 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004399 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004400
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 final long token = Binder.clearCallingIdentity();
4402 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004403 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004404 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004405 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004406 } catch (ImsException e) {
4407 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004408 } finally {
4409 Binder.restoreCallingIdentity(token);
4410 }
4411 }
4412
4413 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004414 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004416 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 final long identity = Binder.clearCallingIdentity();
4418 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004420 // This setting doesn't require an active ImsService connection, so do not verify. The
4421 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004422 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004423 } catch (ImsException e) {
4424 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
4428 }
4429
shilu366312e2019-12-17 09:28:10 -08004430 /**
4431 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4432 * @param subId The subscription to use to check the configuration.
4433 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004435 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004436 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004437 mApp, subId, "isVtSettingEnabled");
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).isVtEnabledByUser();
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 setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004453 "setVtSettingEnabled");
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).setVtSetting(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
shilu366312e2019-12-17 09:28:10 -08004467 /**
4468 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4469 * @param subId The subscription to use to check the configuration.
4470 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 @Override
4472 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004473 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004474 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 final long identity = Binder.clearCallingIdentity();
4476 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004478 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004479 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004480 } catch (ImsException e) {
4481 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485 }
4486
4487 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004488 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004490 "setVoWiFiSettingEnabled");
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. The
4495 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004497 } catch (ImsException e) {
4498 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
4502 }
4503
shilu366312e2019-12-17 09:28:10 -08004504 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004505 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4506 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4507 * @param subId The subscription to use to check the configuration.
4508 */
4509 @Override
4510 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004511 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004512 mApp, subId, "isCrossSimCallingEnabledByUser");
4513 final long identity = Binder.clearCallingIdentity();
4514 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004516 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004517 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004518 } catch (ImsException e) {
4519 throw new ServiceSpecificException(e.getCode());
4520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
4523 }
4524
4525 /**
4526 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4527 * Requires MODIFY_PHONE_STATE permission.
4528 * @param subId The subscription to use to check the configuration.
4529 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4530 * false otherwise
4531 */
4532 @Override
4533 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4535 "setCrossSimCallingEnabled");
4536 final long identity = Binder.clearCallingIdentity();
4537 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004539 // This setting doesn't require an active ImsService connection, so do not verify. The
4540 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004542 } catch (ImsException e) {
4543 throw new ServiceSpecificException(e.getCode());
4544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
4549 /**
shilu366312e2019-12-17 09:28:10 -08004550 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4551 * @param subId The subscription to use to check the configuration.
4552 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004553 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004554
Brad Ebinger35c841c2018-10-01 10:40:55 -07004555 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004556 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004557 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004558 final long identity = Binder.clearCallingIdentity();
4559 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004560 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004561 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004562 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004563 } catch (ImsException e) {
4564 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
4568 }
4569
4570 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004571 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004573 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004574 final long identity = Binder.clearCallingIdentity();
4575 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004576 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004577 // This setting doesn't require an active ImsService connection, so do not verify. The
4578 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004580 } catch (ImsException e) {
4581 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
4585 }
4586
4587 @Override
4588 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4590 "setVoWiFiNonPersistent");
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004593 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004594 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004595 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004596 } catch (ImsException e) {
4597 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
4601 }
4602
shilu366312e2019-12-17 09:28:10 -08004603 /**
4604 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4605 * @param subId The subscription to use to check the configuration.
4606 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004607 @Override
4608 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004609 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004610 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 final long identity = Binder.clearCallingIdentity();
4612 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004613 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004614 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004615 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004616 } catch (ImsException e) {
4617 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
4621 }
4622
4623 @Override
4624 public void setVoWiFiModeSetting(int subId, int mode) {
4625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4626 "setVoWiFiModeSetting");
4627 final long identity = Binder.clearCallingIdentity();
4628 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004629 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004630 // This setting doesn't require an active ImsService connection, so do not verify. The
4631 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004632 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004633 } catch (ImsException e) {
4634 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
4640 @Override
4641 public int getVoWiFiRoamingModeSetting(int subId) {
4642 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4643 final long identity = Binder.clearCallingIdentity();
4644 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004645 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004646 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004647 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004648 } catch (ImsException e) {
4649 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
4653 }
4654
4655 @Override
4656 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4658 "setVoWiFiRoamingModeSetting");
4659 final long identity = Binder.clearCallingIdentity();
4660 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004661 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004662 // This setting doesn't require an active ImsService connection, so do not verify. The
4663 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004664 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004665 } catch (ImsException e) {
4666 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
4670 }
4671
4672 @Override
4673 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4675 "setRttCapabilityEnabled");
4676 final long identity = Binder.clearCallingIdentity();
4677 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004678 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004679 // This setting doesn't require an active ImsService connection, so do not verify. The
4680 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004681 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004682 } catch (ImsException e) {
4683 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004684 } finally {
4685 Binder.restoreCallingIdentity(identity);
4686 }
4687 }
4688
shilu366312e2019-12-17 09:28:10 -08004689 /**
4690 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4691 * @param subId The subscription to use to check the configuration.
4692 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004693 @Override
4694 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004695 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004696 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004697 final long identity = Binder.clearCallingIdentity();
4698 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004699 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004700 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004701 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004702 } catch (ImsException e) {
4703 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004704 } finally {
4705 Binder.restoreCallingIdentity(identity);
4706 }
4707 }
4708
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004709 @Override
4710 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4711 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004712
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004713 final long identity = Binder.clearCallingIdentity();
4714 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004715 if (!isImsAvailableOnDevice()) {
4716 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4717 "IMS not available on device.");
4718 }
4719 int slotId = getSlotIndexOrException(subId);
4720 verifyImsMmTelConfiguredOrThrow(slotId);
4721 ImsManager.getInstance(mApp, slotId)
4722 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004723 } catch (ImsException e) {
4724 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
4730 @Override
4731 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4732 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004733
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004734 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004735 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4736 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4737 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004738 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004740 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004741 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004742 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4743 + "is inactive, ignoring unregister.");
4744 // If the subscription is no longer active, just return, since the callback will already
4745 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
4749 }
4750
joonhunshincffb7fc2021-11-28 07:32:01 +00004751 @Override
4752 public void registerFeatureProvisioningChangedCallback(int subId,
4753 IFeatureProvisioningCallback callback) {
4754 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4755 mApp, subId, "registerFeatureProvisioningChangedCallback");
4756
4757 final long identity = Binder.clearCallingIdentity();
4758 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4759 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4760 }
4761
joonhunshin91bc1952022-04-29 08:47:15 +00004762 try {
4763 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4764 if (controller == null) {
4765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4766 "Device does not support IMS");
4767 }
4768 controller.addFeatureProvisioningChangedCallback(subId, callback);
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004772 }
4773
4774 @Override
4775 public void unregisterFeatureProvisioningChangedCallback(int subId,
4776 IFeatureProvisioningCallback callback) {
4777 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4778 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4779
4780 final long identity = Binder.clearCallingIdentity();
4781 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4782 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4783 }
4784
joonhunshin91bc1952022-04-29 08:47:15 +00004785 try {
4786 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4787 if (controller == null) {
4788 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4789 return;
4790 }
4791 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
4794 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004795 }
allenwtsu99c623b2020-01-03 18:24:23 +08004796
4797 private void checkModifyPhoneStatePermission(int subId, String message) {
4798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4799 message);
4800 }
4801
allenwtsu99c623b2020-01-03 18:24:23 +08004802 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004803 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004804 boolean isProvisioned) {
4805 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4806
4807 final long identity = Binder.clearCallingIdentity();
4808 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004809 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4810 if (controller == null) {
4811 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4812 return;
4813 }
4814 controller.setRcsProvisioningStatusForCapability(
4815 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
allenwtsu99c623b2020-01-03 18:24:23 +08004819 }
4820
4821
4822 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004823 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4824 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4825 mApp, subId, "getRcsProvisioningStatusForCapability");
4826
allenwtsu99c623b2020-01-03 18:24:23 +08004827 final long identity = Binder.clearCallingIdentity();
4828 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004829 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4830 if (controller == null) {
4831 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4832
4833 // device does not support IMS, this method will return true always.
4834 return true;
4835 }
4836 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
4840 }
4841
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004842 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004843 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4844 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004845 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004846
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004847 final long identity = Binder.clearCallingIdentity();
4848 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004849 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4850 if (controller == null) {
4851 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4852 return;
4853 }
4854 controller.setImsProvisioningStatusForCapability(
4855 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
4859 }
4860
4861 @Override
4862 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004863 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4864 mApp, subId, "getProvisioningStatusForCapability");
4865
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004866 final long identity = Binder.clearCallingIdentity();
4867 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004868 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4869 if (controller == null) {
4870 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004871
joonhunshin91bc1952022-04-29 08:47:15 +00004872 // device does not support IMS, this method will return true always.
4873 return true;
4874 }
4875 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
4879 }
4880
4881 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004882 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4883 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4884 mApp, subId, "isProvisioningRequiredForCapability");
4885
4886 final long identity = Binder.clearCallingIdentity();
4887 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004888 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4889 if (controller == null) {
4890 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4891
4892 // device does not support IMS, this method will return false
4893 return false;
4894 }
4895 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004898 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 }
4900
4901 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004902 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4903 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4904 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905
joonhunshincffb7fc2021-11-28 07:32:01 +00004906 final long identity = Binder.clearCallingIdentity();
4907 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004908 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4909 if (controller == null) {
4910 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4911
4912 // device does not support IMS, this method will return false
4913 return false;
4914 }
4915 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 }
4920
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4924 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4925 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004926 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4927 mApp, subId, "getImsProvisioningInt");
4928
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004929 final long identity = Binder.clearCallingIdentity();
4930 try {
4931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 int slotId = getSlotIndex(subId);
4933 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4934 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4935 + subId + "' for key:" + key);
4936 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4937 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004938
joonhunshin91bc1952022-04-29 08:47:15 +00004939 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4940 if (controller == null) {
4941 loge("getImsProvisioningInt: Device does not support IMS");
4942
4943 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4944 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4945 }
4946 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004947 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4948 return retVal;
4949 }
4950
calvinpanb5a34062021-02-08 19:59:36 +08004951 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004952 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4954 + subId + "' for key:" + key);
4955 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
4959 }
4960
4961 @Override
4962 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004963 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4964 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4965 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004966 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4967 mApp, subId, "getImsProvisioningString");
4968
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 int slotId = getSlotIndex(subId);
4973 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4974 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4975 + subId + "' for key:" + key);
4976 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4977 }
calvinpanb5a34062021-02-08 19:59:36 +08004978 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004979 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4981 + subId + "' for key:" + key);
4982 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
4986 }
4987
4988 @Override
4989 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004990 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4991 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4992 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4994 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004995
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004996 final long identity = Binder.clearCallingIdentity();
4997 try {
4998 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004999 int slotId = getSlotIndex(subId);
5000 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5001 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5002 + subId + "' for key:" + key);
5003 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5004 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005005
joonhunshin91bc1952022-04-29 08:47:15 +00005006 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5007 if (controller == null) {
5008 loge("setImsProvisioningInt: Device does not support IMS");
5009
5010 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5011 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5012 }
5013 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005014 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5015 return retVal;
5016 }
5017
calvinpanb5a34062021-02-08 19:59:36 +08005018 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5019 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005020 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005021 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005022 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
5026 }
5027
5028 @Override
5029 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005030 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5031 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5032 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5034 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005038 int slotId = getSlotIndex(subId);
5039 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5040 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5041 + subId + "' for key:" + key);
5042 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5043 }
calvinpanb5a34062021-02-08 19:59:36 +08005044 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5045 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005046 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005047 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005048 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
5052 }
5053
Brad Ebinger919631e2021-06-02 17:46:35 -07005054 /**
5055 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5056 * for the given slot ID or no ImsResolver instance has been created.
5057 * @param slotId The slot ID that the IMS service is created for.
5058 * @throws ImsException If there is no ImsService configured for this slot.
5059 */
5060 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5061 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5062 ImsFeature.FEATURE_MMTEL)) {
5063 throw new ImsException("This subscription does not support MMTEL over IMS",
5064 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5065 }
5066 }
5067
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005068 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005069 int slotId = SubscriptionManager.getSlotIndex(subId);
5070 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005071 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5072 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005073 }
5074 return slotId;
5075 }
5076
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005077 private int getSlotIndex(int subId) {
5078 int slotId = SubscriptionManager.getSlotIndex(subId);
5079 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5080 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5081 }
5082 return slotId;
5083 }
5084
Wink Saville36469e72014-06-11 15:17:00 -07005085 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005086 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005087 */
5088 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005089 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5090 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005091 try {
5092 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5093 } catch (SecurityException se) {
5094 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5095 throw new SecurityException("Package " + callingPackage + " does not belong to "
5096 + Binder.getCallingUid());
5097 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005098 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005099 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005100 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005101 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005102 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005103 mApp, subId, callingPackage, callingFeatureId,
5104 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005105 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5106 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 final long identity = Binder.clearCallingIdentity();
5109 try {
5110 final Phone phone = getPhone(subId);
5111 if (phone != null) {
5112 return phone.getServiceState().getDataNetworkType();
5113 } else {
5114 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5115 }
5116 } finally {
5117 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005119 }
5120
5121 /**
5122 * Returns the data network type
5123 */
5124 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005125 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005126 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5127 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005128 }
5129
5130 /**
5131 * Returns the data network type for a subId
5132 */
5133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005134 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5135 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005136 String functionName = "getDataNetworkTypeForSubscriber";
5137 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5138 mApp, functionName)) {
5139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5140 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5141 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5142 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005143 }
5144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 final Phone phone = getPhone(subId);
5148 if (phone != null) {
5149 return phone.getServiceState().getDataNetworkType();
5150 } else {
5151 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5152 }
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005156 }
5157
5158 /**
Wink Saville36469e72014-06-11 15:17:00 -07005159 * Returns the Voice network type for a subId
5160 */
5161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005162 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5163 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005164 String functionName = "getVoiceNetworkTypeForSubscriber";
5165 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5166 mApp, functionName)) {
5167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5168 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5169 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5170 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005171 }
5172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 final long identity = Binder.clearCallingIdentity();
5174 try {
5175 final Phone phone = getPhone(subId);
5176 if (phone != null) {
5177 return phone.getServiceState().getVoiceNetworkType();
5178 } else {
5179 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5180 }
5181 } finally {
5182 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005184 }
5185
5186 /**
5187 * @return true if a ICC card is present
5188 */
5189 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005190 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005191 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5192 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005193 }
5194
5195 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005196 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005197 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005198 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005199 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 final Phone phone = PhoneFactory.getPhone(slotIndex);
5203 if (phone != null) {
5204 return phone.getIccCard().hasIccCard();
5205 } else {
5206 return false;
5207 }
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005211 }
5212
5213 /**
5214 * Return if the current radio is LTE on CDMA. This
5215 * is a tri-state return value as for a period of time
5216 * the mode may be unknown.
5217 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005218 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005219 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005220 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005221 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005222 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005223 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5224 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5225 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005226 }
5227
Sanket Padawe356d7632015-06-22 14:03:32 -07005228 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005229 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5230 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005231 try {
5232 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5233 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005234 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5235 }
5236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 final Phone phone = getPhone(subId);
5240 if (phone == null) {
5241 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5242 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005243 return TelephonyProperties.lte_on_cdma_device()
5244 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 }
5246 } finally {
5247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005248 }
Wink Saville36469e72014-06-11 15:17:00 -07005249 }
5250
Wink Saville36469e72014-06-11 15:17:00 -07005251 /**
5252 * {@hide}
5253 * Returns Default subId, 0 in the case of single standby.
5254 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005255 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005256 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005257 }
5258
Shishir Agrawala9f32182016-04-12 12:00:16 -07005259 private int getSlotForDefaultSubscription() {
5260 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5261 }
5262
Wink Savilleb564aae2014-10-23 10:18:09 -07005263 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005264 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005265 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005266
Pengquan Menge92a50d2018-09-21 15:54:48 -07005267 private boolean isActiveSubscription(int subId) {
5268 return mSubscriptionController.isActiveSubId(subId);
5269 }
5270
Ihab Awadf2177b72013-11-25 13:33:23 -08005271 /**
5272 * @see android.telephony.TelephonyManager.WifiCallingChoices
5273 */
5274 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005277 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5279 getWhenToMakeWifiCallsDefaultPreference());
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005283 }
5284
5285 /**
5286 * @see android.telephony.TelephonyManager.WifiCallingChoices
5287 */
5288 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
5291 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005292 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005297 }
5298
Sailesh Nepald1e68152013-12-12 19:08:02 -08005299 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005300 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005301 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005302 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005303
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005304 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5305 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5306 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005307 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005308 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5309 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005310 }
5311 return PhoneFactory.getPhone(phoneId);
5312 }
5313
Shishir Agrawal566b7612013-10-28 14:41:00 -07005314 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005315 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005316 @NonNull IccLogicalChannelRequest request) {
5317 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5318 /*message=*/ "iccOpenLogicalChannel");
5319
5320 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5321 // Verify that the callingPackage in the request belongs to the calling UID
5322 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5323
5324 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005325 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326
Rambo Wanga1782702021-11-10 20:15:19 -08005327 private Phone getPhoneFromValidIccLogicalChannelRequest(
5328 @NonNull IccLogicalChannelRequest request, String message) {
5329 Phone phone;
5330 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5332 mApp, request.subId, message);
5333 phone = getPhoneFromSubId(request.subId);
5334 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5335 enforceModifyPermission();
5336 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5337 } else {
5338 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005339 }
Rambo Wanga1782702021-11-10 20:15:19 -08005340 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005341 }
5342
5343 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005344 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 final long identity = Binder.clearCallingIdentity();
5346 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005347 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005349 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5350 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005351 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5352 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 loge("The calling package is not allowed to access ISD-R.");
5354 throw new SecurityException(
5355 "The calling package is not allowed to access ISD-R.");
5356 }
Derek Tan740e1672017-06-27 14:56:27 -07005357 }
Derek Tan740e1672017-06-27 14:56:27 -07005358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005360 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5361 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 return response;
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005366 }
5367
5368 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005369 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5370 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5371 /*message=*/"iccCloseLogicalChannel");
5372
5373 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5374
5375 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005376 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005377
Rambo Wanga1782702021-11-10 20:15:19 -08005378 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5379 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005380 // before this feature is enabled, this API should only return false if
5381 // the operation fails instead of throwing runtime exception for
5382 // backward-compatibility.
5383 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5384 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005387 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005388 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 }
Chen Xue9d737e2022-01-01 23:41:31 -08005390 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005391 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005392 Boolean success = false;
5393 if (result instanceof RuntimeException) {
5394 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005395 if (shouldThrowExceptionOnFailure) {
5396 throw (RuntimeException) result;
5397 } else {
5398 return false;
5399 }
Chen Xue9d737e2022-01-01 23:41:31 -08005400 } else if (result instanceof Boolean) {
5401 success = (Boolean) result;
5402 } else {
5403 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5404 }
Rambo Wanga1782702021-11-10 20:15:19 -08005405 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 return success;
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005409 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005410 }
5411
5412 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005413 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005414 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5416 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005417 if (DBG) {
5418 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5419 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5420 + p3 + " data=" + data);
5421 }
5422 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5423 command, p1, p2, p3, data);
5424 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005425
Jordan Liu4c733742019-02-28 12:03:40 -08005426 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005427 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5428 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005429 enforceModifyPermission();
5430 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005431 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5432 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5433 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005434 }
5435 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005436 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5437 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005438 }
5439
5440 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5441 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 final long identity = Binder.clearCallingIdentity();
5443 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005444 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 return "";
5446 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005449 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5450 null /* workSource */);
5451 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 // Append the returned status code to the end of the response payload.
5454 String s = Integer.toHexString(
5455 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5456 if (response.payload != null) {
5457 s = IccUtils.bytesToHexString(response.payload) + s;
5458 }
5459 return s;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005462 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005463 }
Jake Hambye994d462014-02-03 13:10:13 -08005464
Evan Charltonc66da362014-05-16 14:06:40 -07005465 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005466 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5467 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5469 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005471 if (DBG) {
5472 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5473 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5474 }
5475 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5476 cla, command, p1, p2, p3, data);
5477 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005478
Jordan Liu4c733742019-02-28 12:03:40 -08005479 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005480 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5481 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005482 enforceModifyPermission();
5483 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5484 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005485 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5486 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5487 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005488 }
5489
5490 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005491 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5492 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005493 }
5494
5495 // open APDU basic channel assuming the caller has sufficient permissions
5496 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5497 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498 final long identity = Binder.clearCallingIdentity();
5499 try {
5500 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5501 && TextUtils.equals(ISDR_AID, data)) {
5502 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005503 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5504 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 if (bestComponent == null
5506 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5507 loge("The calling package is not allowed to select ISD-R.");
5508 throw new SecurityException(
5509 "The calling package is not allowed to select ISD-R.");
5510 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005511 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005514 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5515 null /* workSource */);
5516 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 // Append the returned status code to the end of the response payload.
5519 String s = Integer.toHexString(
5520 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5521 if (response.payload != null) {
5522 s = IccUtils.bytesToHexString(response.payload) + s;
5523 }
5524 return s;
5525 } finally {
5526 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005527 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005528 }
5529
5530 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005531 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005532 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5534 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 if (DBG) {
5539 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5540 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5541 }
5542
5543 IccIoResult response =
5544 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5545 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5546 subId);
5547
5548 if (DBG) {
5549 log("Exchange SIM_IO [R]" + response);
5550 }
5551
5552 byte[] result = null;
5553 int length = 2;
5554 if (response.payload != null) {
5555 length = 2 + response.payload.length;
5556 result = new byte[length];
5557 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5558 } else {
5559 result = new byte[length];
5560 }
5561
5562 result[length - 1] = (byte) response.sw2;
5563 result[length - 2] = (byte) response.sw1;
5564 return result;
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005567 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005568 }
5569
Nathan Haroldb3014052017-01-25 15:57:32 -08005570 /**
5571 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5572 * on a particular subscription
5573 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005574 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5575 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005577 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005578 return null;
5579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 if (appType != TelephonyManager.APPTYPE_USIM
5584 && appType != TelephonyManager.APPTYPE_SIM) {
5585 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5586 return null;
5587 }
5588 Object response = sendRequest(
5589 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5590 if (response instanceof String[]) {
5591 return (String[]) response;
5592 }
yincheng zhao2737e882019-09-06 17:06:54 -07005593 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005595 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 } finally {
5597 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005598 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005599 }
5600
yincheng zhao2737e882019-09-06 17:06:54 -07005601 /**
5602 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5603 * subscription.
5604 *
5605 * @param subId the id of the subscription.
5606 * @param appType the uicc app type, must be USIM or SIM.
5607 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5608 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005609 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005610 * @return number of fplmns that is successfully written to the SIM.
5611 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005612 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5613 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5615 mApp, subId, "setForbiddenPlmns");
5616
yincheng zhao2737e882019-09-06 17:06:54 -07005617 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5618 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5619 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5620 }
5621 if (fplmns == null) {
5622 throw new IllegalArgumentException("Fplmn List provided is null");
5623 }
5624 for (String fplmn : fplmns) {
5625 if (!CellIdentity.isValidPlmn(fplmn)) {
5626 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5627 }
5628 }
5629 final long identity = Binder.clearCallingIdentity();
5630 try {
5631 Object response = sendRequest(
5632 CMD_SET_FORBIDDEN_PLMNS,
5633 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5634 subId);
5635 return (int) response;
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
5639 }
5640
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005641 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005642 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5644 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5649 if (response.payload == null) {
5650 return "";
5651 }
Evan Charltonc66da362014-05-16 14:06:40 -07005652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 // Append the returned status code to the end of the response payload.
5654 String s = Integer.toHexString(
5655 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5656 s = IccUtils.bytesToHexString(response.payload) + s;
5657 return s;
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Evan Charltonc66da362014-05-16 14:06:40 -07005661 }
5662
Jake Hambye994d462014-02-03 13:10:13 -08005663 /**
5664 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5665 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5666 *
5667 * @param itemID the ID of the item to read
5668 * @return the NV item as a String, or null on error.
5669 */
5670 @Override
5671 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005672 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5674 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005679 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5681 return value;
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Jake Hambye994d462014-02-03 13:10:13 -08005685 }
5686
5687 /**
5688 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5689 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5690 *
5691 * @param itemID the ID of the item to read
5692 * @param itemValue the value to write, as a String
5693 * @return true on success; false on any failure
5694 */
5695 @Override
5696 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005697 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5699 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700
5701 final long identity = Binder.clearCallingIdentity();
5702 try {
5703 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5704 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005705 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5707 return success;
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Jake Hambye994d462014-02-03 13:10:13 -08005711 }
5712
5713 /**
5714 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5715 * Used for device configuration by some CDMA operators.
5716 *
5717 * @param preferredRoamingList byte array containing the new PRL
5718 * @return true on success; false on any failure
5719 */
5720 @Override
5721 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5723 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724
5725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5728 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5729 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5730 return success;
5731 } finally {
5732 Binder.restoreCallingIdentity(identity);
5733 }
Jake Hambye994d462014-02-03 13:10:13 -08005734 }
5735
5736 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005737 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005738 * Used for device configuration by some CDMA operators.
5739 *
chen xu6dac5ab2018-10-26 17:39:23 -07005740 * @param slotIndex - device slot.
5741 *
Jake Hambye994d462014-02-03 13:10:13 -08005742 * @return true on success; false on any failure
5743 */
5744 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005745 public boolean resetModemConfig(int slotIndex) {
5746 Phone phone = PhoneFactory.getPhone(slotIndex);
5747 if (phone != null) {
5748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5749 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750
chen xu6dac5ab2018-10-26 17:39:23 -07005751 final long identity = Binder.clearCallingIdentity();
5752 try {
5753 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5754 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5755 return success;
5756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 }
chen xu6dac5ab2018-10-26 17:39:23 -07005760 return false;
5761 }
5762
5763 /**
5764 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5765 *
5766 * @param slotIndex - device slot.
5767 *
5768 * @return true on success; false on any failure
5769 */
5770 @Override
5771 public boolean rebootModem(int slotIndex) {
5772 Phone phone = PhoneFactory.getPhone(slotIndex);
5773 if (phone != null) {
5774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5775 mApp, phone.getSubId(), "rebootModem");
5776
5777 final long identity = Binder.clearCallingIdentity();
5778 try {
5779 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5780 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5781 return success;
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
5785 }
5786 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005787 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005788
Brad Ebinger51f743a2017-01-23 13:50:20 -08005789 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005790 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5791 * {@link #disableIms(int)}.
5792 * @param slotIndex device slot.
5793 */
5794 public void resetIms(int slotIndex) {
5795 enforceModifyPermission();
5796
5797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 if (mImsResolver == null) {
5800 // may happen if the does not support IMS.
5801 return;
5802 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005803 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
5807 }
5808
5809 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005810 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5811 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005812 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005813 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005814 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005818 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005819 // may happen if the device does not support IMS.
5820 return;
5821 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005826 }
5827
5828 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005829 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5830 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005831 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005832 public void disableIms(int slotId) {
5833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834
5835 final long identity = Binder.clearCallingIdentity();
5836 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005837 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005838 // may happen if the device does not support IMS.
5839 return;
5840 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005841 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 } finally {
5843 Binder.restoreCallingIdentity(identity);
5844 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005845 }
5846
5847 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005848 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5849 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005850 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005851 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005852 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005853 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854
5855 final long identity = Binder.clearCallingIdentity();
5856 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005858 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5859 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005860 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005861 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005865 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005866 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005867 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5868 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005869 @Override
5870 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005871 enforceModifyPermission();
5872
5873 final long identity = Binder.clearCallingIdentity();
5874 try {
5875 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005876 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
5880 }
5881
5882 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005883 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005884 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005885 */
5886 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5887 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888
5889 final long identity = Binder.clearCallingIdentity();
5890 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005891 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005892 // may happen if the device does not support IMS.
5893 return null;
5894 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005895 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005899 }
5900
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005901 /**
5902 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005903 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005904 */
5905 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5906 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907
5908 final long identity = Binder.clearCallingIdentity();
5909 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005910 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005911 // may happen if the device does not support IMS.
5912 return null;
5913 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005914 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005918 }
5919
Brad Ebinger884c07b2018-02-15 16:17:40 -08005920 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005921 * Sets the ImsService Package Name that Telephony will bind to.
5922 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005923 * @param slotIndex the slot ID that the ImsService should bind for.
5924 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005925 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005926 * @param featureTypes An integer array of feature types associated with a packageName.
5927 * @param packageName The name of the package that the current configuration will be replaced
5928 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005929 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005930 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5932 int[] featureTypes, String packageName) {
5933 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5934 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5936 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005937 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 final long identity = Binder.clearCallingIdentity();
5940 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005942 // may happen if the device does not support IMS.
5943 return false;
5944 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005945 Map<Integer, String> featureConfig = new HashMap<>();
5946 for (int featureType : featureTypes) {
5947 featureConfig.put(featureType, packageName);
5948 }
5949 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5950 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 } finally {
5952 Binder.restoreCallingIdentity(identity);
5953 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005954 }
5955
5956 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005957 * Clears any carrier ImsService overrides for the slot index specified that were previously
5958 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5959 *
5960 * This should only be used for testing.
5961 *
5962 * @param slotIndex the slot ID that the ImsService should bind for.
5963 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5964 */
5965 @Override
5966 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5967 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5969 "clearCarrierImsServiceOverride");
5970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5971 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5972 "clearCarrierImsServiceOverride");
5973
5974 final long identity = Binder.clearCallingIdentity();
5975 try {
5976 if (mImsResolver == null) {
5977 // may happen if the device does not support IMS.
5978 return false;
5979 }
5980 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5981 } finally {
5982 Binder.restoreCallingIdentity(identity);
5983 }
5984 }
5985
5986 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005987 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005988 *
5989 * @param slotId The slot that the ImsService is associated with.
5990 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5991 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005992 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005993 * @return the package name of the ImsService configuration.
5994 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005995 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5996 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005997 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005998 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005999 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006000 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6001 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 final long identity = Binder.clearCallingIdentity();
6004 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006005 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006006 // may happen if the device does not support IMS.
6007 return "";
6008 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006009 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006010 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6011 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006015 }
6016
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006017 /**
6018 * Get the MmTelFeature state associated with the requested subscription id.
6019 * @param subId The subscription that the MmTelFeature is associated with.
6020 * @param callback A callback with an integer containing the
6021 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6022 */
6023 @Override
6024 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6025 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006026 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6027 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6028 "IMS not available on device.");
6029 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006030 final long token = Binder.clearCallingIdentity();
6031 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006032 int slotId = getSlotIndex(subId);
6033 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6034 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6035 + subId + "'");
6036 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6037 }
6038 verifyImsMmTelConfiguredOrThrow(slotId);
6039 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6040 try {
6041 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6042 } catch (RemoteException e) {
6043 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6044 + "Ignore");
6045 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006046 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006047 } catch (ImsException e) {
6048 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006049 } finally {
6050 Binder.restoreCallingIdentity(token);
6051 }
6052 }
6053
Daniel Brightbb5840b2021-01-12 15:48:18 -08006054 /**
6055 * Sets the ims registration state on all valid {@link Phone}s.
6056 */
6057 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059
6060 final long identity = Binder.clearCallingIdentity();
6061 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006062 // NOTE: Before S, this method only set the default phone.
6063 for (final Phone phone : PhoneFactory.getPhones()) {
6064 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6065 phone.setImsRegistrationState(registered);
6066 }
6067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
Wink Saville36469e72014-06-11 15:17:00 -07006071 }
6072
6073 /**
Stuart Scott54788802015-03-30 13:18:01 -07006074 * Set the network selection mode to automatic.
6075 *
6076 */
6077 @Override
6078 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6080 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081
6082 final long identity = Binder.clearCallingIdentity();
6083 try {
shilufc958392020-01-20 11:36:01 -08006084 if (!isActiveSubscription(subId)) {
6085 return;
6086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006088 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6089 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
Stuart Scott54788802015-03-30 13:18:01 -07006093 }
6094
Jack Yud10cdd42020-09-28 20:28:01 -07006095 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006096 * Ask the radio to connect to the input network and change selection mode to manual.
6097 *
6098 * @param subId the id of the subscription.
6099 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6100 * the operator to attach to.
6101 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6102 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6103 * normal network selection next time.
6104 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006105 */
6106 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006107 public boolean setNetworkSelectionModeManual(
6108 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6110 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006111
6112 if (!isActiveSubscription(subId)) {
6113 return false;
6114 }
6115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 final long identity = Binder.clearCallingIdentity();
6117 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006118 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006120 if (DBG) {
6121 log("setNetworkSelectionModeManual: subId: " + subId
6122 + " operator: " + operatorInfo);
6123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006128 }
shilu84f6e8b2019-12-19 13:58:01 -08006129 /**
6130 * Get the manual network selection
6131 *
6132 * @param subId the id of the subscription.
6133 *
6134 * @return the previously saved user selected PLMN
6135 */
6136 @Override
6137 public String getManualNetworkSelectionPlmn(int subId) {
6138 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006139 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006140 mApp, subId, "getManualNetworkSelectionPlmn");
6141
6142 final long identity = Binder.clearCallingIdentity();
6143 try {
6144 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006145 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006146 }
6147
6148 final Phone phone = getPhone(subId);
6149 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006150 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006151 }
6152 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6153 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6154 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6155 } finally {
6156 Binder.restoreCallingIdentity(identity);
6157 }
6158 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006159
6160 /**
6161 * Scans for available networks.
6162 */
6163 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006164 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6165 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6167 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006168 LocationAccessPolicy.LocationPermissionResult locationResult =
6169 LocationAccessPolicy.checkLocationPermission(mApp,
6170 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6171 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006172 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006173 .setCallingPid(Binder.getCallingPid())
6174 .setCallingUid(Binder.getCallingUid())
6175 .setMethod("getCellNetworkScanResults")
6176 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006177 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6178 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006179 .build());
6180 switch (locationResult) {
6181 case DENIED_HARD:
6182 throw new SecurityException("Not allowed to access scan results -- location");
6183 case DENIED_SOFT:
6184 return null;
6185 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186
Pengquan Menga1bb6272018-09-06 09:59:22 -07006187 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 try {
6189 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006190 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006195 }
6196
6197 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006198 * Get the call forwarding info, given the call forwarding reason.
6199 */
6200 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006201 public void getCallForwarding(int subId, int callForwardingReason,
6202 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006203 enforceReadPrivilegedPermission("getCallForwarding");
6204 long identity = Binder.clearCallingIdentity();
6205 try {
6206 if (DBG) {
6207 log("getCallForwarding: subId " + subId
6208 + " callForwardingReason" + callForwardingReason);
6209 }
Hall Liu27d24262020-09-18 19:04:59 -07006210
6211 Phone phone = getPhone(subId);
6212 if (phone == null) {
6213 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006214 callback.onError(
6215 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006216 } catch (RemoteException e) {
6217 // ignore
6218 }
6219 return;
6220 }
6221
6222 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6223 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6224 @Override
6225 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6226 try {
6227 callback.onCallForwardingInfoAvailable(info);
6228 } catch (RemoteException e) {
6229 // ignore
6230 }
6231 }
6232
6233 @Override
6234 public void onError(int error) {
6235 try {
6236 callback.onError(error);
6237 } catch (RemoteException e) {
6238 // ignore
6239 }
6240 }
6241 });
6242 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006243 } finally {
6244 Binder.restoreCallingIdentity(identity);
6245 }
6246 }
6247
6248 /**
6249 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6250 * reason, the number to forward, and the timeout before the forwarding is attempted.
6251 */
6252 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006253 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6254 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006255 enforceModifyPermission();
6256 long identity = Binder.clearCallingIdentity();
6257 try {
6258 if (DBG) {
6259 log("setCallForwarding: subId " + subId
6260 + " callForwardingInfo" + callForwardingInfo);
6261 }
Hall Liu27d24262020-09-18 19:04:59 -07006262
6263 Phone phone = getPhone(subId);
6264 if (phone == null) {
6265 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006266 callback.accept(
6267 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006268 } catch (RemoteException e) {
6269 // ignore
6270 }
6271 return;
6272 }
6273
6274 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6275 FunctionalUtils.ignoreRemoteException(callback::accept));
6276
6277 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
6281 }
6282
6283 /**
Hall Liu27d24262020-09-18 19:04:59 -07006284 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006285 */
6286 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006287 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006288 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006289 long identity = Binder.clearCallingIdentity();
6290 try {
Hall Liu27d24262020-09-18 19:04:59 -07006291 Phone phone = getPhone(subId);
6292 if (phone == null) {
6293 try {
6294 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6295 } catch (RemoteException e) {
6296 // ignore
6297 }
6298 return;
6299 }
SongFerngWang0e767992021-03-31 22:08:45 +08006300 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6301 PersistableBundle c = configManager.getConfigForSubId(subId);
6302 boolean requireUssd = c.getBoolean(
6303 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006304
Shuo Qian4a594052020-01-23 11:59:30 -08006305 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006306 if (requireUssd) {
6307 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6308 getSubscriptionCarrierId(subId));
6309 String newUssdCommand = "";
6310 try {
6311 newUssdCommand = carrierXmlParser.getFeature(
6312 CarrierXmlParser.FEATURE_CALL_WAITING)
6313 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6314 } catch (NullPointerException e) {
6315 loge("Failed to generate USSD number" + e);
6316 }
6317 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6318 mMainThreadHandler, callback, carrierXmlParser,
6319 CarrierXmlParser.SsEntry.SSAction.QUERY);
6320 final String ussdCommand = newUssdCommand;
6321 Executors.newSingleThreadExecutor().execute(() -> {
6322 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6323 });
6324 } else {
6325 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6326 callback::accept);
6327 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6328 }
Shuo Qian4a594052020-01-23 11:59:30 -08006329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 }
6333
6334 /**
Hall Liu27d24262020-09-18 19:04:59 -07006335 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006336 */
6337 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006338 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006339 enforceModifyPermission();
6340 long identity = Binder.clearCallingIdentity();
6341 try {
Hall Liu27d24262020-09-18 19:04:59 -07006342 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6343
6344 Phone phone = getPhone(subId);
6345 if (phone == null) {
6346 try {
6347 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6348 } catch (RemoteException e) {
6349 // ignore
6350 }
6351 return;
6352 }
6353
SongFerngWang0e767992021-03-31 22:08:45 +08006354 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6355 PersistableBundle c = configManager.getConfigForSubId(subId);
6356 boolean requireUssd = c.getBoolean(
6357 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006358
SongFerngWang0e767992021-03-31 22:08:45 +08006359 if (DBG) log("getCallWaitingStatus: subId " + subId);
6360 if (requireUssd) {
6361 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6362 getSubscriptionCarrierId(subId));
6363 CarrierXmlParser.SsEntry.SSAction ssAction =
6364 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6365 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6366 String newUssdCommand = "";
6367 try {
6368 newUssdCommand = carrierXmlParser.getFeature(
6369 CarrierXmlParser.FEATURE_CALL_WAITING)
6370 .makeCommand(ssAction, null);
6371 } catch (NullPointerException e) {
6372 loge("Failed to generate USSD number" + e);
6373 }
6374 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6375 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6376 final String ussdCommand = newUssdCommand;
6377 Executors.newSingleThreadExecutor().execute(() -> {
6378 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6379 });
6380 } else {
6381 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6382 FunctionalUtils.ignoreRemoteException(callback::accept));
6383
6384 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6385 }
Shuo Qian4a594052020-01-23 11:59:30 -08006386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
6389 }
6390
6391 /**
yinxub1bed742017-04-17 11:45:04 -07006392 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006393 *
yinxub1bed742017-04-17 11:45:04 -07006394 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006395 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6396 * location related information which will be sent if the caller already possess
6397 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006398 * @param request contains the radio access networks with bands/channels to scan
6399 * @param messenger callback messenger for scan results or errors
6400 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006401 * @return the id of the requested scan which can be used to stop the scan.
6402 */
6403 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006404 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6405 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006406 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6408 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006409 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006410 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6411 if (!renounceFineLocationAccess) {
6412 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6413 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6414 .setCallingPackage(callingPackage)
6415 .setCallingFeatureId(callingFeatureId)
6416 .setCallingPid(Binder.getCallingPid())
6417 .setCallingUid(Binder.getCallingUid())
6418 .setMethod("requestNetworkScan")
6419 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6420 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6421 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6422 .build());
6423 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006424 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006425 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6426 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006427 if (e != null) {
6428 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6429 throw e;
6430 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006431 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006432 return TelephonyScanManager.INVALID_SCAN_ID;
6433 }
6434 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435 }
Hall Liu912dfd32019-04-25 14:02:26 -07006436 int callingUid = Binder.getCallingUid();
6437 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006438 final long identity = Binder.clearCallingIdentity();
6439 try {
6440 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006441 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006442 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
yinxu504e1392017-04-12 16:03:22 -07006446 }
6447
Hall Liub2ac8ef2019-02-28 15:56:23 -08006448 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006449 NetworkScanRequest request, int subId, String callingPackage) {
6450 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006451 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6452 boolean hasNetworkScanPermission =
6453 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6454 == PERMISSION_GRANTED;
6455
6456 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6457 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6458 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006459 }
6460
6461 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6462 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006463 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6464 return new SecurityException("Specific channels must not be"
6465 + " scanned without location access.");
6466 }
6467 }
6468 }
6469
Hall Liub2ac8ef2019-02-28 15:56:23 -08006470 return null;
6471 }
6472
yinxu504e1392017-04-12 16:03:22 -07006473 /**
6474 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006475 *
6476 * @param subId id of the subscription
6477 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006478 */
6479 @Override
6480 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6482 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483
Hall Liu912dfd32019-04-25 14:02:26 -07006484 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 final long identity = Binder.clearCallingIdentity();
6486 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006487 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
yinxu504e1392017-04-12 16:03:22 -07006491 }
6492
6493 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006494 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006495 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006496 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006497 */
6498 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006499 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006500 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006501 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006502 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503
6504 final long identity = Binder.clearCallingIdentity();
6505 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006506 if (DBG) log("getAllowedNetworkTypesBitmask");
6507 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6508 int networkTypesBitmask = (result != null ? result[0] : -1);
6509 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6510 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511 } finally {
6512 Binder.restoreCallingIdentity(identity);
6513 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006514 }
6515
6516 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006517 * Get the allowed network types for certain reason.
6518 *
6519 * @param subId the id of the subscription.
6520 * @param reason the reason the allowed network type change is taking place
6521 * @return the allowed network types.
6522 */
6523 @Override
6524 public long getAllowedNetworkTypesForReason(int subId,
6525 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006526 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006527 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006528 final long identity = Binder.clearCallingIdentity();
6529 try {
6530 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
6534 }
6535
6536 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006537 * Enable/Disable E-UTRA-NR Dual Connectivity
6538 * @param subId subscription id of the sim card
6539 * @param nrDualConnectivityState expected NR dual connectivity state
6540 * This can be passed following states
6541 * <ol>
6542 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6543 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6544 * <li>Disable NR dual connectivity and force secondary cell to be released
6545 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6546 * </ol>
6547 * @return operation result.
6548 */
6549 @Override
6550 public int setNrDualConnectivityState(int subId,
6551 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6553 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006554 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006555 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6556 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6557 }
6558
Sooraj Sasindran37444802020-08-11 10:40:43 -07006559 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6560 final long identity = Binder.clearCallingIdentity();
6561 try {
6562 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6563 nrDualConnectivityState, subId,
6564 workSource);
6565 if (DBG) log("enableNRDualConnectivity result: " + result);
6566 return result;
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
6570 }
6571
6572 /**
6573 * Is E-UTRA-NR Dual Connectivity enabled
6574 * @return true if dual connectivity is enabled else false
6575 */
6576 @Override
6577 public boolean isNrDualConnectivityEnabled(int subId) {
6578 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006579 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006580 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006581 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006582 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6583 return false;
6584 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006585 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6586 final long identity = Binder.clearCallingIdentity();
6587 try {
6588 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6589 null, subId, workSource);
6590 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6591 return isEnabled;
6592 } finally {
6593 Binder.restoreCallingIdentity(identity);
6594 }
6595 }
6596
6597 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006598 * Set the allowed network types of the device and
6599 * provide the reason triggering the allowed network change.
6600 *
6601 * @param subId the id of the subscription.
6602 * @param reason the reason the allowed network type change is taking place
6603 * @param allowedNetworkTypes the allowed network types.
6604 * @return true on success; false on any failure.
6605 */
6606 @Override
6607 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006608 @TelephonyManager.AllowedNetworkTypesReason int reason,
6609 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6611 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006612 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006613 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6614 return false;
6615 }
6616 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6617 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006618 return false;
6619 }
6620
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006621 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6622 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6623
6624
6625 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6626 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6627 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006628 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006629
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006630 final long identity = Binder.clearCallingIdentity();
6631 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006632 Boolean success = (Boolean) sendRequest(
6633 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6634 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6635
6636 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6637 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006638 } finally {
6639 Binder.restoreCallingIdentity(identity);
6640 }
6641 }
6642
6643 /**
Miaoa84611c2019-03-15 09:21:10 +08006644 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006645 *
Miaoa84611c2019-03-15 09:21:10 +08006646 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006647 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006648 * @hide
6649 */
6650 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006651 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006654 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 try {
Miaoa84611c2019-03-15 09:21:10 +08006656 if (phone != null) {
6657 return phone.hasMatchedTetherApnSetting();
6658 } else {
6659 return false;
6660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 } finally {
6662 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006663 }
Junda Liu475951f2014-11-07 16:45:03 -08006664 }
6665
6666 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006667 * Get the user enabled state of Mobile Data.
6668 *
6669 * TODO: remove and use isUserDataEnabled.
6670 * This can't be removed now because some vendor codes
6671 * calls through ITelephony directly while they should
6672 * use TelephonyManager.
6673 *
6674 * @return true on enabled
6675 */
6676 @Override
6677 public boolean getDataEnabled(int subId) {
6678 return isUserDataEnabled(subId);
6679 }
6680
6681 /**
6682 * Get whether mobile data is enabled per user setting.
6683 *
6684 * There are other factors deciding whether mobile data is actually enabled, but they are
6685 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006686 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006687 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6688 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006689 *
6690 * @return {@code true} if data is enabled else {@code false}
6691 */
6692 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006693 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006694 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006695 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006696 try {
6697 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6698 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006699 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006700 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6701 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006702 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006704 mApp, subId, functionName);
6705
Robert Greenwalt646120a2014-05-23 11:54:03 -07006706 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707
6708 final long identity = Binder.clearCallingIdentity();
6709 try {
6710 int phoneId = mSubscriptionController.getPhoneId(subId);
6711 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6712 Phone phone = PhoneFactory.getPhone(phoneId);
6713 if (phone != null) {
6714 boolean retVal = phone.isUserDataEnabled();
6715 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6716 return retVal;
6717 } else {
6718 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6719 return false;
6720 }
6721 } finally {
6722 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006723 }
6724 }
6725
6726 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006727 * Checks if the device is capable of mobile data by considering whether whether the
6728 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6729 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006730 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006731 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006732 */
6733 @Override
6734 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006735 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006736 try {
6737 try {
6738 mApp.enforceCallingOrSelfPermission(
6739 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006740 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006741 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006742 try {
6743 mApp.enforceCallingOrSelfPermission(
6744 android.Manifest.permission.READ_PHONE_STATE,
6745 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006746 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006747 mApp.enforceCallingOrSelfPermission(
6748 permission.READ_BASIC_PHONE_STATE, functionName);
6749 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006750 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006751 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006752 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754
6755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 Phone phone = PhoneFactory.getPhone(phoneId);
6759 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006760 boolean retVal;
Jack Yuf745f972022-08-15 19:53:50 +00006761 if (phone.isUsingNewDataStack()) {
6762 retVal = phone.getDataSettingsManager().isDataEnabled();
6763 } else {
6764 retVal = phone.getDataEnabledSettings().isDataEnabled();
6765 }
Jack Yu4ad64e52021-12-03 14:23:53 -08006766 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 return retVal;
6768 } else {
6769 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6770 return false;
6771 }
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006774 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006775 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006776
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006777 /**
6778 * Check if data is enabled for a specific reason
6779 * @param subId Subscription index
6780 * @param reason the reason the data enable change is taking place
6781 * @return {@code true} if the overall data is enabled; {@code false} if not.
6782 */
6783 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006784 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006785 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006786 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006787 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006788 try {
6789 mApp.enforceCallingOrSelfPermission(
6790 android.Manifest.permission.ACCESS_NETWORK_STATE,
6791 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006792 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006793 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6794 functionName);
6795 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006796 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006797 try {
6798 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006799 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006800 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006802 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006803 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006804 }
6805
6806
6807 final long identity = Binder.clearCallingIdentity();
6808 try {
6809 int phoneId = mSubscriptionController.getPhoneId(subId);
6810 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006811 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006812 + " reason=" + reason);
6813 }
6814 Phone phone = PhoneFactory.getPhone(phoneId);
6815 if (phone != null) {
6816 boolean retVal;
Jack Yuf745f972022-08-15 19:53:50 +00006817 if (phone.isUsingNewDataStack()) {
6818 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
6819 } else {
6820 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6821 retVal = phone.isUserDataEnabled();
6822 } else {
6823 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6824 }
6825 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006826 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006827 return retVal;
6828 } else {
6829 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006830 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006831 + subId + " retVal=false");
6832 }
6833 return false;
6834 }
6835 } finally {
6836 Binder.restoreCallingIdentity(identity);
6837 }
6838 }
6839
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006840 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006841 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006842 // No permission needed; this only lets the caller inspect their own status.
6843 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006844 }
Junda Liu29340342014-07-10 15:23:27 -07006845
6846 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006847 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006848 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006849 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6850 }
6851
6852 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6853 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006854 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006855 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006856 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6857 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006858 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6859 if (cpt == null) {
6860 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006861 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6862 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006863 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006864 }
6865
6866 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006867 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006868 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006869 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006870 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006871 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006872 Phone phone = getPhone(subId);
6873 if (phone == null) {
6874 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6875 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6876 }
6877 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6878 if (cpt == null) {
6879 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006880 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6881 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006882 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006883 }
6884
6885 @Override
6886 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006887 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006888 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6889 }
6890
6891 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006892 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006893 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006894 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006895 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006896 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6897 Phone phone = PhoneFactory.getPhone(phoneId);
6898 if (phone == null) {
6899 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006900 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006901 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6902 if (cpt == null) {
6903 continue;
6904 }
6905 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006906 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6907 break;
6908 }
6909 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006910 return result;
Junda Liu29340342014-07-10 15:23:27 -07006911 }
Derek Tan89e89d42014-07-08 17:00:10 -07006912
6913 @Override
Junda Liue64de782015-04-16 17:19:16 -07006914 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006915 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006916 Phone phone = PhoneFactory.getPhone(phoneId);
6917 if (phone == null) {
6918 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006919 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006920 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6921 if (cpt == null) {
6922 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006923 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006924 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006925 }
6926
Amith Yamasani6e118872016-02-19 12:53:51 -08006927 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006928 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006929 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006930 Phone phone = PhoneFactory.getPhone(phoneId);
6931 if (phone == null) {
6932 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006933 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006934 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6935 if (cpt == null) {
6936 return Collections.emptyList();
6937 }
6938 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006939 }
6940
chen xuf7e9fe82019-05-09 19:31:02 -07006941 @Override
6942 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006943 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006944 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006945 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006946 try {
6947 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6948 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6949 }
6950 } finally {
6951 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006952 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006953 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006954 }
6955
Rambo Wang6812ffb2022-03-15 16:54:17 -07006956 @Override
6957 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6958 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6959
6960 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6961 if (phone == null) {
6962 return null;
6963 }
6964 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6965 if (cpt == null) {
6966 return null;
6967 }
6968 return cpt.getCarrierServicePackageName();
6969 }
6970
Wink Savilleb564aae2014-10-23 10:18:09 -07006971 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006972 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006973 UiccPort port = phone == null ? null : phone.getUiccPort();
6974 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006975 return null;
6976 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006977 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006978 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006979 return null;
6980 }
6981 return iccId;
6982 }
6983
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006984 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006985 public void setCallComposerStatus(int subId, int status) {
6986 enforceModifyPermission();
6987
6988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 Phone phone = getPhone(subId);
6991 if (phone != null) {
6992 Phone defaultPhone = phone.getImsPhone();
6993 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6994 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6995 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6997 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006998 }
6999 }
Shuo Qian284ae752020-12-22 19:10:14 -08007000 } catch (ImsException e) {
7001 throw new ServiceSpecificException(e.getCode());
7002 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007003 Binder.restoreCallingIdentity(identity);
7004 }
7005 }
7006
7007 @Override
7008 public int getCallComposerStatus(int subId) {
7009 enforceReadPrivilegedPermission("getCallComposerStatus");
7010
7011 final long identity = Binder.clearCallingIdentity();
7012 try {
7013 Phone phone = getPhone(subId);
7014 if (phone != null) {
7015 Phone defaultPhone = phone.getImsPhone();
7016 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7017 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7018 return imsPhone.getCallComposerStatus();
7019 }
7020 }
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
7023 }
7024 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7025 }
7026
7027 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007028 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7029 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007030 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007031 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 final String iccId = getIccId(subId);
7036 final Phone phone = getPhone(subId);
7037 if (phone == null) {
7038 return false;
7039 }
7040 final String subscriberId = phone.getSubscriberId();
7041
7042 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007043 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 + subscriberId + " to " + number);
7045 }
7046
7047 if (TextUtils.isEmpty(iccId)) {
7048 return false;
7049 }
7050
7051 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7052
7053 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7054 if (alphaTag == null) {
7055 editor.remove(alphaTagPrefKey);
7056 } else {
7057 editor.putString(alphaTagPrefKey, alphaTag);
7058 }
7059
7060 // Record both the line number and IMSI for this ICCID, since we need to
7061 // track all merged IMSIs based on line number
7062 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7063 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7064 if (number == null) {
7065 editor.remove(numberPrefKey);
7066 editor.remove(subscriberPrefKey);
7067 } else {
7068 editor.putString(numberPrefKey, number);
7069 editor.putString(subscriberPrefKey, subscriberId);
7070 }
7071
7072 editor.commit();
7073 return true;
7074 } finally {
7075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007076 }
Derek Tan7226c842014-07-02 17:42:23 -07007077 }
7078
7079 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007080 public String getLine1NumberForDisplay(int subId, String callingPackage,
7081 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007082 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007084 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007085 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007086 return null;
7087 }
Derek Tan97ebb422014-09-05 16:55:38 -07007088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 String iccId = getIccId(subId);
7092 if (iccId != null) {
7093 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7094 if (DBG_MERGE) {
7095 log("getLine1NumberForDisplay returning "
7096 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7097 }
7098 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7101 return null;
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007104 }
Derek Tan7226c842014-07-02 17:42:23 -07007105 }
7106
7107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007108 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007111 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007112 return null;
7113 }
Derek Tan97ebb422014-09-05 16:55:38 -07007114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 final long identity = Binder.clearCallingIdentity();
7116 try {
7117 String iccId = getIccId(subId);
7118 if (iccId != null) {
7119 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7120 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7121 }
7122 return null;
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007125 }
Derek Tan7226c842014-07-02 17:42:23 -07007126 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007127
7128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007129 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7130 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007131 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7132 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007134 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007135 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007136 return null;
7137 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007138
Jordan Liub49b04b2019-05-06 14:45:15 -07007139 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7140 // the process, where TelephonyManager was instantiated.
7141 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007142 final long identity = Binder.clearCallingIdentity();
7143 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007144 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 final TelephonyManager tele = TelephonyManager.from(context);
7146 final SubscriptionManager sub = SubscriptionManager.from(context);
7147
7148 // Figure out what subscribers are currently active
7149 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150
Jordan Liub49b04b2019-05-06 14:45:15 -07007151 // Only consider subs which match the current subId
7152 // This logic can be simplified. See b/131189269 for progress.
7153 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007154 activeSubscriberIds.add(tele.getSubscriberId(subId));
7155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156
7157 // First pass, find a number override for an active subscriber
7158 String mergeNumber = null;
7159 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7160 for (String key : prefs.keySet()) {
7161 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7162 final String subscriberId = (String) prefs.get(key);
7163 if (activeSubscriberIds.contains(subscriberId)) {
7164 final String iccId = key.substring(
7165 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7166 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7167 mergeNumber = (String) prefs.get(numberKey);
7168 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007169 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 + " for active subscriber " + subscriberId);
7171 }
7172 if (!TextUtils.isEmpty(mergeNumber)) {
7173 break;
7174 }
7175 }
7176 }
7177 }
7178
7179 // Shortcut when no active merged subscribers
7180 if (TextUtils.isEmpty(mergeNumber)) {
7181 return null;
7182 }
7183
7184 // Second pass, find all subscribers under that line override
7185 final ArraySet<String> result = new ArraySet<>();
7186 for (String key : prefs.keySet()) {
7187 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7188 final String number = (String) prefs.get(key);
7189 if (mergeNumber.equals(number)) {
7190 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7191 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7192 final String subscriberId = (String) prefs.get(subscriberKey);
7193 if (!TextUtils.isEmpty(subscriberId)) {
7194 result.add(subscriberId);
7195 }
7196 }
7197 }
7198 }
7199
7200 final String[] resultArray = result.toArray(new String[result.size()]);
7201 Arrays.sort(resultArray);
7202 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007203 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7205 }
7206 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007207 } finally {
7208 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007209 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007210 }
7211
7212 @Override
zoey chen38003472019-12-13 17:16:31 +08007213 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7214 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007215
7216 final long identity = Binder.clearCallingIdentity();
7217 try {
7218 final TelephonyManager telephonyManager = mApp.getSystemService(
7219 TelephonyManager.class);
7220 String subscriberId = telephonyManager.getSubscriberId(subId);
7221 if (subscriberId == null) {
7222 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007223 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007224 + subId);
7225 }
7226 return null;
7227 }
7228
7229 final SubscriptionInfo info = SubscriptionController.getInstance()
7230 .getSubscriptionInfo(subId);
7231 final ParcelUuid groupUuid = info.getGroupUuid();
7232 // If it doesn't belong to any group, return just subscriberId of itself.
7233 if (groupUuid == null) {
7234 return new String[]{subscriberId};
7235 }
7236
7237 // Get all subscriberIds from the group.
7238 final List<String> mergedSubscriberIds = new ArrayList<>();
7239 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007240 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007241 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007242 for (SubscriptionInfo subInfo : groupInfos) {
7243 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7244 if (subscriberId != null) {
7245 mergedSubscriberIds.add(subscriberId);
7246 }
7247 }
7248
7249 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252
7253 }
7254 }
7255
7256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007257 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007258 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007259 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 final Phone phone = getPhone(subId);
7264 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007268 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007269
7270 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007271 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007272 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7273 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7275 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276
7277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 final Phone phone = getPhone(subId);
7280 if (phone == null) {
7281 return false;
7282 }
7283 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7284 cdmaNonRoamingList);
7285 } finally {
7286 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007287 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007288 }
7289
7290 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007291 @Deprecated
7292 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7293 enforceModifyPermission();
7294
7295 int returnValue = 0;
7296 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007297 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007298 if(result.exception == null) {
7299 if (result.result != null) {
7300 byte[] responseData = (byte[])(result.result);
7301 if(responseData.length > oemResp.length) {
7302 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7303 responseData.length + "bytes. Buffer Size is " +
7304 oemResp.length + "bytes.");
7305 }
7306 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7307 returnValue = responseData.length;
7308 }
7309 } else {
7310 CommandException ex = (CommandException) result.exception;
7311 returnValue = ex.getCommandError().ordinal();
7312 if(returnValue > 0) returnValue *= -1;
7313 }
7314 } catch (RuntimeException e) {
7315 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7316 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7317 if(returnValue > 0) returnValue *= -1;
7318 }
7319
7320 return returnValue;
7321 }
7322
7323 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007324 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007325 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007326 try {
7327 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007328 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007329 mApp, phone.getSubId(), "getRadioAccessFamily");
7330 } catch (SecurityException e) {
7331 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7332 throw e;
7333 }
chen xub97461a2018-10-26 14:17:57 -07007334 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007335 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007336 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338 final long identity = Binder.clearCallingIdentity();
7339 try {
chen xub97461a2018-10-26 14:17:57 -07007340 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007341 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007342 mApp, phone.getSubId(), "getRadioAccessFamily");
7343 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 } finally {
7345 Binder.restoreCallingIdentity(identity);
7346 }
chen xub97461a2018-10-26 14:17:57 -07007347 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007348 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007349
7350 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007351 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007352 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007353 try {
7354 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7355 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007356 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007357 }
7358 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007359 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007360 }
7361 RoleManager rm = mApp.getSystemService(RoleManager.class);
7362 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7363 if (!dialerRoleHolders.contains(callingPackage)) {
7364 throw new SecurityException("App must be the dialer role holder to"
7365 + " upload a call composer pic");
7366 }
7367
7368 Executors.newSingleThreadExecutor().execute(() -> {
7369 ByteArrayOutputStream output = new ByteArrayOutputStream(
7370 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7371 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7372 boolean readUntilEnd = false;
7373 int totalBytesRead = 0;
7374 byte[] buffer = new byte[16 * 1024];
7375 while (true) {
7376 int numRead;
7377 try {
7378 numRead = input.read(buffer);
7379 } catch (IOException e) {
7380 try {
7381 fd.checkError();
7382 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7383 null);
7384 } catch (IOException e1) {
7385 // This means that the other side closed explicitly with an error. If this
7386 // happens, log and ignore.
7387 loge("Remote end of call composer picture pipe closed: " + e1);
7388 }
7389 break;
7390 }
7391 if (numRead == -1) {
7392 readUntilEnd = true;
7393 break;
7394 }
7395 totalBytesRead += numRead;
7396 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7397 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7398 try {
7399 input.close();
7400 } catch (IOException e) {
7401 // ignore
7402 }
7403 break;
7404 }
7405 output.write(buffer, 0, numRead);
7406 }
7407 // Generally, the remote end will close the file descriptors. The only case where we
7408 // close is above, where the picture size is too big.
7409
7410 try {
7411 fd.checkError();
7412 } catch (IOException e) {
7413 loge("Remote end for call composer closed with an error: " + e);
7414 return;
7415 }
7416
Hall Liuaa4211e2021-01-20 15:43:39 -08007417 if (!readUntilEnd) {
7418 loge("Did not finish reading entire image; aborting");
7419 return;
7420 }
Hall Liu82694d52020-12-11 18:22:04 -08007421
Hall Liuaa4211e2021-01-20 15:43:39 -08007422 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7423 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7424 new CallComposerPictureTransfer.Factory() {},
7425 imageData,
7426 (result) -> {
7427 if (result.first != null) {
7428 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7429 Bundle outputResult = new Bundle();
7430 outputResult.putParcelable(
7431 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7432 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7433 outputResult);
7434 } else {
7435 callback.send(result.second, null);
7436 }
7437 }
7438 );
Hall Liu82694d52020-12-11 18:22:04 -08007439 });
7440 }
7441
7442 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007443 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446
7447 final long identity = Binder.clearCallingIdentity();
7448 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 ImsManager.getInstance(defaultPhone.getContext(),
7450 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007454 }
7455
7456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007457 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007458 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7460 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007461 return false;
7462 }
Svet Ganovb320e182015-04-16 12:30:10 -07007463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 // Check the user preference and the system-level IMS setting. Even if the user has
7467 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7468 // In the long run, we may instead need to check if there exists a connection service
7469 // which can support video calling.
7470 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007471 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 return imsManager.isVtEnabledByPlatform()
7473 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7474 && imsManager.isVtEnabledByUser();
7475 } finally {
7476 Binder.restoreCallingIdentity(identity);
7477 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007478 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007479
Andrew Leea1239f22015-03-02 17:44:07 -08007480 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7482 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007484 mApp, subId, callingPackage, callingFeatureId,
7485 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 return false;
7487 }
7488
7489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 CarrierConfigManager configManager =
7492 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007493 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
Andrew Leea1239f22015-03-02 17:44:07 -08007498 }
7499
7500 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007501 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007503 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 return false;
7505 }
7506
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 CarrierConfigManager configManager =
7510 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
Andrew Leea1239f22015-03-02 17:44:07 -08007516 }
7517
Andrew Lee9431b832015-03-09 18:46:45 -07007518 @Override
7519 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007520 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007521 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007522 }
7523
7524 @Override
7525 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 final long identity = Binder.clearCallingIdentity();
7527 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007528 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
Andrew Lee9431b832015-03-09 18:46:45 -07007532 }
7533
Hall Liuf6668912018-10-31 17:05:23 -07007534 /**
7535 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7536 * support for the feature and device firmware support.
7537 *
7538 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7539 */
7540 @Override
7541 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 final Phone phone = getPhone(subscriptionId);
7544 if (phone == null) {
7545 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7546 return false;
7547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7551 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007552 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 return isCarrierSupported && isDeviceSupported;
7554 } finally {
7555 Binder.restoreCallingIdentity(identity);
7556 }
Hall Liu98187582018-01-22 19:15:32 -08007557 }
7558
Hall Liuf6668912018-10-31 17:05:23 -07007559 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007560 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7561 * RTT setting, will return true if the device and carrier both support RTT.
7562 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007563 */
7564 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 final long identity = Binder.clearCallingIdentity();
7566 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007567 boolean isRttSupported = isRttSupported(subscriptionId);
7568 boolean isUserRttSettingOn = Settings.Secure.getInt(
7569 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7570 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7571 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7572 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007576 }
7577
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007578 @Deprecated
7579 @Override
7580 public String getDeviceId(String callingPackage) {
7581 return getDeviceIdWithFeature(callingPackage, null);
7582 }
7583
Sanket Padawe7310cc72015-01-14 09:53:20 -08007584 /**
7585 * Returns the unique device ID of phone, for example, the IMEI for
7586 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7587 *
7588 * <p>Requires Permission:
7589 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7590 */
7591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007592 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007593 try {
7594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7595 } catch (SecurityException se) {
7596 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7597 throw new SecurityException("Package " + callingPackage + " does not belong to "
7598 + Binder.getCallingUid());
7599 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007600 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007601 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007602 return null;
7603 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007604 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007605 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007606 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007607 return null;
7608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609
7610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 return phone.getDeviceId();
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007616 }
7617
Ping Sunc67b7c22016-03-02 19:16:45 +08007618 /**
7619 * {@hide}
7620 * Returns the IMS Registration Status on a particular subid
7621 *
7622 * @param subId
7623 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007624 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007625 Phone phone = getPhone(subId);
7626 if (phone != null) {
7627 return phone.isImsRegistered();
7628 } else {
7629 return false;
7630 }
7631 }
7632
Santos Cordon7a1885b2015-02-03 11:15:19 -08007633 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007634 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007635 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007637 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007638 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7639 }
7640 final long identity = Binder.clearCallingIdentity();
7641 try {
7642 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7643 } finally {
7644 Binder.restoreCallingIdentity(identity);
7645 }
7646 }
7647
7648 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007649 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007650 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007651 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007652 mApp,
7653 subscriptionId,
7654 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007655 final long identity = Binder.clearCallingIdentity();
7656 try {
7657 Phone phone = getPhone(subscriptionId);
7658 if (phone == null) {
7659 return null;
7660 }
7661 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7662 } finally {
7663 Binder.restoreCallingIdentity(identity);
7664 }
7665 }
7666
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007667 /**
7668 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007669 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007670 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 final long identity = Binder.clearCallingIdentity();
7672 try {
7673 Phone phone = getPhone(subId);
7674 if (phone != null) {
7675 return phone.isWifiCallingEnabled();
7676 } else {
7677 return false;
7678 }
7679 } finally {
7680 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007681 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007682 }
7683
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007684 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007685 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007686 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007687 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 Phone phone = getPhone(subId);
7691 if (phone != null) {
7692 return phone.isVideoEnabled();
7693 } else {
7694 return false;
7695 }
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007698 }
7699 }
7700
7701 /**
7702 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7703 * defined in {@link ImsRegistrationImplBase}.
7704 */
7705 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 Phone phone = getPhone(subId);
7709 if (phone != null) {
7710 return phone.getImsRegistrationTech();
7711 } else {
7712 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7713 }
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007716 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007717 }
7718
Stuart Scott8eef64f2015-04-08 15:13:54 -07007719 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007720 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007721 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007722 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7723 return;
7724 }
Kai Shif70f46f2021-03-03 13:59:46 -08007725 Phone defaultPhone = getDefaultPhone();
7726 if (defaultPhone != null) {
7727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7728 mApp, getDefaultPhone().getSubId(), "factoryReset");
7729 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007730 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007731
Svet Ganovcc087f82015-05-12 20:35:54 -07007732 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007733 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7734 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007735 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007736 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007737 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007738 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007739 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007740 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007741 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007742 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007743 // There has been issues when Sms raw table somehow stores orphan
7744 // fragments. They lead to garbled message when new fragments come
7745 // in and combined with those stale ones. In case this happens again,
7746 // user can reset all network settings which will clean up this table.
7747 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007748 // Clean up IMS settings as well here.
7749 int slotId = getSlotIndex(subId);
7750 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7751 ImsManager.getInstance(mApp, slotId).factoryReset();
7752 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007753
Kai Shif70f46f2021-03-03 13:59:46 -08007754 if (defaultPhone == null) {
7755 return;
7756 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007757 // Erase modem config if erase modem on network setting is enabled.
7758 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7759 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7760 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007761 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007762 }
Kai Shif70f46f2021-03-03 13:59:46 -08007763
7764 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007765 } finally {
7766 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007767 }
7768 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007769
SongFerngWangfd89b102021-05-27 22:44:54 +08007770 @VisibleForTesting
7771 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7772 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7773 return;
7774 }
7775 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7776 RILConstants.PREFERRED_NETWORK_MODE);
7777 SubscriptionManager.setSubscriptionProperty(subId,
7778 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7779 "user=" + defaultNetworkType);
7780 phone.loadAllowedNetworksFromSubscriptionDatabase();
7781 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7782 defaultNetworkType, null);
7783 }
7784
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007785 private void cleanUpSmsRawTable(Context context) {
7786 ContentResolver resolver = context.getContentResolver();
7787 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7788 resolver.delete(uri, null, null);
7789 }
7790
Narayan Kamath1c496c22015-04-16 14:40:19 +01007791 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007792 public String getSimLocaleForSubscriber(int subId) {
7793 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7794 final Phone phone = getPhone(subId);
7795 if (phone == null) {
7796 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007797 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799 final long identity = Binder.clearCallingIdentity();
7800 try {
chen xu5d3637b2019-01-21 23:31:38 -08007801 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007802 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007803 if (info == null) {
7804 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7805 return null;
7806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807 // Try and fetch the locale from the carrier properties or from the SIM language
7808 // preferences (EF-PL and EF-LI)...
7809 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007811 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7812 if (localeFromDefaultSim != null) {
7813 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7814 if (DBG) log("Using locale from subId: " + subId + " locale: "
7815 + localeFromDefaultSim);
7816 return localeFromDefaultSim.toLanguageTag();
7817 } else {
7818 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 }
7820 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 // The SIM language preferences only store a language (e.g. fr = French), not an
7823 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7824 // the SIM and carrier preferences does not include a country we add the country
7825 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007826 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007828 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 return mccLocale.toLanguageTag();
7830 }
7831
7832 if (DBG) log("No locale found - returning null");
7833 return null;
7834 } finally {
7835 Binder.restoreCallingIdentity(identity);
7836 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007837 }
7838
7839 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007840 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007841 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007842 }
7843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 /**
7845 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7846 */
7847 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007848 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007849 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007850 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007851
Gary Jian3aa9a762022-01-24 16:41:19 +08007852 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7853 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007854
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007855 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007856 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7857 * representing the state of the modem.
7858 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007859 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7860 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007861 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007862 */
7863 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007864 public void requestModemActivityInfo(ResultReceiver result) {
7865 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007866 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007870 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 } finally {
7872 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007873 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007874 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007875
Siddharth Rayb8114062018-06-17 15:02:38 -07007876 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7877 // less than total activity duration.
7878 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7879 if (info == null) {
7880 return false;
7881 }
7882 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007883 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7884 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7885
Siddharth Rayb8114062018-06-17 15:02:38 -07007886 return (info.isValid()
7887 && (info.getSleepTimeMillis() <= activityDurationMs)
7888 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007889 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007890 && (totalTxTimeMs <= activityDurationMs));
7891 }
7892
Gary Jian3aa9a762022-01-24 16:41:19 +08007893 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7894 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7895 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7896 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7897
7898 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7899 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7900 }
7901
7902 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7903 mLastModemActivityInfo.setReceiveTimeMillis(
7904 rat,
7905 freq,
7906 info.getReceiveTimeMillis(rat, freq)
7907 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7908 }
7909
7910 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7911 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7912 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7913 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7914
7915 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7916 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7917 }
7918 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7919 mLastModemActivityInfo.setReceiveTimeMillis(
7920 rat,
7921 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7922 }
7923
7924 /**
7925 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7926 * @param info recent ModemActivityInfo
7927 */
7928 private void mergeModemActivityInfo(ModemActivityInfo info) {
7929 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7930 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7931 boolean matched;
7932 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7933 matched = false;
7934 int rat = info.getSpecificInfoRat(i);
7935 int freq = info.getSpecificInfoFrequencyRange(i);
7936 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7937 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7938 //if it already exists
7939 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7940 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7941 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7942 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7943 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7944 updateLastModemActivityInfo(info, rat, freq);
7945 matched = true;
7946 }
7947 } else {
7948 updateLastModemActivityInfo(info, rat);
7949 matched = true;
7950 }
7951 }
7952 }
7953
7954 if (!matched) {
7955 mDeltaSpecificInfo =
7956 new ActivityStatsTechSpecificInfo(
7957 rat,
7958 freq,
7959 info.getTransmitTimeMillis(rat, freq),
7960 (int) info.getReceiveTimeMillis(rat, freq));
7961 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7962 }
7963 }
7964 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7965 mLastModemActivitySpecificInfo =
7966 new ActivityStatsTechSpecificInfo[merged.size()];
7967 merged.toArray(mLastModemActivitySpecificInfo);
7968
7969 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7970 mLastModemActivityInfo.setSleepTimeMillis(
7971 info.getSleepTimeMillis()
7972 + mLastModemActivityInfo.getSleepTimeMillis());
7973 mLastModemActivityInfo.setIdleTimeMillis(
7974 info.getIdleTimeMillis()
7975 + mLastModemActivityInfo.getIdleTimeMillis());
7976 }
7977
Jack Yu85bd38a2015-11-09 11:34:32 -08007978 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007979 * Returns the service state information on specified subscription.
7980 */
7981 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007982 public ServiceState getServiceStateForSubscriber(int subId,
7983 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7984 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007986 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007987 return null;
7988 }
7989
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007990 boolean hasFinePermission = false;
7991 boolean hasCoarsePermission = false;
7992 if (!renounceFineLocationAccess) {
7993 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7994 LocationAccessPolicy.checkLocationPermission(mApp,
7995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7996 .setCallingPackage(callingPackage)
7997 .setCallingFeatureId(callingFeatureId)
7998 .setCallingPid(Binder.getCallingPid())
7999 .setCallingUid(Binder.getCallingUid())
8000 .setMethod("getServiceStateForSubscriber")
8001 .setLogAsInfo(true)
8002 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8003 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8004 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8005 .build());
8006 hasFinePermission =
8007 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8008 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008009
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008010 if (!renounceCoarseLocationAccess) {
8011 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8012 LocationAccessPolicy.checkLocationPermission(mApp,
8013 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8014 .setCallingPackage(callingPackage)
8015 .setCallingFeatureId(callingFeatureId)
8016 .setCallingPid(Binder.getCallingPid())
8017 .setCallingUid(Binder.getCallingUid())
8018 .setMethod("getServiceStateForSubscriber")
8019 .setLogAsInfo(true)
8020 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8021 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8022 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8023 .build());
8024 hasCoarsePermission =
8025 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8026 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008027
Jack Yu479f40e2020-10-27 21:29:25 -07008028 final Phone phone = getPhone(subId);
8029 if (phone == null) {
8030 return null;
8031 }
8032
Jordan Liu0f2bc442020-11-18 16:47:37 -08008033 final long identity = Binder.clearCallingIdentity();
8034
Jack Yu479f40e2020-10-27 21:29:25 -07008035 boolean isCallingPackageDataService = phone.getDataServicePackages()
8036 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008038 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8039 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8040 Rlog.d(LOG_TAG,
8041 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8042 return null;
8043 }
8044
Hall Liuf19c44f2018-11-27 14:38:17 -08008045 ServiceState ss = phone.getServiceState();
8046
8047 // Scrub out the location info in ServiceState depending on what level of access
8048 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008049 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008050 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8051 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 } finally {
8053 Binder.restoreCallingIdentity(identity);
8054 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008055 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008056
8057 /**
8058 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8059 *
8060 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8061 * voicemail ringtone.
8062 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8063 * PhoneAccount.
8064 */
8065 @Override
8066 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 final long identity = Binder.clearCallingIdentity();
8068 try {
8069 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8070 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008071 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8075 } finally {
8076 Binder.restoreCallingIdentity(identity);
8077 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008078 }
8079
8080 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008081 * Sets the per-account voicemail ringtone.
8082 *
8083 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8084 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8085 *
8086 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8087 * voicemail ringtone.
8088 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8089 * PhoneAccount.
8090 */
8091 @Override
8092 public void setVoicemailRingtoneUri(String callingPackage,
8093 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008094 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008095 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008096 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8097 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8099 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8100 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102
8103 final long identity = Binder.clearCallingIdentity();
8104 try {
8105 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8106 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008107 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 }
8109 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8110 } finally {
8111 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008112 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008113 }
8114
8115 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008116 * Returns whether vibration is set for voicemail notification in Phone settings.
8117 *
8118 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8119 * voicemail vibration setting.
8120 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8121 */
8122 @Override
8123 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 final long identity = Binder.clearCallingIdentity();
8125 try {
8126 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8127 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008128 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
8134 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008135 }
8136
Youhan Wange64578a2016-05-02 15:32:42 -07008137 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008138 * Sets the per-account voicemail vibration.
8139 *
8140 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8141 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8142 *
8143 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8144 * voicemail vibration setting.
8145 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8146 * specific PhoneAccount.
8147 */
8148 @Override
8149 public void setVoicemailVibrationEnabled(String callingPackage,
8150 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008151 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008152 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008153 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8154 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8156 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8157 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008158 }
8159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008160 final long identity = Binder.clearCallingIdentity();
8161 try {
8162 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8163 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008164 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165 }
8166 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8167 } finally {
8168 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008169 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008170 }
8171
8172 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008173 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8174 *
8175 * @throws SecurityException if the caller does not have the required permission
8176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008177 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008178 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008179 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008180 }
8181
8182 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008183 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8184 * permission.
8185 *
8186 * @throws SecurityException if the caller does not have the required permission
8187 */
8188 private void enforceSendSmsPermission() {
8189 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8190 }
8191
8192 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008193 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008194 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008195 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008196 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008197 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198 final long identity = Binder.clearCallingIdentity();
8199 try {
8200 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008201 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008202 if (componentName == null) {
8203 throw new SecurityException(
8204 "Caller not current active visual voicemail package[null]");
8205 }
8206 String vvmPackage = componentName.getPackageName();
8207 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008208 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 }
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008212 }
8213 }
8214
8215 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008216 * Return the application ID for the app type.
8217 *
8218 * @param subId the subscription ID that this request applies to.
8219 * @param appType the uicc app type.
8220 * @return Application ID for specificied app type, or null if no uicc.
8221 */
8222 @Override
8223 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008224 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008225 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226
8227 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008228 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229 if (phone == null) {
8230 return null;
8231 }
8232 String aid = null;
8233 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008234 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 .getApplicationByType(appType).getAid();
8236 } catch (Exception e) {
8237 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8238 }
8239 return aid;
8240 } finally {
8241 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008242 }
Youhan Wange64578a2016-05-02 15:32:42 -07008243 }
8244
Youhan Wang4001d252016-05-11 10:29:41 -07008245 /**
8246 * Return the Electronic Serial Number.
8247 *
8248 * @param subId the subscription ID that this request applies to.
8249 * @return ESN or null if error.
8250 */
8251 @Override
8252 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008253 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008254 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255
8256 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008257 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 if (phone == null) {
8259 return null;
8260 }
8261 String esn = null;
8262 try {
8263 esn = phone.getEsn();
8264 } catch (Exception e) {
8265 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8266 }
8267 return esn;
8268 } finally {
8269 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008270 }
Youhan Wang4001d252016-05-11 10:29:41 -07008271 }
8272
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008273 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008274 * Return the Preferred Roaming List Version.
8275 *
8276 * @param subId the subscription ID that this request applies to.
8277 * @return PRLVersion or null if error.
8278 */
8279 @Override
8280 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008281 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008282 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283
8284 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008285 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 if (phone == null) {
8287 return null;
8288 }
8289 String cdmaPrlVersion = null;
8290 try {
8291 cdmaPrlVersion = phone.getCdmaPrlVersion();
8292 } catch (Exception e) {
8293 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8294 }
8295 return cdmaPrlVersion;
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008298 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008299 }
8300
8301 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008302 * Get snapshot of Telephony histograms
8303 * @return List of Telephony histograms
8304 * @hide
8305 */
8306 @Override
8307 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8309 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
8313 return RIL.getTelephonyRILTimingHistograms();
8314 } finally {
8315 Binder.restoreCallingIdentity(identity);
8316 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008317 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008318
8319 /**
8320 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008321 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8322 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008323 * Require system privileges. In the future we may add this to carrier APIs.
8324 *
Michele Berionne482f8202018-11-27 18:57:59 -08008325 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008326 */
8327 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008328 @TelephonyManager.SetCarrierRestrictionResult
8329 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008330 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008332
Michele Berionne482f8202018-11-27 18:57:59 -08008333 if (carrierRestrictionRules == null) {
8334 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008335 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 final long identity = Binder.clearCallingIdentity();
8338 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008339 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008340 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008344 }
8345
8346 /**
8347 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008348 * Get the allowed carrier list and the excluded carrier list, including the priority between
8349 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008350 * Require system privileges. In the future we may add this to carrier APIs.
8351 *
Michele Berionne482f8202018-11-27 18:57:59 -08008352 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008353 */
8354 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008355 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008356 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358
8359 final long identity = Binder.clearCallingIdentity();
8360 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008361 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8362 if (response instanceof CarrierRestrictionRules) {
8363 return (CarrierRestrictionRules) response;
8364 }
8365 // Response is an Exception of some kind,
8366 // which is signalled to the user as a NULL retval
8367 return null;
8368 } catch (Exception e) {
8369 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8370 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 } finally {
8372 Binder.restoreCallingIdentity(identity);
8373 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008374 }
8375
fionaxu59545b42016-05-25 15:53:37 -07008376 /**
fionaxu59545b42016-05-25 15:53:37 -07008377 * Action set from carrier signalling broadcast receivers to enable/disable radio
8378 * @param subId the subscription ID that this action applies to.
8379 * @param enabled control enable or disable radio.
8380 * {@hide}
8381 */
8382 @Override
8383 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8384 enforceModifyPermission();
8385 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386
8387 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008388 if (phone == null) {
8389 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8390 return;
8391 }
8392 try {
8393 phone.carrierActionSetRadioEnabled(enabled);
8394 } catch (Exception e) {
8395 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 } finally {
8397 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008398 }
8399 }
8400
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008401 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008402 * Enable or disable Voice over NR (VoNR)
8403 * @param subId the subscription ID that this action applies to.
8404 * @param enabled enable or disable VoNR.
8405 * @return operation result.
8406 */
8407 @Override
8408 public int setVoNrEnabled(int subId, boolean enabled) {
8409 enforceModifyPermission();
8410 final Phone phone = getPhone(subId);
8411
8412 final long identity = Binder.clearCallingIdentity();
8413 if (phone == null) {
8414 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8415 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8416 }
8417
8418 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8419 try {
8420 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8421 workSource);
8422 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008423
8424 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8425 if (DBG) {
8426 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8427 }
8428 SubscriptionManager.setSubscriptionProperty(
8429 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8430 (enabled ? "1" : "0"));
8431 }
8432
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008433 return result;
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
8437 }
8438
8439 /**
8440 * Is voice over NR enabled
8441 * @return true if VoNR is enabled else false
8442 */
8443 @Override
8444 public boolean isVoNrEnabled(int subId) {
8445 enforceReadPrivilegedPermission("isVoNrEnabled");
8446 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8447 final long identity = Binder.clearCallingIdentity();
8448 try {
8449 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8450 null, subId, workSource);
8451 if (DBG) log("isVoNrEnabled: " + isEnabled);
8452 return isEnabled;
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
8455 }
8456 }
8457
8458 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008459 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8460 * network status based on which carrier apps could apply actions accordingly,
8461 * enable/disable default url handler for example.
8462 *
8463 * @param subId the subscription ID that this action applies to.
8464 * @param report control start/stop reporting the default network status.
8465 * {@hide}
8466 */
8467 @Override
8468 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8469 enforceModifyPermission();
8470 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471
8472 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008473 if (phone == null) {
8474 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8475 return;
8476 }
8477 try {
8478 phone.carrierActionReportDefaultNetworkStatus(report);
8479 } catch (Exception e) {
8480 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008481 } finally {
8482 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008483 }
8484 }
8485
8486 /**
fionaxud9622282017-07-17 17:51:30 -07008487 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8488 * @param subId the subscription ID that this action applies to.
8489 * {@hide}
8490 */
8491 @Override
8492 public void carrierActionResetAll(int subId) {
8493 enforceModifyPermission();
8494 final Phone phone = getPhone(subId);
8495 if (phone == null) {
8496 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8497 return;
8498 }
8499 try {
8500 phone.carrierActionResetAll();
8501 } catch (Exception e) {
8502 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8503 }
8504 }
8505
8506 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008507 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8508 * bug report is being generated.
8509 */
8510 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008511 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008512 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8513 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008514 writer.println("Permission Denial: can't dump Phone from pid="
8515 + Binder.getCallingPid()
8516 + ", uid=" + Binder.getCallingUid()
8517 + "without permission "
8518 + android.Manifest.permission.DUMP);
8519 return;
8520 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008521 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008522 }
Jack Yueb89b242016-06-22 13:27:47 -07008523
Brad Ebingerdac2f002018-04-03 15:17:52 -07008524 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008525 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8526 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8527 @NonNull String[] args) {
8528 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8529 this, in.getFileDescriptor(), out.getFileDescriptor(),
8530 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008531 }
8532
Jack Yueb89b242016-06-22 13:27:47 -07008533 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008534 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008535 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008536 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008537 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008538 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008539 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008540 */
8541 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008542 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008543 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008544 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8545 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8546 try {
8547 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008548 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008549 } catch (SecurityException se) {
8550 enforceModifyPermission();
8551 }
8552 } else {
8553 enforceModifyPermission();
8554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 Phone phone = getPhone(subId);
8559 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008560 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8561 phone.carrierActionSetMeteredApnsEnabled(enabled);
8562 } else {
Jack Yuf745f972022-08-15 19:53:50 +00008563 if (phone.isUsingNewDataStack()) {
8564 phone.getDataSettingsManager().setDataEnabled(
8565 reason, enabled, callingPackage);
8566 } else {
8567 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8568 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570 }
8571 } finally {
8572 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008573 }
8574 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008575
8576 /**
8577 * Get Client request stats
8578 * @return List of Client Request Stats
8579 * @hide
8580 */
8581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008582 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8583 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008585 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008586 return null;
8587 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008588 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590 final long identity = Binder.clearCallingIdentity();
8591 try {
8592 if (phone != null) {
8593 return phone.getClientRequestStats();
8594 }
8595
8596 return null;
8597 } finally {
8598 Binder.restoreCallingIdentity(identity);
8599 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008600 }
8601
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008602 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008603 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008604 if (uid == Process.ROOT_UID && packageName == null) {
8605 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8606 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8607 // exception. ROOT_UID seems not to have a valid package name returned by
8608 // PackageManager, so just fake it here to avoid issues when running telephony shell
8609 // commands that plumb through the RIL as root, like so:
8610 // $ adb root
8611 // $ adb shell cmd phone ...
8612 packageName = "root";
8613 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008614 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008615 }
Jack Yueb4124c2017-02-16 15:32:43 -08008616
8617 /**
Grace Chen70990072017-03-24 17:21:30 -07008618 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008619 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008620 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008621 * @param state State of SIM (power down, power up, pass through)
8622 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8623 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8624 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008625 *
8626 **/
8627 @Override
Grace Chen70990072017-03-24 17:21:30 -07008628 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008629 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008630 Phone phone = PhoneFactory.getPhone(slotIndex);
8631
vagdeviaf9a5b92018-08-15 16:01:53 -07008632 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008634 final long identity = Binder.clearCallingIdentity();
8635 try {
8636 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008637 phone.setSimPowerState(state, null, workSource);
8638 }
8639 } finally {
8640 Binder.restoreCallingIdentity(identity);
8641 }
8642 }
8643
8644 /**
8645 * Set SIM card power state.
8646 *
8647 * @param slotIndex SIM slot id.
8648 * @param state State of SIM (power down, power up, pass through)
8649 * @param callback callback to trigger after success or failure
8650 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8651 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8652 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8653 *
8654 **/
8655 @Override
8656 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8657 IIntegerConsumer callback) {
8658 enforceModifyPermission();
8659 Phone phone = PhoneFactory.getPhone(slotIndex);
8660
8661 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8662
8663 final long identity = Binder.clearCallingIdentity();
8664 try {
8665 if (phone != null) {
8666 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8667 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008668 }
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008671 }
8672 }
Shuo Qiandd210312017-04-12 22:11:33 +00008673
Tyler Gunn65d45c22017-06-05 11:22:26 -07008674 private boolean isUssdApiAllowed(int subId) {
8675 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008676 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008677 if (configManager == null) {
8678 return false;
8679 }
8680 PersistableBundle pb = configManager.getConfigForSubId(subId);
8681 if (pb == null) {
8682 return false;
8683 }
8684 return pb.getBoolean(
8685 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8686 }
8687
Shuo Qiandd210312017-04-12 22:11:33 +00008688 /**
8689 * Check if phone is in emergency callback mode
8690 * @return true if phone is in emergency callback mode
8691 * @param subId sub id
8692 */
goneil9c5f4872017-12-05 14:07:56 -08008693 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008694 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008695 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008696 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008697
8698 final long identity = Binder.clearCallingIdentity();
8699 try {
8700 if (phone != null) {
8701 return phone.isInEcm();
8702 } else {
8703 return false;
8704 }
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008707 }
8708 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008709
8710 /**
8711 * Get the current signal strength information for the given subscription.
8712 * Because this information is not updated when the device is in a low power state
8713 * it should not be relied-upon to be current.
8714 * @param subId Subscription index
8715 * @return the most recent cached signal strength info from the modem
8716 */
8717 @Override
8718 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 Phone p = getPhone(subId);
8722 if (p == null) {
8723 return null;
8724 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008726 return p.getSignalStrength();
8727 } finally {
8728 Binder.restoreCallingIdentity(identity);
8729 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008730 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008731
Pengquan Meng77b7f132018-08-22 14:49:57 -07008732 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008733 * Get the current modem radio state for the given slot.
8734 * @param slotIndex slot index.
8735 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008736 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008737 * @return the current radio power state from the modem
8738 */
8739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008740 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008741 Phone phone = PhoneFactory.getPhone(slotIndex);
8742 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8744 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008745 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8746 }
8747
8748 final long identity = Binder.clearCallingIdentity();
8749 try {
8750 return phone.getRadioPowerState();
8751 } finally {
8752 Binder.restoreCallingIdentity(identity);
8753 }
8754 }
8755 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8756 }
8757
8758 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008759 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8760 *
8761 * <p>Requires one of the following permissions:
8762 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008763 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008764 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8765 * privileges.
8766 *
8767 * @param subId subscription id
8768 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8769 * {@code false}.
8770 */
8771 @Override
8772 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008773 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008774 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008775 try {
8776 mApp.enforceCallingOrSelfPermission(
8777 android.Manifest.permission.ACCESS_NETWORK_STATE,
8778 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008779 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008780 mApp.enforceCallingOrSelfPermission(
8781 permission.READ_BASIC_PHONE_STATE, functionName);
8782 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008783 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008784 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008785 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008786 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008787
Pengquan Menga1bb6272018-09-06 09:59:22 -07008788 boolean isEnabled = false;
8789 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008790 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008791 Phone phone = getPhone(subId);
8792 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008793 } finally {
8794 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008795 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008796 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008797 }
8798
8799
8800 /**
8801 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8802 *
8803 * <p> Requires permission:
8804 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8805 * privileges.
8806 *
8807 * @param subId subscription id
8808 * @param isEnabled {@code true} means enable, {@code false} means disable.
8809 */
8810 @Override
8811 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8813 mApp, subId, "setDataRoamingEnabled");
8814
Pengquan Menga1bb6272018-09-06 09:59:22 -07008815 final long identity = Binder.clearCallingIdentity();
8816 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008817 Phone phone = getPhone(subId);
8818 if (phone != null) {
8819 phone.setDataRoamingEnabled(isEnabled);
8820 }
8821 } finally {
8822 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008823 }
8824 }
8825
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008826 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008827 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008828 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008829 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008830 mApp, subId, "isManualNetworkSelectionAllowed");
8831
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008832 boolean isAllowed = true;
8833 final long identity = Binder.clearCallingIdentity();
8834 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008835 Phone phone = getPhone(subId);
8836 if (phone != null) {
8837 isAllowed = phone.isCspPlmnEnabled();
8838 }
8839 } finally {
8840 Binder.restoreCallingIdentity(identity);
8841 }
8842 return isAllowed;
8843 }
8844
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008845 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8846 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008847 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008848 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008849 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008850 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8851 if (phone == null) {
8852 return false;
8853 }
8854 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8855 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8856 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008857 }
8858
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008859 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008860 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008861 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008862 mApp.getSystemService(AppOpsManager.class)
8863 .checkPackage(Binder.getCallingUid(), callingPackage);
8864
Jordan Liu1e142fc2019-04-22 15:10:43 -07008865 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008866 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008867 try {
8868 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008869 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008870 } catch (SecurityException e) {
8871 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8872 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008873 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008874 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008875 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008876 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008877 }
sandeepjsb6c87872021-09-27 15:34:44 +00008878 // checking compatibility, if calling app's target SDK is T and beyond.
8879 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8880 Binder.getCallingUid())) {
8881 isIccIdAccessRestricted = true;
8882 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008883 final long identity = Binder.clearCallingIdentity();
8884 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008885 UiccController uiccController = UiccController.getInstance();
8886 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008887 if (hasReadPermission) {
8888 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008889 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008890
8891 // Remove private info if the caller doesn't have access
8892 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8893 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008894 //setting the value after compatibility check
8895 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008896 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8897 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008898 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008899 if (card == null) {
8900 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008901 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008902 continue;
8903 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008904 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8905 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008906 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008907 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008908 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008909 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8910 for (UiccPortInfo portInfo : portInfos) {
8911 UiccPort port = uiccController.getUiccPortForSlot(
8912 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8913 if (port == null) {
8914 // assume no access if port is null
8915 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8916 continue;
8917 }
8918 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8919 uiccPortInfos.add(portInfo);
8920 } else {
8921 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8922 }
8923 }
8924 filteredInfos.add(new UiccCardInfo(
8925 cardInfo.isEuicc(),
8926 cardInfo.getCardId(),
8927 null,
8928 cardInfo.getPhysicalSlotIndex(),
8929 cardInfo.isRemovable(),
8930 cardInfo.isMultipleEnabledProfilesSupported(),
8931 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008932 }
8933 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008934 } finally {
8935 Binder.restoreCallingIdentity(identity);
8936 }
8937 }
8938
sandeepjsb6c87872021-09-27 15:34:44 +00008939 /**
8940 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8941 * generally private and require carrier privileges to view.
8942 *
8943 * @hide
8944 */
8945 @NonNull
8946 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8947 List<UiccPortInfo> portinfo = new ArrayList<>();
8948 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8949 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8950 }
8951 return new UiccCardInfo(
8952 cardInfo.isEuicc(),
8953 cardInfo.getCardId(),
8954 null,
8955 cardInfo.getPhysicalSlotIndex(),
8956 cardInfo.isRemovable(),
8957 cardInfo.isMultipleEnabledProfilesSupported(),
8958 portinfo
8959 );
8960 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008961
sandeepjsb6c87872021-09-27 15:34:44 +00008962 /**
8963 * @hide
8964 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8965 * These values are generally private and require carrier privileges to view.
8966 */
8967 @NonNull
8968 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8969 return new UiccPortInfo(
8970 UiccPortInfo.ICCID_REDACTED,
8971 portInfo.getPortIndex(),
8972 portInfo.getLogicalSlotIndex(),
8973 portInfo.isActive()
8974 );
8975 }
8976 @Override
8977 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008978 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008979 mApp.getSystemService(AppOpsManager.class)
8980 .checkPackage(Binder.getCallingUid(), callingPackage);
8981
sandeepjsb6c87872021-09-27 15:34:44 +00008982 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008983
Aman Guptaf3c90b32022-03-17 04:54:16 +00008984 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8985 // we are reading iccId which is PII data.
8986 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008987
8988 // checking compatibility, if calling app's target SDK is T and beyond.
8989 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8990 Binder.getCallingUid())) {
8991 isLogicalSlotAccessRestricted = true;
8992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008996 if (slots == null || slots.length == 0) {
8997 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008998 return null;
8999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009000 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9001 for (int i = 0; i < slots.length; i++) {
9002 UiccSlot slot = slots[i];
9003 if (slot == null) {
9004 continue;
9005 }
9006
Jordan Liu7be7e652019-05-06 18:55:02 +00009007 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009008 UiccCard card = slot.getUiccCard();
9009 if (card != null) {
9010 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009011 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009012 cardId = slot.getEid();
9013 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009014 // If cardId is null, use iccId of default port as cardId.
9015 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009017 }
9018
Jordan Liu857451f2019-05-09 16:35:35 -07009019 if (cardId != null) {
9020 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9021 // if cardId is an EID, it's all digits so this is fine
9022 cardId = IccUtils.stripTrailingFs(cardId);
9023 }
9024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009025 int cardState = 0;
9026 switch (slot.getCardState()) {
9027 case CARDSTATE_ABSENT:
9028 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9029 break;
9030 case CARDSTATE_PRESENT:
9031 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9032 break;
9033 case CARDSTATE_ERROR:
9034 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9035 break;
9036 case CARDSTATE_RESTRICTED:
9037 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9038 break;
9039 default:
9040 break;
9041
9042 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009043 List<UiccPortInfo> portInfos = new ArrayList<>();
9044 int[] portIndexes = slot.getPortList();
9045 for (int portIdx : portIndexes) {
9046 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009047 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009048 portInfos.add(new UiccPortInfo(iccId, portIdx,
9049 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009051 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009052 slot.isEuicc(),
9053 cardId,
9054 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009055 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009056 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009057 //setting the value after compatibility check
9058 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009059 }
9060 return infos;
9061 } finally {
9062 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009063 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009064 }
9065
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009066 /* Returns null if doesn't have read permission or carrier privilege access. */
9067 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9068 boolean hasReadPermission) {
9069 String iccId = slot.getIccId(portIndex);
9070 if (hasReadPermission) { // if has read permission
9071 return iccId;
9072 } else {
9073 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9074 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9075 // if no read permission, checking carrier privilege access
9076 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9077 return iccId;
9078 }
9079 }
9080 }
9081 // No read permission or carrier privilege access.
9082 return UiccPortInfo.ICCID_REDACTED;
9083 }
9084
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009085 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009086 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009087 public boolean switchSlots(int[] physicalSlots) {
9088 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009089
9090 final long identity = Binder.clearCallingIdentity();
9091 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009092 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9093 for (int i = 0; i < physicalSlots.length; i++) {
9094 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9095 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9096 physicalSlots[i], i));
9097 }
9098 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009099 } finally {
9100 Binder.restoreCallingIdentity(identity);
9101 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009102 }
Jack Yu4c988042018-02-27 15:30:01 -08009103
9104 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009105 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9106 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9107 enforceModifyPermission();
9108
9109 final long identity = Binder.clearCallingIdentity();
9110 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009111 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009112 } finally {
9113 Binder.restoreCallingIdentity(identity);
9114 }
9115 }
9116
9117 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009118 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009119 final long identity = Binder.clearCallingIdentity();
9120 try {
9121 return UiccController.getInstance().getCardIdForDefaultEuicc();
9122 } finally {
9123 Binder.restoreCallingIdentity(identity);
9124 }
9125 }
9126
Pengquan Meng85728fb2018-03-12 16:31:21 -07009127 /**
goneil47ffb6e2018-04-06 15:40:58 -07009128 * A test API to reload the UICC profile.
9129 *
9130 * <p>Requires that the calling app has permission
9131 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9132 * @hide
9133 */
9134 @Override
9135 public void refreshUiccProfile(int subId) {
9136 enforceModifyPermission();
9137
9138 final long identity = Binder.clearCallingIdentity();
9139 try {
9140 Phone phone = getPhone(subId);
9141 if (phone == null) {
9142 return;
9143 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009144 UiccPort uiccPort = phone.getUiccPort();
9145 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009146 return;
9147 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009148 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009149 if (uiccProfile == null) {
9150 return;
9151 }
9152 uiccProfile.refresh();
9153 } finally {
9154 Binder.restoreCallingIdentity(identity);
9155 }
9156 }
9157
9158 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009159 * Returns false if the mobile data is disabled by default, otherwise return true.
9160 */
9161 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009162 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009163 }
9164
9165 /**
9166 * Returns true if the data roaming is enabled by default, i.e the system property
9167 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9168 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9169 */
9170 private boolean getDefaultDataRoamingEnabled(int subId) {
9171 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009172 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009173 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009174 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9175 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9176 return isDataRoamingEnabled;
9177 }
9178
9179 /**
9180 * Returns the default network type for the given {@code subId}, if the default network type is
9181 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9182 */
9183 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009184 List<Integer> list = TelephonyProperties.default_network();
9185 int phoneId = mSubscriptionController.getPhoneId(subId);
9186 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9187 return list.get(phoneId);
9188 }
9189 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009190 }
fionaxua13278b2018-03-21 00:08:13 -07009191
9192 @Override
9193 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009194 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009196
9197 final long identity = Binder.clearCallingIdentity();
9198 try {
9199 final Phone phone = getPhone(subId);
9200 if (phone == null) {
9201 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9202 return;
9203 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009204 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9205 if (cpt != null) {
9206 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9207 }
9208 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009209 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9210 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009211 if (carrierPrivilegeRules == null) {
9212 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9213 } else {
9214 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009216 } finally {
9217 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009218 }
fionaxua13278b2018-03-21 00:08:13 -07009219 }
9220
9221 @Override
9222 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009223 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009224
9225 final long identity = Binder.clearCallingIdentity();
9226 try {
9227 final Phone phone = getPhone(subId);
9228 if (phone == null) {
9229 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9230 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9231 }
9232 return phone.getCarrierIdListVersion();
9233 } finally {
9234 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009235 }
fionaxua13278b2018-03-21 00:08:13 -07009236 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009237
9238 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009239 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9240 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009242 mApp, subId, callingPackage, callingFeatureId,
9243 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009244 return -1;
9245 }
9246
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9250 } finally {
9251 Binder.restoreCallingIdentity(identity);
9252 }
9253 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009254
9255 @Override
9256 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009257 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009258 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009259 mApp, subId, "getCdmaRoamingMode");
9260
9261 final long identity = Binder.clearCallingIdentity();
9262 try {
9263 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267 }
9268
9269 @Override
9270 public boolean setCdmaRoamingMode(int subId, int mode) {
9271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9272 mApp, subId, "setCdmaRoamingMode");
9273
9274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9277 } finally {
9278 Binder.restoreCallingIdentity(identity);
9279 }
9280 }
9281
9282 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009283 public int getCdmaSubscriptionMode(int subId) {
9284 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009285 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009286 mApp, subId, "getCdmaSubscriptionMode");
9287
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9291 } finally {
9292 Binder.restoreCallingIdentity(identity);
9293 }
9294 }
9295
9296 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009297 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9299 mApp, subId, "setCdmaSubscriptionMode");
9300
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
9303 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009308
sqianc5eccab2018-10-19 18:46:41 -07009309 @Override
sqian8c685422019-02-22 15:55:18 -08009310 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009311 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009313 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9314 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009315 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9316 }
9317 final long identity = Binder.clearCallingIdentity();
9318 try {
sqian854d44b2018-12-12 16:48:18 -08009319 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9320 for (Phone phone: PhoneFactory.getPhones()) {
9321 if (phone.getEmergencyNumberTracker() != null
9322 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9323 emergencyNumberListInternal.put(
9324 phone.getSubId(),
9325 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9326 }
sqian11b7a0e2018-12-05 18:48:28 -08009327 }
sqian854d44b2018-12-12 16:48:18 -08009328 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009329 } finally {
9330 Binder.restoreCallingIdentity(identity);
9331 }
sqianc5eccab2018-10-19 18:46:41 -07009332 }
9333
9334 @Override
sqian8c685422019-02-22 15:55:18 -08009335 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009336 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009337 if (!exactMatch) {
9338 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009339 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009340 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009341 }
9342 final long identity = Binder.clearCallingIdentity();
9343 try {
sqian854d44b2018-12-12 16:48:18 -08009344 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009345 //Note: we ignore passed in param exactMatch. We can remove it once
9346 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009347 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009348 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009349 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009350 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009351 }
sqian11b7a0e2018-12-05 18:48:28 -08009352 }
9353 return false;
9354 } finally {
9355 Binder.restoreCallingIdentity(identity);
9356 }
9357 }
9358
sqianf4ca7ed2019-01-15 18:32:07 -08009359 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009360 * Start emergency callback mode for GsmCdmaPhone for testing.
9361 */
9362 @Override
9363 public void startEmergencyCallbackMode() {
9364 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9365 "startEmergencyCallbackMode");
9366 enforceModifyPermission();
9367 final long identity = Binder.clearCallingIdentity();
9368 try {
9369 for (Phone phone : PhoneFactory.getPhones()) {
9370 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9371 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9372 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9373 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9374 gsmCdmaPhone.obtainMessage(
9375 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9376 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9377 }
9378 }
9379 } finally {
9380 Binder.restoreCallingIdentity(identity);
9381 }
9382 }
9383
9384 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009385 * Update emergency number list for test mode.
9386 */
9387 @Override
9388 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9389 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9390 "updateEmergencyNumberListTestMode");
9391
9392 final long identity = Binder.clearCallingIdentity();
9393 try {
9394 for (Phone phone: PhoneFactory.getPhones()) {
9395 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9396 if (tracker != null) {
9397 tracker.executeEmergencyNumberTestModeCommand(action, num);
9398 }
9399 }
9400 } finally {
9401 Binder.restoreCallingIdentity(identity);
9402 }
9403 }
9404
9405 /**
9406 * Get the full emergency number list for test mode.
9407 */
9408 @Override
9409 public List<String> getEmergencyNumberListTestMode() {
9410 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9411 "getEmergencyNumberListTestMode");
9412
9413 final long identity = Binder.clearCallingIdentity();
9414 try {
9415 Set<String> emergencyNumbers = new HashSet<>();
9416 for (Phone phone: PhoneFactory.getPhones()) {
9417 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9418 if (tracker != null) {
9419 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9420 emergencyNumbers.add(num.getNumber());
9421 }
9422 }
9423 }
9424 return new ArrayList<>(emergencyNumbers);
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
9429
chen xud6b45bd2018-10-30 22:27:10 -07009430 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009431 public int getEmergencyNumberDbVersion(int subId) {
9432 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9433
9434 final long identity = Binder.clearCallingIdentity();
9435 try {
9436 final Phone phone = getPhone(subId);
9437 if (phone == null) {
9438 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9439 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9440 }
9441 return phone.getEmergencyNumberDbVersion();
9442 } finally {
9443 Binder.restoreCallingIdentity(identity);
9444 }
9445 }
9446
9447 @Override
9448 public void notifyOtaEmergencyNumberDbInstalled() {
9449 enforceModifyPermission();
9450
9451 final long identity = Binder.clearCallingIdentity();
9452 try {
9453 for (Phone phone: PhoneFactory.getPhones()) {
9454 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9455 if (tracker != null) {
9456 tracker.updateOtaEmergencyNumberDatabase();
9457 }
9458 }
9459 } finally {
9460 Binder.restoreCallingIdentity(identity);
9461 }
9462 }
9463
9464 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009465 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009466 enforceActiveEmergencySessionPermission();
9467
9468 final long identity = Binder.clearCallingIdentity();
9469 try {
9470 for (Phone phone: PhoneFactory.getPhones()) {
9471 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9472 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009473 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9474 }
9475 }
9476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 }
9480
9481 @Override
9482 public void resetOtaEmergencyNumberDbFilePath() {
9483 enforceActiveEmergencySessionPermission();
9484
9485 final long identity = Binder.clearCallingIdentity();
9486 try {
9487 for (Phone phone: PhoneFactory.getPhones()) {
9488 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9489 if (tracker != null) {
9490 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009491 }
9492 }
9493 } finally {
9494 Binder.restoreCallingIdentity(identity);
9495 }
9496 }
9497
9498 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009499 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9500 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9501 Phone phone = getPhone(subId);
9502 if (phone == null) {
9503 return null;
9504 }
9505 final long identity = Binder.clearCallingIdentity();
9506 try {
9507 UiccProfile profile = UiccController.getInstance()
9508 .getUiccProfileForPhone(phone.getPhoneId());
9509 if (profile != null) {
9510 return profile.getCertsFromCarrierPrivilegeAccessRules();
9511 }
9512 } finally {
9513 Binder.restoreCallingIdentity(identity);
9514 }
9515 return null;
9516 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009517
9518 /**
9519 * Enable or disable a modem stack.
9520 */
9521 @Override
9522 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9523 enforceModifyPermission();
9524
9525 final long identity = Binder.clearCallingIdentity();
9526 try {
9527 Phone phone = PhoneFactory.getPhone(slotIndex);
9528 if (phone == null) {
9529 return false;
9530 } else {
9531 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9532 }
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
Michelecea4cf22018-12-21 15:00:11 -08009537
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009538 /**
9539 * Whether a modem stack is enabled or not.
9540 */
9541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009542 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9543 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009544 Phone phone = PhoneFactory.getPhone(slotIndex);
9545 if (phone == null) return false;
9546
9547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009548 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9549 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009550 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9551 }
9552
9553 final long identity = Binder.clearCallingIdentity();
9554 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009555 try {
9556 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9557 } catch (NoSuchElementException ex) {
9558 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9559 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563 }
9564
Michelecea4cf22018-12-21 15:00:11 -08009565 @Override
Michele0ea7d782019-03-19 14:58:42 -07009566 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009567 enforceModifyPermission();
9568
9569 final long identity = Binder.clearCallingIdentity();
9570 try {
9571 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009572 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009573 .commit();
9574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
9578
9579 @Override
Michele0ea7d782019-03-19 14:58:42 -07009580 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009581 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009583 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9584 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009585 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009586 }
Michelecea4cf22018-12-21 15:00:11 -08009587
9588 final long identity = Binder.clearCallingIdentity();
9589 try {
Michele0ea7d782019-03-19 14:58:42 -07009590 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009591 } finally {
9592 Binder.restoreCallingIdentity(identity);
9593 }
9594 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009595
Michele0ea7d782019-03-19 14:58:42 -07009596 @TelephonyManager.IsMultiSimSupportedResult
9597 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009598 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9599 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9600 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009601 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9602 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009603 }
9604 // Check if the hardware supports multisim functionality. If usage of multisim is not
9605 // supported by the modem, indicate that it is restricted.
9606 PhoneCapability staticCapability =
9607 mPhoneConfigurationManager.getStaticPhoneCapability();
9608 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009609 loge("isMultiSimSupportedInternal: no static configuration available");
9610 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009611 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009612 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009613 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9614 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009615 }
9616 // Check if support of multiple SIMs is restricted by carrier
9617 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009618 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009619 }
9620
Michele0ea7d782019-03-19 14:58:42 -07009621 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009622 }
9623
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009624 /**
9625 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009626 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9627 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9628 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009629 * @param numOfSims number of active sims we want to switch to
9630 */
9631 @Override
9632 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009633 if (numOfSims == 1) {
9634 enforceModifyPermission();
9635 } else {
9636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9637 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9638 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009639 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009640
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009641 try {
Michele30b57b22019-03-01 12:01:14 -08009642 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009643 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009644 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9645 return;
9646 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009647 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9648 } finally {
9649 Binder.restoreCallingIdentity(identity);
9650 }
9651 }
9652
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009653 @Override
9654 public boolean isApplicationOnUicc(int subId, int appType) {
9655 enforceReadPrivilegedPermission("isApplicationOnUicc");
9656 Phone phone = getPhone(subId);
9657 if (phone == null) {
9658 return false;
9659 }
9660 final long identity = Binder.clearCallingIdentity();
9661 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009662 UiccPort uiccPort = phone.getUiccPort();
9663 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009664 return false;
9665 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009666 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009667 if (uiccProfile == null) {
9668 return false;
9669 }
9670 if (TelephonyManager.APPTYPE_SIM <= appType
9671 && appType <= TelephonyManager.APPTYPE_ISIM) {
9672 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9673 }
9674 return false;
9675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
9679
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009680 /**
chen xub4baa772019-04-03 10:23:41 -07009681 * Get whether making changes to modem configurations will trigger reboot.
9682 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009683 */
9684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009685 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9686 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009688 mApp, subId, callingPackage, callingFeatureId,
9689 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009690 return false;
9691 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009692 final long identity = Binder.clearCallingIdentity();
9693 try {
9694 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9695 } finally {
9696 Binder.restoreCallingIdentity(identity);
9697 }
9698 }
9699
Nathan Harold29f5f052019-02-15 13:41:57 -08009700 private void updateModemStateMetrics() {
9701 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9702 // TODO: check the state for each modem if the api is ready.
9703 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9704 }
9705
Pengquan Meng3889a572019-01-23 11:16:29 -08009706 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009707 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009708 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009709 // Verify that the callingPackage belongs to the calling UID
9710 mApp.getSystemService(AppOpsManager.class)
9711 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009712 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009713 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009714 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009715 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9716 if (slotInfos != null) {
9717 for (int i = 0; i < slotInfos.length; i++) {
9718 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9719 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9720 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9721 portInfo.getLogicalSlotIndex()));
9722 }
9723 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009724 }
9725 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009726 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009727 } finally {
9728 Binder.restoreCallingIdentity(identity);
9729 }
9730 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009731
9732 /**
9733 * Get the IRadio HAL Version
9734 */
9735 @Override
9736 public int getRadioHalVersion() {
9737 Phone phone = getDefaultPhone();
9738 if (phone == null) return -1;
9739 HalVersion hv = phone.getHalVersion();
9740 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9741 return hv.major * 100 + hv.minor;
9742 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009743
9744 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009745 * Get the current calling package name.
9746 * @return the current calling package name
9747 */
9748 @Override
9749 public String getCurrentPackageName() {
9750 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9751 }
9752
9753 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009754 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9755 * corresponding network requests on a subId.
9756 *
9757 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009758 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009759 * 2) APN is un-metered for this subscription, or
9760 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009761 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009762 *
9763 * @return whether data is allowed for a apn type.
9764 *
9765 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009766 */
9767 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009768 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009769 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9770 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009771
9772 // Now that all security checks passes, perform the operation as ourselves.
9773 final long identity = Binder.clearCallingIdentity();
9774 try {
9775 Phone phone = getPhone(subId);
9776 if (phone == null) return false;
9777
Jack Yu27422a52022-03-21 10:38:05 -07009778 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009779 boolean isDataEnabled;
Jack Yuf745f972022-08-15 19:53:50 +00009780 if (phone.isUsingNewDataStack()) {
9781 isMetered = phone.getDataNetworkController().getDataConfigManager()
9782 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9783 phone.getServiceState().getDataRoaming());
9784 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9785 } else {
9786 isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
9787 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9788 }
Jack Yu99e87332021-12-17 23:14:15 -08009789 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 }
9794
9795 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009796 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009797 enforceReadPrivilegedPermission("isApnMetered");
9798
9799 // Now that all security checks passes, perform the operation as ourselves.
9800 final long identity = Binder.clearCallingIdentity();
9801 try {
9802 Phone phone = getPhone(subId);
9803 if (phone == null) return true; // By default return true.
Jack Yuf745f972022-08-15 19:53:50 +00009804 if (phone.isUsingNewDataStack()) {
9805 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9806 DataUtils.apnTypeToNetworkCapability(apnType),
9807 phone.getServiceState().getDataRoaming());
9808 }
9809
9810 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009815
9816 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009817 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9818 int subscriptionId, IBooleanConsumer resultCallback) {
9819 enforceModifyPermission();
9820 long token = Binder.clearCallingIdentity();
9821 try {
9822 Phone phone = getPhone(subscriptionId);
9823 if (phone == null) {
9824 try {
9825 if (resultCallback != null) {
9826 resultCallback.accept(false);
9827 }
9828 } catch (RemoteException e) {
9829 // ignore
9830 }
9831 return;
9832 }
9833 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9834 Pair.create(specifiers, (x) -> {
9835 try {
9836 if (resultCallback != null) {
9837 resultCallback.accept(x);
9838 }
9839 } catch (RemoteException e) {
9840 // ignore
9841 }
9842 });
9843 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9844 } finally {
9845 Binder.restoreCallingIdentity(token);
9846 }
9847 }
9848
9849 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009850 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9851 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009852 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009853 mApp, subId, "getSystemSelectionChannels");
9854 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9855 final long identity = Binder.clearCallingIdentity();
9856 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009857 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9858 if (result instanceof IllegalStateException) {
9859 throw (IllegalStateException) result;
9860 }
9861 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009862 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9863 return specifiers;
9864 } finally {
9865 Binder.restoreCallingIdentity(identity);
9866 }
9867 }
9868
9869 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009870 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009871 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009872 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009873 }
9874
9875 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009876 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9877 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009878 if (callingPackage == null) {
9879 callingPackage = getCurrentPackageName();
9880 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009881 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9882 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009883 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9884 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009885 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9886 }
9887 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9888 Intent intent = new Intent();
9889 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9890 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9891 // Bring up choose default SMS subscription dialog right now
9892 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9893 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9894 mApp.startActivity(intent);
9895 }
chen xud5ca2d52019-05-28 15:20:57 -07009896
9897 @Override
9898 public String getMmsUAProfUrl(int subId) {
9899 //TODO investigate if this API should require proper permission check in R b/133791609
9900 final long identity = Binder.clearCallingIdentity();
9901 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009902 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9903 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9904 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9905 return carrierUAProfUrl;
9906 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009907 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9908 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009909 } finally {
9910 Binder.restoreCallingIdentity(identity);
9911 }
9912 }
9913
9914 @Override
9915 public String getMmsUserAgent(int subId) {
9916 //TODO investigate if this API should require proper permission check in R b/133791609
9917 final long identity = Binder.clearCallingIdentity();
9918 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009919 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9920 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9921 if (!TextUtils.isEmpty(carrierUserAgent)) {
9922 return carrierUserAgent;
9923 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009924 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9925 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009926 } finally {
9927 Binder.restoreCallingIdentity(identity);
9928 }
9929 }
Jack Yub07d4972019-05-28 16:12:25 -07009930
9931 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009932 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9933 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009934
Jack Yub07d4972019-05-28 16:12:25 -07009935 final long identity = Binder.clearCallingIdentity();
9936 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009937 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009938 if (phone == null) return false;
9939
Hall Liua62f5da2020-09-25 10:42:19 -07009940 switch (policy) {
9941 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuf745f972022-08-15 19:53:50 +00009942 if (phone.isUsingNewDataStack()) {
9943 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9944 } else {
9945 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9946 }
Hall Liua62f5da2020-09-25 10:42:19 -07009947 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuf745f972022-08-15 19:53:50 +00009948 if (phone.isUsingNewDataStack()) {
9949 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9950 } else {
9951 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9952 }
Hall Liua62f5da2020-09-25 10:42:19 -07009953 default:
9954 throw new IllegalArgumentException(policy + " is not a valid policy");
9955 }
Jack Yub07d4972019-05-28 16:12:25 -07009956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 }
9960
9961 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009962 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009963 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009964 enforceModifyPermission();
9965
changbettyd5c246e2019-12-24 15:40:37 +08009966 final long identity = Binder.clearCallingIdentity();
9967 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009968 Phone phone = getPhone(subscriptionId);
9969 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009970
Hall Liua62f5da2020-09-25 10:42:19 -07009971 switch (policy) {
9972 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuf745f972022-08-15 19:53:50 +00009973 if (phone.isUsingNewDataStack()) {
9974 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9975 } else {
9976 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9977 }
Hall Liua62f5da2020-09-25 10:42:19 -07009978 break;
9979 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuf745f972022-08-15 19:53:50 +00009980 if (phone.isUsingNewDataStack()) {
9981 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9982 } else {
9983 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9984 }
Hall Liua62f5da2020-09-25 10:42:19 -07009985 break;
9986 default:
9987 throw new IllegalArgumentException(policy + " is not a valid policy");
9988 }
changbettyd5c246e2019-12-24 15:40:37 +08009989 } finally {
9990 Binder.restoreCallingIdentity(identity);
9991 }
9992 }
9993
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009994 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009995 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009996 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9997 * otherwise.
9998 */
9999 @Override
10000 public void setCepEnabled(boolean isCepEnabled) {
10001 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10002
10003 final long identity = Binder.clearCallingIdentity();
10004 try {
10005 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10006 for (Phone phone : PhoneFactory.getPhones()) {
10007 Phone defaultPhone = phone.getImsPhone();
10008 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10009 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10010 ImsPhoneCallTracker imsPhoneCallTracker =
10011 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10012 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10013 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10014 + imsPhone.getMsisdn());
10015 }
10016 }
10017 } finally {
10018 Binder.restoreCallingIdentity(identity);
10019 }
10020 }
allenwtsu46dcc572020-01-08 18:24:03 +080010021
10022 /**
10023 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10024 *
10025 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10026 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10027 * before being read.
10028 */
10029 @Override
10030 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10031 isCompressed) {
10032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10033 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010034 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10035 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10036 }
10037 if (!isImsAvailableOnDevice()) {
10038 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10039 "IMS not available on device.");
10040 }
10041
10042 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010043 try {
Hui Wang761a6682020-10-31 05:12:53 +000010044 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10045 } finally {
10046 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010047 }
10048 }
zoey chene02881a2019-12-30 16:11:23 +080010049
10050 @Override
10051 public boolean isIccLockEnabled(int subId) {
10052 enforceReadPrivilegedPermission("isIccLockEnabled");
10053
10054 // Now that all security checks passes, perform the operation as ourselves.
10055 final long identity = Binder.clearCallingIdentity();
10056 try {
10057 Phone phone = getPhone(subId);
10058 if (phone != null && phone.getIccCard() != null) {
10059 return phone.getIccCard().getIccLockEnabled();
10060 } else {
10061 return false;
10062 }
10063 } finally {
10064 Binder.restoreCallingIdentity(identity);
10065 }
10066 }
10067
10068 /**
10069 * Set the ICC pin lock enabled or disabled.
10070 *
10071 * @return an integer representing the status of IccLock enabled or disabled in the following
10072 * three cases:
10073 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10074 * successfully.
10075 * - Positive number and zero for remaining password attempts.
10076 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10077 *
10078 */
10079 @Override
10080 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10081 enforceModifyPermission();
10082
10083 Phone phone = getPhone(subId);
10084 if (phone == null) {
10085 return 0;
10086 }
10087 // Now that all security checks passes, perform the operation as ourselves.
10088 final long identity = Binder.clearCallingIdentity();
10089 try {
10090 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10091 new Pair<Boolean, String>(enabled, password), phone, null);
10092 return attemptsRemaining;
10093
10094 } catch (Exception e) {
10095 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10096 } finally {
10097 Binder.restoreCallingIdentity(identity);
10098 }
10099 return 0;
10100 }
10101
10102 /**
10103 * Change the ICC password used in ICC pin lock.
10104 *
10105 * @return an integer representing the status of IccLock changed in the following three cases:
10106 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10107 * - Positive number and zero for remaining password attempts.
10108 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10109 *
10110 */
10111 @Override
10112 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10113 enforceModifyPermission();
10114
10115 Phone phone = getPhone(subId);
10116 if (phone == null) {
10117 return 0;
10118 }
10119 // Now that all security checks passes, perform the operation as ourselves.
10120 final long identity = Binder.clearCallingIdentity();
10121 try {
10122 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10123 new Pair<String, String>(oldPassword, newPassword), phone, null);
10124 return attemptsRemaining;
10125
10126 } catch (Exception e) {
10127 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10128 } finally {
10129 Binder.restoreCallingIdentity(identity);
10130 }
10131 return 0;
10132 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010133
10134 /**
10135 * Request for receiving user activity notification
10136 */
10137 @Override
10138 public void requestUserActivityNotification() {
10139 if (!mNotifyUserActivity.get()
10140 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10141 mNotifyUserActivity.set(true);
10142 }
10143 }
10144
10145 /**
10146 * Called when userActivity is signalled in the power manager.
10147 * This is safe to call from any thread, with any window manager locks held or not.
10148 */
10149 @Override
10150 public void userActivity() {
10151 // ***************************************
10152 // * Inherited from PhoneWindowManager *
10153 // ***************************************
10154 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10155 // WITH ITS LOCKS HELD.
10156 //
10157 // This code must be VERY careful about the locks
10158 // it acquires.
10159 // In fact, the current code acquires way too many,
10160 // and probably has lurking deadlocks.
10161
10162 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10163 throw new SecurityException("Only the OS may call notifyUserActivity()");
10164 }
10165
10166 if (mNotifyUserActivity.getAndSet(false)) {
10167 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10168 USER_ACTIVITY_NOTIFICATION_DELAY);
10169 }
10170 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010171
10172 @Override
10173 public boolean canConnectTo5GInDsdsMode() {
10174 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10175 }
Jack Yud10cdd42020-09-28 20:28:01 -070010176
10177 @Override
10178 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10179 String callingFeatureId) {
10180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10181 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10182 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10183 }
10184
10185 Phone phone = getPhone(subId);
10186 if (phone == null) {
10187 throw new RuntimeException("phone is not available");
10188 }
10189 // Now that all security checks passes, perform the operation as ourselves.
10190 final long identity = Binder.clearCallingIdentity();
10191 try {
10192 return phone.getEquivalentHomePlmns();
10193 } finally {
10194 Binder.restoreCallingIdentity(identity);
10195 }
10196 }
Daniel Bright59e67312020-11-13 11:49:37 -080010197
10198 @Override
10199 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010200 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10201 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010202 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010203 if (radioInterfaceCapabilities == null) {
10204 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010205 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010206 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010207 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010208
Hui Wang641e81c2020-10-12 12:14:23 -070010209 @Override
10210 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10211 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010212 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10213 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10214 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10215 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10216 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010217 if (DBG) {
10218 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10219 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10220 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10221 }
10222
10223 if (!SubscriptionManager.isValidSubscriptionId(subId)
10224 || appType < TelephonyManager.APPTYPE_UNKNOWN
10225 || appType > TelephonyManager.APPTYPE_ISIM
10226 || nafUrl == null || securityProtocol == null || callback == null) {
10227 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10228 if (callback != null) {
10229 try {
10230 callback.onAuthenticationFailure(
10231 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10232 } catch (RemoteException exception) {
10233 log("Fail to notify onAuthenticationFailure due to " + exception);
10234 }
10235 return;
10236 }
10237 }
10238
10239 final long token = Binder.clearCallingIdentity();
10240 try {
10241 getGbaManager(subId).bootstrapAuthenticationRequest(
10242 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10243 forceBootStrapping, callback));
10244 } finally {
10245 Binder.restoreCallingIdentity(token);
10246 }
10247 }
10248
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010249 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010250 * Attempts to set the radio power state for all phones for thermal reason.
10251 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010252 * requested radio power state will actually be set. See {@link
10253 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10254 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010255 * @param enable {@code true} if trying to turn radio on.
10256 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10257 * false}.
10258 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010259 private boolean setRadioPowerForThermal(boolean enable) {
10260 boolean isPhoneAvailable = false;
10261 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10262 Phone phone = PhoneFactory.getPhone(i);
10263 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010264 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010265 isPhoneAvailable = true;
10266 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010267 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010268
10269 // return true if successfully informed the phone object about the thermal radio power
10270 // request.
10271 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010272 }
10273
10274 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010275 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010276 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10277 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10278 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10279 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10280 throw new IllegalArgumentException("modem does not support data throttling");
10281 }
10282
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010283 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10284 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010285 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010286 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10287 }
10288
Sarah Chinecc78c42022-03-31 21:16:48 -070010289 setDataEnabledForReason(
10290 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010291
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010292 if (isDataThrottlingSupported) {
10293 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010294 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010295 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10296 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10297 } else if (thermalMitigationResult
10298 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010299 log("Modem likely does not support data throttling on secondary carrier. Data " +
10300 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10301 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010302 }
10303 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010304 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010305
10306 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010307 }
10308
Jack Nudelman644b91a2021-03-12 14:09:48 -080010309 private static List<String> getThermalMitigationAllowlist(Context context) {
10310 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10311 for (String pckg : context.getResources()
10312 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10313 sThermalMitigationAllowlistedPackages.add(pckg);
10314 }
10315 }
10316
10317 return sThermalMitigationAllowlistedPackages;
10318 }
10319
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010320 private boolean isAnyPhoneInEmergencyState() {
10321 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10322 if (tm.isInEmergencyCall()) {
10323 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10324 return true;
10325 }
10326 for (Phone phone : PhoneFactory.getPhones()) {
10327 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10328 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10329 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10330 + phone.isInEcm());
10331 return true;
10332 }
10333 }
10334
10335 return false;
10336 }
10337
Jack Nudelman644b91a2021-03-12 14:09:48 -080010338 /**
10339 * Used by shell commands to add an authorized package name for thermal mitigation.
10340 * @param packageName name of package to be allowlisted
10341 * @param context
10342 */
10343 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10344 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10345 sThermalMitigationAllowlistedPackages.add(packageName);
10346 }
10347
10348 /**
10349 * Used by shell commands to remove an authorized package name for thermal mitigation.
10350 * @param packageName name of package to remove from allowlist
10351 * @param context
10352 */
10353 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10354 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10355 sThermalMitigationAllowlistedPackages.remove(packageName);
10356 }
10357
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010358 /**
10359 * Thermal mitigation request to control functionalities at modem.
10360 *
10361 * @param subId the id of the subscription.
10362 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010363 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010364 *
10365 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10366 */
10367 @Override
10368 @ThermalMitigationResult
10369 public int sendThermalMitigationRequest(
10370 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010371 ThermalMitigationRequest thermalMitigationRequest,
10372 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010373 enforceModifyPermission();
10374
Jack Nudelman644b91a2021-03-12 14:09:48 -080010375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10376 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10377 .contains(callingPackage)) {
10378 throw new SecurityException("Calling package must be configured in the device config. "
10379 + "calling package: " + callingPackage);
10380 }
10381
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010382 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10383 final long identity = Binder.clearCallingIdentity();
10384
10385 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10386 try {
10387 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10388 switch (thermalMitigationAction) {
10389 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10390 thermalMitigationResult =
10391 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010392 thermalMitigationRequest.getDataThrottlingRequest(),
10393 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010394 break;
10395 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10396 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10397 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10398 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10399 }
10400
10401 // Ensure that radio is on. If not able to power on due to phone being
10402 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010403 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010404 thermalMitigationResult =
10405 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10406 break;
10407 }
10408
10409 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010410 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010411 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10412 break;
10413 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10414 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10415 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10416 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10417 }
10418
10419 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10420 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010421 Phone phone = getPhone(subId);
10422 if (phone == null) {
10423 thermalMitigationResult =
10424 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10425 break;
10426 }
10427
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010428 TelephonyConnectionService service =
10429 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010430 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010431 Log.e(LOG_TAG, "An emergency call is pending");
10432 thermalMitigationResult =
10433 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10434 break;
10435 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010436 thermalMitigationResult =
10437 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10438 break;
10439 }
10440 } else {
10441 thermalMitigationResult =
10442 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10443 break;
10444 }
10445
10446 // Turn radio off. If not able to power off due to phone being unavailable,
10447 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010448 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010449 thermalMitigationResult =
10450 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10451 break;
10452 }
10453 thermalMitigationResult =
10454 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10455 break;
10456 default:
10457 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10458 + "not exist. Requested action: " + thermalMitigationAction);
10459 }
10460 } catch (IllegalArgumentException e) {
10461 throw e;
10462 } catch (Exception e) {
10463 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10464 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10465 } finally {
10466 Binder.restoreCallingIdentity(identity);
10467 }
10468
10469 if (DBG) {
10470 log("thermalMitigationRequest returning with thermalMitigationResult: "
10471 + thermalMitigationResult);
10472 }
10473
10474 return thermalMitigationResult;
10475 }
Hui Wang641e81c2020-10-12 12:14:23 -070010476
10477 /**
10478 * Set the GbaService Package Name that Telephony will bind to.
10479 *
10480 * @param subId The sim that the GbaService is associated with.
10481 * @param packageName The name of the package to be replaced with.
10482 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10483 */
10484 @Override
10485 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10486 enforceModifyPermission();
10487
10488 final long identity = Binder.clearCallingIdentity();
10489 try {
10490 return getGbaManager(subId).overrideServicePackage(packageName);
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 /**
10497 * Return the package name of the currently bound GbaService.
10498 *
10499 * @param subId The sim that the GbaService is associated with.
10500 * @return the package name of the GbaService configuration, null if GBA is not supported.
10501 */
10502 @Override
10503 public String getBoundGbaService(int subId) {
10504 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10505
10506 final long identity = Binder.clearCallingIdentity();
10507 try {
10508 return getGbaManager(subId).getServicePackage();
10509 } finally {
10510 Binder.restoreCallingIdentity(identity);
10511 }
10512 }
10513
10514 /**
10515 * Set the release time for telephony to unbind GbaService.
10516 *
10517 * @param subId The sim that the GbaService is associated with.
10518 * @param interval The release time to unbind GbaService by millisecond.
10519 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10520 */
10521 @Override
10522 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10523 enforceModifyPermission();
10524
10525 final long identity = Binder.clearCallingIdentity();
10526 try {
10527 return getGbaManager(subId).overrideReleaseTime(interval);
10528 } finally {
10529 Binder.restoreCallingIdentity(identity);
10530 }
10531 }
10532
10533 /**
10534 * Return the release time for telephony to unbind GbaService.
10535 *
10536 * @param subId The sim that the GbaService is associated with.
10537 * @return The release time to unbind GbaService by millisecond.
10538 */
10539 @Override
10540 public int getGbaReleaseTime(int subId) {
10541 enforceReadPrivilegedPermission("getGbaReleaseTime");
10542
10543 final long identity = Binder.clearCallingIdentity();
10544 try {
10545 return getGbaManager(subId).getReleaseTime();
10546 } finally {
10547 Binder.restoreCallingIdentity(identity);
10548 }
10549 }
10550
10551 private GbaManager getGbaManager(int subId) {
10552 GbaManager instance = GbaManager.getInstance(subId);
10553 if (instance == null) {
10554 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10555 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10556 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10557 }
10558 return instance;
10559 }
Hui Wang761a6682020-10-31 05:12:53 +000010560
10561 /**
10562 * indicate whether the device and the carrier can support
10563 * RCS VoLTE single registration.
10564 */
10565 @Override
10566 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010567 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10568 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10569 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10570 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010571
10572 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10573 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10574 }
10575
10576 final long identity = Binder.clearCallingIdentity();
10577 try {
10578 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10579 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010580 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10581 if (isCapable != null) {
10582 return isCapable;
10583 }
Hui Wang761a6682020-10-31 05:12:53 +000010584 }
Hui Wang67af90e2021-06-04 16:57:15 -070010585 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10586 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010587 } finally {
10588 Binder.restoreCallingIdentity(identity);
10589 }
10590 }
10591
10592 /**
10593 * Register RCS provisioning callback.
10594 */
10595 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010596 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010597 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010598 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010599 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010600 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10601 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010602
10603 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10604 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10605 }
10606 if (!isImsAvailableOnDevice()) {
10607 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10608 "IMS not available on device.");
10609 }
10610
10611 final long identity = Binder.clearCallingIdentity();
10612 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010613 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010614 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010615 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10616 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010617 }
Hui Wang761a6682020-10-31 05:12:53 +000010618 } finally {
10619 Binder.restoreCallingIdentity(identity);
10620 }
10621 }
10622
10623 /**
10624 * Unregister RCS provisioning callback.
10625 */
10626 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010627 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010628 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010629 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010630 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010631 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10632 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010633
10634 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10635 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10636 }
10637 if (!isImsAvailableOnDevice()) {
10638 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10639 "IMS not available on device.");
10640 }
10641
10642 final long identity = Binder.clearCallingIdentity();
10643 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010644 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010645 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010646 } finally {
10647 Binder.restoreCallingIdentity(identity);
10648 }
10649 }
10650
10651 /**
10652 * trigger RCS reconfiguration.
10653 */
10654 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010655 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10656 "triggerRcsReconfiguration",
10657 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010658
10659 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10660 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10661 }
10662 if (!isImsAvailableOnDevice()) {
10663 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10664 "IMS not available on device.");
10665 }
10666
10667 final long identity = Binder.clearCallingIdentity();
10668 try {
10669 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
10674
10675 /**
10676 * Provide the client configuration parameters of the RCS application.
10677 */
10678 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010679 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10680 "setRcsClientConfiguration",
10681 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010682
10683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10684 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10685 }
10686 if (!isImsAvailableOnDevice()) {
10687 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10688 "IMS not available on device.");
10689 }
10690
10691 final long identity = Binder.clearCallingIdentity();
10692
10693 try {
10694 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10695 if (configBinder == null) {
10696 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010697 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10698 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010699 } else {
10700 configBinder.setRcsClientConfiguration(rcc);
10701 }
joonhunshin3e154242021-09-17 06:33:39 +000010702
10703 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10704 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010705 } catch (RemoteException e) {
10706 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010707 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10708 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010709 } finally {
10710 Binder.restoreCallingIdentity(identity);
10711 }
10712 }
10713
10714 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010715 * Enables or disables the test mode for RCS VoLTE single registration.
10716 */
10717 @Override
10718 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10719 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10720 "setRcsSingleRegistrationTestModeEnabled");
10721
10722 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10723 }
10724
10725 /**
10726 * Gets the test mode for RCS VoLTE single registration.
10727 */
10728 @Override
10729 public boolean getRcsSingleRegistrationTestModeEnabled() {
10730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10731 "getRcsSingleRegistrationTestModeEnabled");
10732
10733 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10734 }
10735
10736 /**
Hui Wang761a6682020-10-31 05:12:53 +000010737 * Overrides the config of RCS VoLTE single registration enabled for the device.
10738 */
10739 @Override
10740 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10742 "setDeviceSingleRegistrationEnabledOverride");
10743 enforceModifyPermission();
10744
10745 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10746 : Boolean.parseBoolean(enabledStr);
10747 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010748 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010749 }
10750
10751 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010752 * Sends a device to device communication message. Only usable via shell.
10753 * @param message message to send.
10754 * @param value message value.
10755 */
10756 @Override
10757 public void sendDeviceToDeviceMessage(int message, int value) {
10758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010759 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010760 enforceModifyPermission();
10761
10762 final long identity = Binder.clearCallingIdentity();
10763 try {
10764 TelephonyConnectionService service =
10765 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10766 if (service == null) {
10767 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10768 return;
10769 }
10770 service.sendTestDeviceToDeviceMessage(message, value);
10771 } finally {
10772 Binder.restoreCallingIdentity(identity);
10773 }
10774 }
10775
Tyler Gunnbabbda02021-02-10 11:05:02 -080010776 /**
10777 * Sets the specified device to device transport active.
10778 * @param transport The transport to set active.
10779 */
10780 @Override
10781 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10783 "setActiveDeviceToDeviceTransport");
10784 enforceModifyPermission();
10785
10786 final long identity = Binder.clearCallingIdentity();
10787 try {
10788 TelephonyConnectionService service =
10789 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10790 if (service == null) {
10791 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10792 return;
10793 }
10794 service.setActiveDeviceToDeviceTransport(transport);
10795 } finally {
10796 Binder.restoreCallingIdentity(identity);
10797 }
10798 }
Tyler Gunn92479152021-01-20 16:30:10 -080010799
Tyler Gunnd4339262021-05-03 14:46:49 -070010800 @Override
10801 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10803 "setDeviceToDeviceForceEnabled");
10804
10805 final long identity = Binder.clearCallingIdentity();
10806 try {
10807 Arrays.stream(PhoneFactory.getPhones()).forEach(
10808 p -> {
10809 Phone thePhone = p.getImsPhone();
10810 if (thePhone != null && thePhone instanceof ImsPhone) {
10811 ImsPhone imsPhone = (ImsPhone) thePhone;
10812 CallTracker tracker = imsPhone.getCallTracker();
10813 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10814 ImsPhoneCallTracker imsPhoneCallTracker =
10815 (ImsPhoneCallTracker) tracker;
10816 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10817 }
10818 }
10819 }
10820 );
10821 } finally {
10822 Binder.restoreCallingIdentity(identity);
10823 }
10824 }
10825
Tyler Gunn92479152021-01-20 16:30:10 -080010826 /**
Hui Wang761a6682020-10-31 05:12:53 +000010827 * Gets the config of RCS VoLTE single registration enabled for the device.
10828 */
10829 @Override
10830 public boolean getDeviceSingleRegistrationEnabled() {
10831 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10832 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10833 }
10834
10835 /**
10836 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10837 */
10838 @Override
10839 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10841 "setCarrierSingleRegistrationEnabledOverride");
10842 enforceModifyPermission();
10843
10844 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10845 : Boolean.parseBoolean(enabledStr);
10846 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10847 subId, enabled);
10848 }
10849
10850 /**
10851 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10852 */
10853 @Override
10854 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10855 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10856 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10857 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010858
10859 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010860 * Overrides the ims feature validation result
10861 */
10862 @Override
10863 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10865 "setImsFeatureValidationOverride");
10866
10867 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10868 : Boolean.parseBoolean(enabledStr);
10869 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10870 subId, enabled);
10871 }
10872
10873 /**
10874 * Gets the ims feature validation override value
10875 */
10876 @Override
10877 public boolean getImsFeatureValidationOverride(int subId) {
10878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10879 "getImsFeatureValidationOverride");
10880 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10881 }
10882
10883 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010884 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10885 * their mobile plan.
10886 */
10887 @Override
10888 public String getMobileProvisioningUrl() {
10889 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10890 final long identity = Binder.clearCallingIdentity();
10891 try {
10892 return getDefaultPhone().getMobileProvisioningUrl();
10893 } finally {
10894 Binder.restoreCallingIdentity(identity);
10895 }
10896 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010897
James.cf Linbcdf8b32021-01-14 16:44:13 +080010898 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010899 * Get the EAB contact from the EAB database.
10900 */
10901 @Override
10902 public String getContactFromEab(String contact) {
10903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10904 enforceModifyPermission();
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
10907 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
10912
10913 /**
Calvin Pana1434322021-07-01 19:27:01 +080010914 * Get the EAB capability from the EAB database.
10915 */
10916 @Override
10917 public String getCapabilityFromEab(String contact) {
10918 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10919 enforceModifyPermission();
10920 final long identity = Binder.clearCallingIdentity();
10921 try {
10922 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
10928 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010929 * Remove the EAB contacts from the EAB database.
10930 */
10931 @Override
10932 public int removeContactFromEab(int subId, String contacts) {
10933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10934 enforceModifyPermission();
10935 final long identity = Binder.clearCallingIdentity();
10936 try {
10937 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10938 } finally {
10939 Binder.restoreCallingIdentity(identity);
10940 }
10941 }
10942
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010943 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010944 public boolean getDeviceUceEnabled() {
10945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10946 final long identity = Binder.clearCallingIdentity();
10947 try {
10948 return mApp.getDeviceUceEnabled();
10949 } finally {
10950 Binder.restoreCallingIdentity(identity);
10951 }
10952 }
10953
10954 @Override
10955 public void setDeviceUceEnabled(boolean isEnabled) {
10956 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10957 final long identity = Binder.clearCallingIdentity();
10958 try {
10959 mApp.setDeviceUceEnabled(isEnabled);
10960 } finally {
10961 Binder.restoreCallingIdentity(identity);
10962 }
10963 }
10964
Brad Ebinger14d467f2021-02-12 06:18:28 +000010965 /**
10966 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10967 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10968 */
10969 // Used for SHELL command only right now.
10970 @Override
10971 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10972 List<String> featureTags) {
10973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10974 "addUceRegistrationOverrideShell");
10975 final long identity = Binder.clearCallingIdentity();
10976 try {
10977 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10978 new ArraySet<>(featureTags));
10979 } catch (ImsException e) {
10980 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
10985
10986 /**
10987 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10988 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10989 */
10990 // Used for SHELL command only right now.
10991 @Override
10992 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10993 List<String> featureTags) {
10994 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10995 "removeUceRegistrationOverrideShell");
10996 final long identity = Binder.clearCallingIdentity();
10997 try {
10998 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10999 new ArraySet<>(featureTags));
11000 } catch (ImsException e) {
11001 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11002 } finally {
11003 Binder.restoreCallingIdentity(identity);
11004 }
11005 }
11006
11007 /**
11008 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11009 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11010 */
11011 // Used for SHELL command only right now.
11012 @Override
11013 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11015 "clearUceRegistrationOverrideShell");
11016 final long identity = Binder.clearCallingIdentity();
11017 try {
11018 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11019 } catch (ImsException e) {
11020 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
11025
11026 /**
11027 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11028 */
11029 // Used for SHELL command only right now.
11030 @Override
11031 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11033 "getLatestRcsContactUceCapabilityShell");
11034 final long identity = Binder.clearCallingIdentity();
11035 try {
11036 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11037 } catch (ImsException e) {
11038 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11039 } finally {
11040 Binder.restoreCallingIdentity(identity);
11041 }
11042 }
11043
11044 /**
11045 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11046 * device does not have an active PUBLISH.
11047 */
11048 // Used for SHELL command only right now.
11049 @Override
11050 public String getLastUcePidfXmlShell(int subId) {
11051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11052 final long identity = Binder.clearCallingIdentity();
11053 try {
11054 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11055 } catch (ImsException e) {
11056 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11057 } finally {
11058 Binder.restoreCallingIdentity(identity);
11059 }
11060 }
11061
James.cf Line8713a42021-04-29 16:04:26 +080011062 /**
11063 * Remove UCE requests cannot be sent to the network status.
11064 */
11065 // Used for SHELL command only right now.
11066 @Override
11067 public boolean removeUceRequestDisallowedStatus(int subId) {
11068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11069 final long identity = Binder.clearCallingIdentity();
11070 try {
11071 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11072 } catch (ImsException e) {
11073 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11074 } finally {
11075 Binder.restoreCallingIdentity(identity);
11076 }
11077 }
11078
James.cf Lin18bb9002021-05-25 01:37:38 +080011079 /**
11080 * Remove UCE requests cannot be sent to the network status.
11081 */
11082 // Used for SHELL command only.
11083 @Override
11084 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11086 final long identity = Binder.clearCallingIdentity();
11087 try {
11088 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11089 } catch (ImsException e) {
11090 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11091 } finally {
11092 Binder.restoreCallingIdentity(identity);
11093 }
11094 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011095
James.cf Lin4b784aa2021-01-31 03:25:15 +080011096 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011097 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11098 String callingPackage) {
11099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11100 mApp, subId, "setSignalStrengthUpdateRequest");
11101
11102 final int callingUid = Binder.getCallingUid();
11103 // Verify that tha callingPackage belongs to the calling UID
11104 mApp.getSystemService(AppOpsManager.class)
11105 .checkPackage(callingUid, callingPackage);
11106
Rambo Wang3607f502021-02-01 21:51:40 -080011107 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011108
11109 final long identity = Binder.clearCallingIdentity();
11110 try {
11111 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11112 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11113
11114 if (result instanceof IllegalStateException) {
11115 throw (IllegalStateException) result;
11116 }
11117 } finally {
11118 Binder.restoreCallingIdentity(identity);
11119 }
11120 }
11121
11122 @Override
11123 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11124 String callingPackage) {
11125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11126 mApp, subId, "clearSignalStrengthUpdateRequest");
11127
11128 final int callingUid = Binder.getCallingUid();
11129 // Verify that tha callingPackage belongs to the calling UID
11130 mApp.getSystemService(AppOpsManager.class)
11131 .checkPackage(callingUid, callingPackage);
11132
11133 final long identity = Binder.clearCallingIdentity();
11134 try {
11135 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11136 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11137
11138 if (result instanceof IllegalStateException) {
11139 throw (IllegalStateException) result;
11140 }
11141 } finally {
11142 Binder.restoreCallingIdentity(identity);
11143 }
11144 }
11145
Rambo Wang3607f502021-02-01 21:51:40 -080011146 private static void validateSignalStrengthUpdateRequest(Context context,
11147 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011148 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11149 // phone/system process do not have further restriction on request
11150 return;
11151 }
11152
11153 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011154 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011155 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011156 context.enforceCallingOrSelfPermission(
11157 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11158 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011159 }
11160
11161 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11162 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11163 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11164 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11165 || info.isEnabled()) {
11166 throw new IllegalArgumentException(
11167 "Only system can set hide fields in SignalThresholdInfo");
11168 }
11169
11170 // Thresholds length for each RAN need in range. This has been validated in
11171 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11172 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11173 final int[] thresholds = info.getThresholds();
11174 Objects.requireNonNull(thresholds);
11175 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11176 || thresholds.length
11177 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11178 throw new IllegalArgumentException(
11179 "thresholds length is out of range: " + thresholds.length);
11180 }
11181 }
11182 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011183
11184 /**
11185 * Gets the current phone capability.
11186 *
11187 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11188 * @return the PhoneCapability which describes the data connection capability of modem.
11189 * It's used to evaluate possible phone config change, for example from single
11190 * SIM device to multi-SIM device.
11191 */
11192 @Override
11193 public PhoneCapability getPhoneCapability() {
11194 enforceReadPrivilegedPermission("getPhoneCapability");
11195 final long identity = Binder.clearCallingIdentity();
11196 try {
11197 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11198 } finally {
11199 Binder.restoreCallingIdentity(identity);
11200 }
11201 }
Michele Berionne5e411512020-11-13 02:36:59 +000011202
11203 /**
11204 * Prepare TelephonyManager for an unattended reboot. The reboot is
11205 * required to be done shortly after the API is invoked.
11206 */
11207 @Override
11208 @TelephonyManager.PrepareUnattendedRebootResult
11209 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011210 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011211 enforceRebootPermission();
11212
11213 final long identity = Binder.clearCallingIdentity();
11214 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011215 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011216 } finally {
11217 Binder.restoreCallingIdentity(identity);
11218 }
11219 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011220
11221 /**
11222 * Request to get the current slicing configuration including URSP rules and
11223 * NSSAIs (configured, allowed and rejected).
11224 *
11225 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11226 */
11227 @Override
11228 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011229 TelephonyPermissions
11230 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11231 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011232
11233 final long identity = Binder.clearCallingIdentity();
11234 try {
11235 Phone phone = getDefaultPhone();
11236 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11237 } finally {
11238 Binder.restoreCallingIdentity(identity);
11239 }
11240 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011241
11242 /**
11243 * Register an IMS connection state callback
11244 */
11245 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011246 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11247 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011248 if (feature == ImsFeature.FEATURE_MMTEL) {
11249 // ImsMmTelManager
11250 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11251 TelephonyPermissions
11252 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11253 mApp, subId, "registerImsStateCallback");
11254 } else if (feature == ImsFeature.FEATURE_RCS) {
11255 // ImsRcsManager or SipDelegateManager
11256 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11257 Binder.getCallingUid(), "registerImsStateCallback",
11258 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11259 Manifest.permission.READ_PRECISE_PHONE_STATE,
11260 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11261 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11262 }
11263
11264 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11265 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11266 "IMS not available on device.");
11267 }
11268
11269 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11270 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11271 }
11272
11273 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11274 if (controller == null) {
11275 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11276 "IMS not available on device.");
11277 }
11278
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011279 if (callingPackage == null) {
11280 callingPackage = getCurrentPackageName();
11281 }
11282
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011283 final long token = Binder.clearCallingIdentity();
11284 try {
11285 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011286 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011287 } catch (ImsException e) {
11288 throw new ServiceSpecificException(e.getCode());
11289 } finally {
11290 Binder.restoreCallingIdentity(token);
11291 }
11292 }
11293
11294 /**
11295 * Unregister an IMS connection state callback
11296 */
11297 @Override
11298 public void unregisterImsStateCallback(IImsStateCallback cb) {
11299 final long token = Binder.clearCallingIdentity();
11300 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11301 if (controller == null) {
11302 return;
11303 }
11304 try {
11305 controller.unregisterImsStateCallback(cb);
11306 } finally {
11307 Binder.restoreCallingIdentity(token);
11308 }
11309 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011310
11311 /**
11312 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11313 *
11314 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11315 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11316 * SecurityException.
11317 * If there is current registered network this value will be same as the registered cell
11318 * identity. If the device goes out of service the previous cell identity is cached and
11319 * will be returned. If the cache age of the Cell identity is more than 24 hours
11320 * it will be cleared and null will be returned.
11321 *
11322 */
11323 @Override
11324 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11325 String callingFeatureId) {
11326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11327 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11328 LocationAccessPolicy.checkLocationPermission(mApp,
11329 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11330 .setCallingPackage(callingPackage)
11331 .setCallingFeatureId(callingFeatureId)
11332 .setCallingPid(Binder.getCallingPid())
11333 .setCallingUid(Binder.getCallingUid())
11334 .setMethod("getLastKnownCellIdentity")
11335 .setLogAsInfo(true)
11336 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11337 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11338 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11339 .build());
11340
11341 boolean hasFinePermission =
11342 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11343 if (!hasFinePermission
11344 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11345 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011346 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011347 }
11348
11349 final long identity = Binder.clearCallingIdentity();
11350 try {
11351 Phone phone = getPhone(subId);
11352 if (phone == null) return null;
11353 ServiceStateTracker sst = phone.getServiceStateTracker();
11354 if (sst == null) return null;
11355 return sst.getLastKnownCellIdentity();
11356 } finally {
11357 Binder.restoreCallingIdentity(identity);
11358 }
11359 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011360
Jack Yuf745f972022-08-15 19:53:50 +000011361 @Override
11362 public boolean isUsingNewDataStack() {
11363 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11364 return getDefaultPhone().isUsingNewDataStack();
11365 }
11366
jimsun3b9ccac2021-10-26 15:01:23 +080011367 /**
11368 * Sets the modem service class Name that Telephony will bind to.
11369 *
11370 * @param serviceName The class name of the modem service.
11371 * @return true if the operation is succeed, otherwise false.
11372 */
11373 public boolean setModemService(String serviceName) {
11374 Log.d(LOG_TAG, "setModemService - " + serviceName);
11375 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11377 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11378 "setModemService");
11379 return mPhoneConfigurationManager.setModemService(serviceName);
11380 }
11381
11382 /**
11383 * Return the class name of the currently bounded modem service.
11384 *
11385 * @return the class name of the modem service.
11386 */
11387 public String getModemService() {
11388 String result;
11389 Log.d(LOG_TAG, "getModemService");
11390 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11391 TelephonyPermissions
11392 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11393 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11394 "getModemService");
11395 result = mPhoneConfigurationManager.getModemService();
11396 Log.d(LOG_TAG, "result = " + result);
11397 return result;
11398 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011399
11400 @Override
11401 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11402 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11403 mApp.enforceCallingOrSelfPermission(
11404 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11406
11407 final long identity = Binder.clearCallingIdentity();
11408 try {
11409 Phone phone = getPhone(subId);
11410 if (phone == null) return;
11411 phone.setVoiceServiceStateOverride(hasService);
11412 } finally {
11413 Binder.restoreCallingIdentity(identity);
11414 }
11415 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011416
11417 /**
11418 * set removable eSIM as default eUICC.
11419 *
11420 * @hide
11421 */
11422 @Override
11423 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11424 enforceModifyPermission();
11425 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11426
11427 final long identity = Binder.clearCallingIdentity();
11428 try {
11429 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11430 } finally {
11431 Binder.restoreCallingIdentity(identity);
11432 }
11433 }
11434
11435 /**
11436 * Returns whether the removable eSIM is default eUICC or not.
11437 *
11438 * @hide
11439 */
11440 @Override
11441 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11442 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11444
11445 final long identity = Binder.clearCallingIdentity();
11446 try {
11447 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11448 } finally {
11449 Binder.restoreCallingIdentity(identity);
11450 }
11451 }
11452
11453
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011454}