blob: c1db593e7eff9ec482b186561d6927aef21fca17 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080075import android.telephony.AccessNetworkConstants;
76import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070077import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070078import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080080import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070081import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080082import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070083import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080084import android.telephony.CellIdentityCdma;
85import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070087import android.telephony.CellInfoGsm;
88import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070089import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080090import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070091import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070092import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070093import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080094import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070095import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080096import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070097import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080098import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080099import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700100import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800103import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800104import android.telephony.SignalStrengthUpdateRequest;
105import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800106import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800108import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700109import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700110import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800111import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800112import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800113import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000115import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700117import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700118import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800119import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800120import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700121import android.telephony.gba.GbaAuthRequest;
122import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700123import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000126import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700127import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000128import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700129import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700131import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700133import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000134import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700135import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800152import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700157import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800158import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800159import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800160import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700161import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000162import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800164import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800167import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700169import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700172import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800173import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700174import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700175import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700176import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700177import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800178import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800179import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700181import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800183import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800184import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700186import com.android.internal.telephony.data.DataUtils;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700187import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
197import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700199import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000202import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800205import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700206import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700207import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800208import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800209import com.android.phone.callcomposer.CallComposerPictureManager;
210import com.android.phone.callcomposer.CallComposerPictureTransfer;
211import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700212import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800214import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700216import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800217import com.android.services.telephony.TelecomAccountRegistry;
218import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800219import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800220
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.IOException;
224import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700225import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000228import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800229import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800230import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800231import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800232import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100233import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700235import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800237import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800239import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800240import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
242/**
243 * Implementation of the ITelephony interface.
244 */
Santos Cordon117fee72014-05-16 17:56:12 -0700245public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 private static final String LOG_TAG = "PhoneInterfaceManager";
247 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
248 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
251 // Message codes used with mMainThreadHandler
252 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700253 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
254 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700255 private static final int CMD_OPEN_CHANNEL = 9;
256 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
257 private static final int CMD_CLOSE_CHANNEL = 11;
258 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800259 private static final int CMD_NV_READ_ITEM = 13;
260 private static final int EVENT_NV_READ_ITEM_DONE = 14;
261 private static final int CMD_NV_WRITE_ITEM = 15;
262 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
263 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
264 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_RESET_MODEM_CONFIG = 19;
266 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800267 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
268 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800269 private static final int CMD_SEND_ENVELOPE = 25;
270 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000271 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
272 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700273 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
274 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
275 private static final int CMD_EXCHANGE_SIM_IO = 31;
276 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
278 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700279 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
280 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700281 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
282 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700283 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
284 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
285 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
286 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700287 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
288 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
289 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
290 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700291 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800292 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
293 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000294 private static final int CMD_SWITCH_SLOTS = 50;
295 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700296 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
297 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
298 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
299 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
300 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
301 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
302 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
303 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700304 private static final int CMD_GET_ALL_CELL_INFO = 60;
305 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
306 private static final int CMD_GET_CELL_LOCATION = 62;
307 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700308 private static final int CMD_MODEM_REBOOT = 64;
309 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700310 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
311 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800312 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
313 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700314 private static final int CMD_GET_MODEM_STATUS = 70;
315 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700316 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
317 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700318 private static final int CMD_ERASE_MODEM_CONFIG = 74;
319 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800320 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
321 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
322 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
323 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800324 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
325 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800326 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800327 private static final int CMD_GET_CALL_FORWARDING = 83;
328 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
329 private static final int CMD_SET_CALL_FORWARDING = 85;
330 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
331 private static final int CMD_GET_CALL_WAITING = 87;
332 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
333 private static final int CMD_SET_CALL_WAITING = 89;
334 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700335 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
336 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
337 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
338 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700339 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
340 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800341 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
342 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800343 private static final int CMD_SET_DATA_THROTTLING = 99;
344 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800345 private static final int CMD_SET_SIM_POWER = 101;
346 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800347 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
348 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
349 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
350 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800351 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
352 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000353 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800354 private static final int CMD_GET_SLICING_CONFIG = 110;
355 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800356 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700357 private static final int CMD_ENABLE_VONR = 113;
358 private static final int EVENT_ENABLE_VONR_DONE = 114;
359 private static final int CMD_IS_VONR_ENABLED = 115;
360 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800362 // Parameters of select command.
363 private static final int SELECT_COMMAND = 0xA4;
364 private static final int SELECT_P1 = 0x04;
365 private static final int SELECT_P2 = 0;
366 private static final int SELECT_P3 = 0x10;
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 /** The singleton instance. */
369 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800370 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800374 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700375 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700377 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800379 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700381 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800382 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 /** User Activity */
385 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
387
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700388 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
389
Derek Tan97ebb422014-09-05 16:55:38 -0700390 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
391 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800392 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800393 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700394
Michelecea4cf22018-12-21 15:00:11 -0800395 // String to store multi SIM allowed
396 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
397
Derek Tan740e1672017-06-27 14:56:27 -0700398 // The AID of ISD-R.
399 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
400
yinxub1bed742017-04-17 11:45:04 -0700401 private NetworkScanRequestTracker mNetworkScanRequestTracker;
402
David Kelly5e06a7f2018-03-12 14:10:59 +0000403 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
404 private static final int MANUFACTURER_CODE_LENGTH = 8;
405
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800407 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408
Derek Tan89e89d42014-07-08 17:00:10 -0700409 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700410 * Experiment flag to enable erase modem config on reset network, default value is false
411 */
412 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
413 "reset_network_erase_modem_config_enabled";
414
Rambo Wang0f050d82021-02-12 11:43:36 -0800415 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800416
sandeepjsb6c87872021-09-27 15:34:44 +0000417 /**
418 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
419 * one ICCID active at the same time.
420 * Apps should use below API signatures if targeting SDK is T and beyond.
421 *
422 * @hide
423 */
424 @ChangeId
425 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
426 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800427
Naina Nallurid63128d2019-09-17 14:10:30 -0700428 /**
Chen Xu540470b2021-12-14 17:15:47 -0800429 * Apps targeting on Android T and beyond will get exception whenever icc close channel
430 * operation fails.
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
435
436 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 * A request object to use for transmitting data to an ICC.
438 */
439 private static final class IccAPDUArgument {
440 public int channel, cla, command, p1, p2, p3;
441 public String data;
442
443 public IccAPDUArgument(int channel, int cla, int command,
444 int p1, int p2, int p3, String data) {
445 this.channel = channel;
446 this.cla = cla;
447 this.command = command;
448 this.p1 = p1;
449 this.p2 = p2;
450 this.p3 = p3;
451 this.data = data;
452 }
453 }
454
455 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700456 * A request object to use for transmitting data to an ICC.
457 */
458 private static final class ManualNetworkSelectionArgument {
459 public OperatorInfo operatorInfo;
460 public boolean persistSelection;
461
462 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
463 this.operatorInfo = operatorInfo;
464 this.persistSelection = persistSelection;
465 }
466 }
467
468 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
470 * request after sending. The main thread will notify the request when it is complete.
471 */
472 private static final class MainThreadRequest {
473 /** The argument to use for the request */
474 public Object argument;
475 /** The result of the request that is run on the main thread */
476 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800477 // The subscriber id that this request applies to. Defaults to
478 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
479 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Nathan Harold92bed182018-10-12 18:16:49 -0700481 // In cases where subId is unavailable, the caller needs to specify the phone.
482 public Phone phone;
483
vagdeviaf9a5b92018-08-15 16:01:53 -0700484 public WorkSource workSource;
485
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 public MainThreadRequest(Object argument) {
487 this.argument = argument;
488 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800489
Nathan Harold92bed182018-10-12 18:16:49 -0700490 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
491 this.argument = argument;
492 if (phone != null) {
493 this.phone = phone;
494 }
495 this.workSource = workSource;
496 }
497
vagdeviaf9a5b92018-08-15 16:01:53 -0700498 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800499 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800500 if (subId != null) {
501 this.subId = subId;
502 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700503 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 }
506
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800507 private static final class IncomingThirdPartyCallArgs {
508 public final ComponentName component;
509 public final String callId;
510 public final String callerDisplayName;
511
512 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
513 String callerDisplayName) {
514 this.component = component;
515 this.callId = callId;
516 this.callerDisplayName = callerDisplayName;
517 }
518 }
519
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 /**
521 * A handler that processes messages on the main thread in the phone process. Since many
522 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
523 * inbound binder threads to the main thread in the phone process. The Binder thread
524 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
525 * on, which will be notified when the operation completes and will contain the result of the
526 * request.
527 *
528 * <p>If a MainThreadRequest object is provided in the msg.obj field,
529 * note that request.result must be set to something non-null for the calling thread to
530 * unblock.
531 */
532 private final class MainThreadHandler extends Handler {
533 @Override
534 public void handleMessage(Message msg) {
535 MainThreadRequest request;
536 Message onCompleted;
537 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000538 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800540 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541
542 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 case CMD_HANDLE_USSD_REQUEST: {
544 request = (MainThreadRequest) msg.obj;
545 final Phone phone = getPhoneFromRequest(request);
546 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800547 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 if (!isUssdApiAllowed(request.subId)) {
551 // Carrier does not support use of this API, return failure.
552 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
553 UssdResponse response = new UssdResponse(ussdRequest, null);
554 Bundle returnData = new Bundle();
555 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
556 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700557
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 request.result = true;
559 notifyRequester(request);
560 return;
561 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700562
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 try {
564 request.result = phone != null
565 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
566 } catch (CallStateException cse) {
567 request.result = false;
568 }
569 // Wake up the requesting thread
570 notifyRequester(request);
571 break;
pkanwar32d516d2016-10-14 19:37:38 -0700572 }
573
Yorke Lee716f67e2015-06-17 15:39:16 -0700574 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700576 final Phone phone = getPhoneFromRequest(request);
577 request.result = phone != null ?
578 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
579 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700580 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 uiccPort = getUiccPortFromRequest(request);
589 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800591 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800595 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000596 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800597 iccArgument.channel, iccArgument.cla, iccArgument.command,
598 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
599 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800609 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800612 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800614 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 } else {
616 loge("iccTransmitApduLogicalChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 uiccPort = getUiccPortFromRequest(request);
626 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800628 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800632 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000633 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800634 iccArgument.cla, iccArgument.command, iccArgument.p1,
635 iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800692 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800696 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800752
753 uiccPort = getUiccPortFromRequest(request);
754 IccLogicalChannelRequest channelRequest =
755 (IccLogicalChannelRequest) request.argument;
756 channelRequest.channel = channelId;
757 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 if (ar.result == null) {
760 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 if (ar.exception != null) {
763 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
764 }
765
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700766 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700767 if (ar.exception instanceof CommandException) {
768 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800769 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700770 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700772 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700773 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 }
775 }
776 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800777 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700779 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 break;
782
783 case CMD_CLOSE_CHANNEL:
784 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000785 uiccPort = getUiccPortFromRequest(request);
786 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800788 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800789 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800790 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700791 } else {
792 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000793 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 break;
796
797 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800798 ar = (AsyncResult) msg.obj;
799 request = (MainThreadRequest) ar.userObj;
800 if (ar.exception == null) {
801 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800802 uiccPort = getUiccPortFromRequest(request);
803 final int channelId = (Integer) request.argument;
804 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800805 } else {
806 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800807 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800808 if (ar.exception instanceof CommandException) {
809 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
810 CommandException.Error error =
811 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800812 if (error == CommandException.Error.INVALID_ARGUMENTS) {
813 // should only throw exceptions from the binder threads.
814 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800815 "iccCloseLogicalChannel: invalid argument ");
816 }
817 } else {
818 loge("iccCloseLogicalChannel: Unknown exception");
819 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800820 request.result = (exception != null) ? exception :
821 new IllegalStateException(
822 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800823 }
824 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800825 break;
826
827 case CMD_NV_READ_ITEM:
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800830 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
831 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800832 break;
833
834 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800840 request.result = "";
841 if (ar.result == null) {
842 loge("nvReadItem: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("nvReadItem: CommandException: " +
845 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800847 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 }
849 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700850 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 break;
852
Jake Hambye994d462014-02-03 13:10:13 -0800853 case CMD_NV_WRITE_ITEM:
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
856 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800857 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700858 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800859 break;
860
861 case EVENT_NV_WRITE_ITEM_DONE:
862 handleNullReturnEvent(msg, "nvWriteItem");
863 break;
864
865 case CMD_NV_WRITE_CDMA_PRL:
866 request = (MainThreadRequest) msg.obj;
867 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800868 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800869 break;
870
871 case EVENT_NV_WRITE_CDMA_PRL_DONE:
872 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
873 break;
874
chen xu6dac5ab2018-10-26 17:39:23 -0700875 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800876 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700877 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800878 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800879 break;
880
chen xu6dac5ab2018-10-26 17:39:23 -0700881 case EVENT_RESET_MODEM_CONFIG_DONE:
882 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800883 break;
884
Sooraj Sasindran37444802020-08-11 10:40:43 -0700885 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
888 request);
889 Phone phone = getPhoneFromRequest(request);
890 if (phone != null) {
891 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
892 } else {
893 loge("isNRDualConnectivityEnabled: No phone object");
894 request.result = false;
895 notifyRequester(request);
896 }
897 break;
898 }
899
900 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result;
905 } else {
906 // request.result must be set to something non-null
907 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700908 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700909 request.result = ar.result;
910 } else {
911 request.result = false;
912 }
913 if (ar.result == null) {
914 loge("isNRDualConnectivityEnabled: Empty response");
915 } else if (ar.exception instanceof CommandException) {
916 loge("isNRDualConnectivityEnabled: CommandException: "
917 + ar.exception);
918 } else {
919 loge("isNRDualConnectivityEnabled: Unknown exception");
920 }
921 }
922 notifyRequester(request);
923 break;
924
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700925 case CMD_IS_VONR_ENABLED: {
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
928 request);
929 Phone phone = getPhoneFromRequest(request);
930 if (phone != null) {
931 phone.isVoNrEnabled(onCompleted, request.workSource);
932 } else {
933 loge("isVoNrEnabled: No phone object");
934 request.result = false;
935 notifyRequester(request);
936 }
937 break;
938 }
939
940 case EVENT_IS_VONR_ENABLED_DONE:
941 ar = (AsyncResult) msg.obj;
942 request = (MainThreadRequest) ar.userObj;
943 if (ar.exception == null && ar.result != null) {
944 request.result = ar.result;
945 } else {
946 // request.result must be set to something non-null
947 // for the calling thread to unblock
948 if (ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = false;
952 }
953 if (ar.result == null) {
954 loge("isVoNrEnabled: Empty response");
955 } else if (ar.exception instanceof CommandException) {
956 loge("isVoNrEnabled: CommandException: "
957 + ar.exception);
958 } else {
959 loge("isVoNrEnabled: Unknown exception");
960 }
961 }
962 notifyRequester(request);
963 break;
964
Sooraj Sasindran37444802020-08-11 10:40:43 -0700965 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
971 request.workSource);
972 } else {
973 loge("enableNrDualConnectivity: No phone object");
974 request.result =
975 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null) {
985 request.result =
986 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
987 } else {
988 request.result =
989 TelephonyManager
990 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
991 if (ar.exception instanceof CommandException) {
992 CommandException.Error error =
993 ((CommandException) (ar.exception)).getCommandError();
994 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
995 request.result =
996 TelephonyManager
997 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000998 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
999 request.result =
1000 TelephonyManager
1001 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001002 }
1003 loge("enableNrDualConnectivity" + ": CommandException: "
1004 + ar.exception);
1005 } else {
1006 loge("enableNrDualConnectivity" + ": Unknown exception");
1007 }
1008 }
1009 notifyRequester(request);
1010 break;
1011 }
1012
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001013 case CMD_ENABLE_VONR: {
1014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1016 Phone phone = getPhoneFromRequest(request);
1017 if (phone != null) {
1018 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1019 request.workSource);
1020 } else {
1021 loge("setVoNrEnabled: No phone object");
1022 request.result =
1023 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1024 notifyRequester(request);
1025 }
1026 break;
1027 }
1028
1029 case EVENT_ENABLE_VONR_DONE: {
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception == null) {
1033 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1034 } else {
1035 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1040 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1041 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1042 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1043 } else {
1044 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1045 }
1046 loge("setVoNrEnabled" + ": CommandException: "
1047 + ar.exception);
1048 } else {
1049 loge("setVoNrEnabled" + ": Unknown exception");
1050 }
1051 }
1052 notifyRequester(request);
1053 break;
1054 }
1055
SongFerngWang3ef3e072020-12-21 16:41:52 +08001056 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001057 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001058 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1059 request);
1060 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001061 break;
1062
SongFerngWang3ef3e072020-12-21 16:41:52 +08001063 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null && ar.result != null) {
1067 request.result = ar.result; // Integer
1068 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301069 // request.result must be set to something non-null
1070 // for the calling thread to unblock
1071 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001073 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 loge("getAllowedNetworkTypesBitmask: CommandException: "
1076 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001078 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001079 }
1080 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001081 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 break;
1083
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1087 request);
1088 Pair<Integer, Long> reasonWithNetworkTypes =
1089 (Pair<Integer, Long>) request.argument;
1090 getPhoneFromRequest(request).setAllowedNetworkTypes(
1091 reasonWithNetworkTypes.first,
1092 reasonWithNetworkTypes.second,
1093 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 break;
1095
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1097 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 break;
1099
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001100 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1101 request = (MainThreadRequest)msg.obj;
1102 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001103 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001104 break;
1105
1106 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1107 ar = (AsyncResult)msg.obj;
1108 request = (MainThreadRequest)ar.userObj;
1109 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001111 break;
1112
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001113 case CMD_SET_VOICEMAIL_NUMBER:
1114 request = (MainThreadRequest) msg.obj;
1115 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1116 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001117 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1118 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001119 break;
1120
1121 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1122 handleNullReturnEvent(msg, "setVoicemailNumber");
1123 break;
1124
Stuart Scott54788802015-03-30 13:18:01 -07001125 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1128 request);
1129 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1130 break;
1131
1132 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1133 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1134 break;
1135
Shishir Agrawal302c8692015-06-19 13:49:39 -07001136 case CMD_PERFORM_NETWORK_SCAN:
1137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1139 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1140 break;
1141
Hall Liu27d24262020-09-18 19:04:59 -07001142 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001145 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1146 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1147 request.argument;
1148 int callForwardingReason = args.first;
1149 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001150 break;
Hall Liu27d24262020-09-18 19:04:59 -07001151 }
1152 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001155 TelephonyManager.CallForwardingInfoCallback callback =
1156 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1157 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001158 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001159 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001160 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1161 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1162 // Service Class is a bit mask per 3gpp 27.007. Search for
1163 // any service for voice call.
1164 if ((callForwardInfo.serviceClass
1165 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001166 callForwardingInfo = new CallForwardingInfo(
1167 callForwardInfo.status
1168 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001169 callForwardInfo.reason,
1170 callForwardInfo.number,
1171 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 break;
1173 }
1174 }
1175 // Didn't find a call forward info for voice call.
1176 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001177 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1178 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 }
Hall Liu27d24262020-09-18 19:04:59 -07001180 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 } else {
1182 if (ar.result == null) {
1183 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1184 }
1185 if (ar.exception != null) {
1186 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1187 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 int errorCode = TelephonyManager
1189 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 if (ar.exception instanceof CommandException) {
1191 CommandException.Error error =
1192 ((CommandException) (ar.exception)).getCommandError();
1193 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager
1195 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 }
1200 }
Hall Liu27d24262020-09-18 19:04:59 -07001201 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203 break;
Hall Liu27d24262020-09-18 19:04:59 -07001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205
Hall Liu27d24262020-09-18 19:04:59 -07001206 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001209 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001211 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1212 request.argument).first;
1213 request.phone.setCallForwardingOption(
1214 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001215 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001216 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001217 callForwardingInfoToSet.getReason(),
1218 callForwardingInfoToSet.getNumber(),
1219 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1220 break;
Hall Liu27d24262020-09-18 19:04:59 -07001221 }
Shuo Qian4a594052020-01-23 11:59:30 -08001222
Hall Liu27d24262020-09-18 19:04:59 -07001223 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001226 Consumer<Integer> callback =
1227 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1228 request.argument).second;
1229 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 int errorCode = TelephonyManager.CallForwardingInfoCallback
1232 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001233 if (ar.exception instanceof CommandException) {
1234 CommandException.Error error =
1235 ((CommandException) (ar.exception)).getCommandError();
1236 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 errorCode = TelephonyManager.CallForwardingInfoCallback
1238 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001239 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001242 }
1243 }
1244 callback.accept(errorCode);
1245 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1254 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001261 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001262 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001264 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 // Service Class is a bit mask per 3gpp 27.007.
1266 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001267 if (callForwardResults.length > 1
1268 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001269 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001270 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001271 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1272 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001274 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
1276 } else {
1277 if (ar.result == null) {
1278 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1279 }
1280 if (ar.exception != null) {
1281 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1282 }
1283 if (ar.exception instanceof CommandException) {
1284 CommandException.Error error =
1285 ((CommandException) (ar.exception)).getCommandError();
1286 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001287 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001288 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001289 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1290 callWaitingStatus =
1291 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001292 }
1293 }
1294 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001296 break;
Hall Liu27d24262020-09-18 19:04:59 -07001297 }
Shuo Qian4a594052020-01-23 11:59:30 -08001298
Hall Liu27d24262020-09-18 19:04:59 -07001299 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001300 request = (MainThreadRequest) msg.obj;
1301 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001302 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1303 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001310 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1311 Consumer<Integer> callback =
1312 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1313 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001314 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001315 if (ar.exception instanceof CommandException) {
1316 CommandException.Error error =
1317 ((CommandException) (ar.exception)).getCommandError();
1318 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1319 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1321 callback.accept(
1322 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001323 } else {
1324 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1325 }
1326 } else {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1328 }
1329 } else {
1330 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1331 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001332 }
Shuo Qian4a594052020-01-23 11:59:30 -08001333 break;
Hall Liu27d24262020-09-18 19:04:59 -07001334 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001335 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
1338 CellNetworkScanResult cellScanResult;
1339 if (ar.exception == null && ar.result != null) {
1340 cellScanResult = new CellNetworkScanResult(
1341 CellNetworkScanResult.STATUS_SUCCESS,
1342 (List<OperatorInfo>) ar.result);
1343 } else {
1344 if (ar.result == null) {
1345 loge("getCellNetworkScanResults: Empty response");
1346 }
1347 if (ar.exception != null) {
1348 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1349 }
1350 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1351 if (ar.exception instanceof CommandException) {
1352 CommandException.Error error =
1353 ((CommandException) (ar.exception)).getCommandError();
1354 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1355 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1356 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1357 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1358 }
1359 }
1360 cellScanResult = new CellNetworkScanResult(errorCode, null);
1361 }
1362 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001363 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001364 break;
1365
1366 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1367 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001368 ManualNetworkSelectionArgument selArg =
1369 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001370 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1371 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001372 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1373 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001374 break;
1375
1376 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 if (ar.exception == null) {
1380 request.result = true;
1381 } else {
1382 request.result = false;
1383 loge("setNetworkSelectionModeManual " + ar.exception);
1384 }
1385 notifyRequester(request);
1386 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001387 break;
1388
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 case CMD_GET_MODEM_ACTIVITY_INFO:
1390 request = (MainThreadRequest) msg.obj;
1391 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001392 if (defaultPhone != null) {
1393 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001394 } else {
1395 ResultReceiver result = (ResultReceiver) request.argument;
1396 Bundle bundle = new Bundle();
1397 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001398 new ModemActivityInfo(0, 0, 0,
1399 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001400 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001401 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001402 break;
1403
Hall Liud0f208c2020-10-14 16:54:44 -07001404 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001408 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001409 if (mLastModemActivityInfo == null) {
1410 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1411 mLastModemActivitySpecificInfo[0] =
1412 new ActivityStatsTechSpecificInfo(
1413 0,
1414 0,
1415 new int[ModemActivityInfo.getNumTxPowerLevels()],
1416 0);
1417 mLastModemActivityInfo =
1418 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1419 }
1420
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001421 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001422 // Update the last modem activity info and the result of the request.
1423 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1424 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001425 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001426 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001427 mLastModemActivityInfo =
1428 new ModemActivityInfo(
1429 mLastModemActivityInfo.getTimestampMillis(),
1430 mLastModemActivityInfo.getSleepTimeMillis(),
1431 mLastModemActivityInfo.getIdleTimeMillis(),
1432 mLastModemActivitySpecificInfo);
1433
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 } else {
1435 if (ar.result == null) {
1436 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001437 error = TelephonyManager.ModemActivityInfoException
1438 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001439 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001440 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001441 error = TelephonyManager.ModemActivityInfoException
1442 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 } else {
1444 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 }
1448 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001449 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001450 if (mLastModemActivityInfo != null) {
1451 bundle.putParcelable(
1452 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1453 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001454 } else {
1455 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1456 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001458 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001460 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461
Meng Wang1a7c35a2016-05-05 20:56:15 -07001462 case CMD_SET_ALLOWED_CARRIERS:
1463 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001464 CarrierRestrictionRules argument =
1465 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001466 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001467 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001468 break;
1469
1470 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
1473 if (ar.exception == null && ar.result != null) {
1474 request.result = ar.result;
1475 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001476 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1477 if (ar.exception instanceof CommandException) {
1478 loge("setAllowedCarriers: CommandException: " + ar.exception);
1479 CommandException.Error error =
1480 ((CommandException) (ar.exception)).getCommandError();
1481 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1482 request.result =
1483 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1484 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001485 } else {
1486 loge("setAllowedCarriers: Unknown exception");
1487 }
1488 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001489 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001490 break;
1491
1492 case CMD_GET_ALLOWED_CARRIERS:
1493 request = (MainThreadRequest) msg.obj;
1494 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001495 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001496 break;
1497
1498 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 if (ar.exception == null && ar.result != null) {
1502 request.result = ar.result;
1503 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001504 request.result = new IllegalStateException(
1505 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001506 if (ar.result == null) {
1507 loge("getAllowedCarriers: Empty response");
1508 } else if (ar.exception instanceof CommandException) {
1509 loge("getAllowedCarriers: CommandException: " +
1510 ar.exception);
1511 } else {
1512 loge("getAllowedCarriers: Unknown exception");
1513 }
1514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001515 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001516 break;
1517
Nathan Haroldb3014052017-01-25 15:57:32 -08001518 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1519 ar = (AsyncResult) msg.obj;
1520 request = (MainThreadRequest) ar.userObj;
1521 if (ar.exception == null && ar.result != null) {
1522 request.result = ar.result;
1523 } else {
1524 request.result = new IllegalArgumentException(
1525 "Failed to retrieve Forbidden Plmns");
1526 if (ar.result == null) {
1527 loge("getForbiddenPlmns: Empty response");
1528 } else {
1529 loge("getForbiddenPlmns: Unknown exception");
1530 }
1531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001532 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001533 break;
1534
1535 case CMD_GET_FORBIDDEN_PLMNS:
1536 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001537 uiccPort = getUiccPortFromRequest(request);
1538 if (uiccPort == null) {
1539 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001540 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001541 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001542 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001543 break;
1544 }
1545 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001546 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 if (uiccApp == null) {
1548 loge("getForbiddenPlmns() no app with specified type -- "
1549 + appType);
1550 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001551 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001552 break;
1553 } else {
1554 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1555 + " specified type -- " + appType);
1556 }
1557 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1558 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1559 onCompleted);
1560 break;
1561
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001562 case CMD_SWITCH_SLOTS:
1563 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001564 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001565 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001566 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001567 break;
1568
1569 case EVENT_SWITCH_SLOTS_DONE:
1570 ar = (AsyncResult) msg.obj;
1571 request = (MainThreadRequest) ar.userObj;
1572 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 notifyRequester(request);
1574 break;
1575 case CMD_GET_NETWORK_SELECTION_MODE:
1576 request = (MainThreadRequest) msg.obj;
1577 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1578 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1579 break;
1580
1581 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1582 ar = (AsyncResult) msg.obj;
1583 request = (MainThreadRequest) ar.userObj;
1584 if (ar.exception != null) {
1585 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1586 } else {
1587 int mode = ((int[]) ar.result)[0];
1588 if (mode == 0) {
1589 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1590 } else {
1591 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1592 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001593 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001594 notifyRequester(request);
1595 break;
1596 case CMD_GET_CDMA_ROAMING_MODE:
1597 request = (MainThreadRequest) msg.obj;
1598 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1599 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1600 break;
1601 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 if (ar.exception != null) {
1605 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1606 } else {
1607 request.result = ((int[]) ar.result)[0];
1608 }
1609 notifyRequester(request);
1610 break;
1611 case CMD_SET_CDMA_ROAMING_MODE:
1612 request = (MainThreadRequest) msg.obj;
1613 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1614 int mode = (int) request.argument;
1615 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1616 break;
1617 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 request.result = ar.exception == null;
1621 notifyRequester(request);
1622 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001623 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1624 request = (MainThreadRequest) msg.obj;
1625 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1626 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1627 break;
1628 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception != null) {
1632 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1633 } else {
1634 request.result = ((int[]) ar.result)[0];
1635 }
1636 notifyRequester(request);
1637 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1639 request = (MainThreadRequest) msg.obj;
1640 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1641 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001642 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1643 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001644 break;
1645 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
1648 request.result = ar.exception == null;
1649 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001650 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 case CMD_GET_ALL_CELL_INFO:
1652 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001653 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001654 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001655 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001656 case EVENT_GET_ALL_CELL_INFO_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001659 // If a timeout occurs, the response will be null
1660 request.result = (ar.exception == null && ar.result != null)
1661 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 synchronized (request) {
1663 request.notifyAll();
1664 }
1665 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001666 case CMD_REQUEST_CELL_INFO_UPDATE:
1667 request = (MainThreadRequest) msg.obj;
1668 request.phone.requestCellInfoUpdate(request.workSource,
1669 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1670 break;
1671 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1672 ar = (AsyncResult) msg.obj;
1673 request = (MainThreadRequest) ar.userObj;
1674 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1675 try {
1676 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001677 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001678 cb.onError(
1679 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1680 ar.exception.getClass().getName(),
1681 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001682 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001683 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001684 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 } else {
1686 // use the result as returned
1687 cb.onCellInfo((List<CellInfo>) ar.result);
1688 }
1689 } catch (RemoteException re) {
1690 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1691 }
1692 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001693 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 request = (MainThreadRequest) msg.obj;
1695 WorkSource ws = (WorkSource) request.argument;
1696 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001697 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001698 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001699 }
1700 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 if (ar.exception == null) {
1704 request.result = ar.result;
1705 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001706 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001707 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001708 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 }
1710
1711 synchronized (request) {
1712 request.notifyAll();
1713 }
1714 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001715 }
chen xu6dac5ab2018-10-26 17:39:23 -07001716 case CMD_MODEM_REBOOT:
1717 request = (MainThreadRequest) msg.obj;
1718 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001719 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001720 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001721 case EVENT_CMD_MODEM_REBOOT_DONE:
1722 handleNullReturnEvent(msg, "rebootModem");
1723 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001724 case CMD_REQUEST_ENABLE_MODEM:
1725 request = (MainThreadRequest) msg.obj;
1726 boolean enable = (boolean) request.argument;
1727 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001728 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001729 PhoneConfigurationManager.getInstance()
1730 .enablePhone(request.phone, enable, onCompleted);
1731 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001732 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001736 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001737 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001738 if ((boolean) request.result) {
1739 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1740 updateModemStateMetrics();
1741 } else {
1742 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1743 + ar.exception);
1744 }
1745 notifyRequester(request);
1746 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001747 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001748 case CMD_GET_MODEM_STATUS:
1749 request = (MainThreadRequest) msg.obj;
1750 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1751 PhoneConfigurationManager.getInstance()
1752 .getPhoneStatusFromModem(request.phone, onCompleted);
1753 break;
1754 case EVENT_GET_MODEM_STATUS_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 int id = request.phone.getPhoneId();
1758 if (ar.exception == null && ar.result != null) {
1759 request.result = ar.result;
1760 //update the cache as modem status has changed
1761 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1762 (boolean) request.result);
1763 } else {
1764 // Return true if modem status cannot be retrieved. For most cases,
1765 // modem status is on. And for older version modems, GET_MODEM_STATUS
1766 // and disable modem are not supported. Modem is always on.
1767 // TODO: this should be fixed in R to support a third
1768 // status UNKNOWN b/131631629
1769 request.result = true;
1770 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1771 + ar.exception);
1772 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001773 notifyRequester(request);
1774 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001775 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1776 request = (MainThreadRequest) msg.obj;
1777 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1778 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1779 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1780 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1781 break;
1782 }
1783 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1787 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1788 args.second.accept(ar.exception == null);
1789 notifyRequester(request);
1790 break;
1791 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001792 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1793 request = (MainThreadRequest) msg.obj;
1794 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1795 Phone phone = getPhoneFromRequest(request);
1796 if (phone != null) {
1797 phone.getSystemSelectionChannels(onCompleted);
1798 } else {
1799 loge("getSystemSelectionChannels: No phone object");
1800 request.result = new ArrayList<RadioAccessSpecifier>();
1801 notifyRequester(request);
1802 }
1803 break;
1804 }
1805 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1806 ar = (AsyncResult) msg.obj;
1807 request = (MainThreadRequest) ar.userObj;
1808 if (ar.exception == null && ar.result != null) {
1809 request.result = ar.result;
1810 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001811 request.result = new IllegalStateException(
1812 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001813 if (ar.result == null) {
1814 loge("getSystemSelectionChannels: Empty response");
1815 } else {
1816 loge("getSystemSelectionChannels: Unknown exception");
1817 }
1818 }
1819 notifyRequester(request);
1820 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001821 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1822 ar = (AsyncResult) msg.obj;
1823 request = (MainThreadRequest) ar.userObj;
1824 if (ar.exception == null && ar.result != null) {
1825 request.result = ar.result;
1826 } else {
1827 request.result = -1;
1828 loge("Failed to set Forbidden Plmns");
1829 if (ar.result == null) {
1830 loge("setForbidenPlmns: Empty response");
1831 } else if (ar.exception != null) {
1832 loge("setForbiddenPlmns: Exception: " + ar.exception);
1833 request.result = -1;
1834 } else {
1835 loge("setForbiddenPlmns: Unknown exception");
1836 }
1837 }
1838 notifyRequester(request);
1839 break;
1840 case CMD_SET_FORBIDDEN_PLMNS:
1841 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001842 uiccPort = getUiccPortFromRequest(request);
1843 if (uiccPort == null) {
1844 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001845 request.result = -1;
1846 notifyRequester(request);
1847 break;
1848 }
1849 Pair<Integer, List<String>> setFplmnsArgs =
1850 (Pair<Integer, List<String>>) request.argument;
1851 appType = setFplmnsArgs.first;
1852 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001853 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001854 if (uiccApp == null) {
1855 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1856 request.result = -1;
1857 loge("Failed to get UICC App");
1858 notifyRequester(request);
1859 } else {
1860 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1861 ((SIMRecords) uiccApp.getIccRecords())
1862 .setForbiddenPlmns(onCompleted, fplmns);
1863 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001864 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001865 case CMD_ERASE_MODEM_CONFIG:
1866 request = (MainThreadRequest) msg.obj;
1867 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1868 defaultPhone.eraseModemConfig(onCompleted);
1869 break;
1870 case EVENT_ERASE_MODEM_CONFIG_DONE:
1871 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001872 break;
zoey chene02881a2019-12-30 16:11:23 +08001873
Kai Shif70f46f2021-03-03 13:59:46 -08001874 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1875 request = (MainThreadRequest) msg.obj;
1876 request.result = defaultPhone.eraseDataInSharedPreferences();
1877 notifyRequester(request);
1878 break;
1879
zoey chene02881a2019-12-30 16:11:23 +08001880 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1883 Pair<String, String> changed = (Pair<String, String>) request.argument;
1884 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1885 changed.first, changed.second, onCompleted);
1886 break;
1887 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890 if (ar.exception == null) {
1891 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001892 // If the operation is successful, update the PIN storage
1893 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1894 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001895 UiccController.getInstance().getPinStorage()
1896 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001897 } else {
1898 request.result = msg.arg1;
1899 }
1900 notifyRequester(request);
1901 break;
1902
Michele Berionne5e411512020-11-13 02:36:59 +00001903 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001904 request = (MainThreadRequest) msg.obj;
1905 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1906 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1907 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1908 enabled.first, enabled.second, onCompleted);
1909 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001910 }
zoey chene02881a2019-12-30 16:11:23 +08001911 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1912 ar = (AsyncResult) msg.obj;
1913 request = (MainThreadRequest) ar.userObj;
1914 if (ar.exception == null) {
1915 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001916 // If the operation is successful, update the PIN storage
1917 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1918 int phoneId = getPhoneFromRequest(request).getPhoneId();
1919 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001920 UiccController.getInstance().getPinStorage()
1921 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001922 } else {
1923 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1924 }
zoey chene02881a2019-12-30 16:11:23 +08001925 } else {
1926 request.result = msg.arg1;
1927 }
Michele Berionne5e411512020-11-13 02:36:59 +00001928
1929
zoey chene02881a2019-12-30 16:11:23 +08001930 notifyRequester(request);
1931 break;
1932
Peter Wangdafb9ac2020-01-15 14:13:38 -08001933 case MSG_NOTIFY_USER_ACTIVITY:
1934 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001935 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001936 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1937 getDefaultPhone().getContext().sendBroadcastAsUser(
1938 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1939 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001940
1941 case CMD_SET_DATA_THROTTLING: {
1942 request = (MainThreadRequest) msg.obj;
1943 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1944 DataThrottlingRequest dataThrottlingRequest =
1945 (DataThrottlingRequest) request.argument;
1946 Phone phone = getPhoneFromRequest(request);
1947 if (phone != null) {
1948 phone.setDataThrottling(onCompleted,
1949 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1950 dataThrottlingRequest.getCompletionDurationMillis());
1951 } else {
1952 loge("setDataThrottling: No phone object");
1953 request.result =
1954 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1955 notifyRequester(request);
1956 }
1957
1958 break;
1959 }
1960 case EVENT_SET_DATA_THROTTLING_DONE:
1961 ar = (AsyncResult) msg.obj;
1962 request = (MainThreadRequest) ar.userObj;
1963
1964 if (ar.exception == null) {
1965 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1966 } else if (ar.exception instanceof CommandException) {
1967 loge("setDataThrottling: CommandException: " + ar.exception);
1968 CommandException.Error error =
1969 ((CommandException) (ar.exception)).getCommandError();
1970
1971 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1972 request.result = TelephonyManager
1973 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1974 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1975 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001976 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1977 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001978 } else {
1979 request.result =
1980 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1981 }
1982 } else {
1983 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1984 }
1985 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1986 notifyRequester(request);
1987 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001988
1989 case CMD_SET_SIM_POWER: {
1990 request = (MainThreadRequest) msg.obj;
1991 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1992 request = (MainThreadRequest) msg.obj;
1993 int stateToSet =
1994 ((Pair<Integer, IIntegerConsumer>)
1995 request.argument).first;
1996 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1997 break;
1998 }
1999 case EVENT_SET_SIM_POWER_DONE: {
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 IIntegerConsumer callback =
2003 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2004 if (ar.exception != null) {
2005 loge("setSimPower exception: " + ar.exception);
2006 int errorCode = TelephonyManager.CallForwardingInfoCallback
2007 .RESULT_ERROR_UNKNOWN;
2008 if (ar.exception instanceof CommandException) {
2009 CommandException.Error error =
2010 ((CommandException) (ar.exception)).getCommandError();
2011 if (error == CommandException.Error.SIM_ERR) {
2012 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2013 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2014 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2015 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2016 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2017 } else {
2018 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2019 }
2020 }
2021 try {
2022 callback.accept(errorCode);
2023 } catch (RemoteException e) {
2024 // Ignore if the remote process is no longer available to call back.
2025 Log.w(LOG_TAG, "setSimPower: callback not available.");
2026 }
2027 } else {
2028 try {
2029 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2030 } catch (RemoteException e) {
2031 // Ignore if the remote process is no longer available to call back.
2032 Log.w(LOG_TAG, "setSimPower: callback not available.");
2033 }
2034 }
2035 break;
2036 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002037 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2038 request = (MainThreadRequest) msg.obj;
2039
2040 final Phone phone = getPhoneFromRequest(request);
2041 if (phone == null || phone.getServiceStateTracker() == null) {
2042 request.result = new IllegalStateException("Phone or SST is null");
2043 notifyRequester(request);
2044 break;
2045 }
2046
2047 Pair<Integer, SignalStrengthUpdateRequest> pair =
2048 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2049 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2050 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002051 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002052 request.subId, pair.first /*callingUid*/,
2053 pair.second /*request*/, onCompleted);
2054 break;
2055 }
2056 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2057 ar = (AsyncResult) msg.obj;
2058 request = (MainThreadRequest) ar.userObj;
2059 // request.result will be the exception of ar if present, true otherwise.
2060 // Be cautious not to leave result null which will wait() forever
2061 request.result = ar.exception != null ? ar.exception : true;
2062 notifyRequester(request);
2063 break;
2064 }
2065 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2066 request = (MainThreadRequest) msg.obj;
2067
2068 Phone phone = getPhoneFromRequest(request);
2069 if (phone == null || phone.getServiceStateTracker() == null) {
2070 request.result = new IllegalStateException("Phone or SST is null");
2071 notifyRequester(request);
2072 break;
2073 }
2074
2075 Pair<Integer, SignalStrengthUpdateRequest> pair =
2076 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2077 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2078 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002079 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002080 request.subId, pair.first /*callingUid*/,
2081 pair.second /*request*/, onCompleted);
2082 break;
2083 }
2084 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2085 ar = (AsyncResult) msg.obj;
2086 request = (MainThreadRequest) ar.userObj;
2087 request.result = ar.exception != null ? ar.exception : true;
2088 notifyRequester(request);
2089 break;
2090 }
Jordan Liu109698e2020-11-24 14:50:34 -08002091
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002092 case CMD_GET_SLICING_CONFIG: {
2093 request = (MainThreadRequest) msg.obj;
2094 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2095 request.phone.getSlicingConfig(onCompleted);
2096 break;
2097 }
2098 case EVENT_GET_SLICING_CONFIG_DONE: {
2099 ar = (AsyncResult) msg.obj;
2100 request = (MainThreadRequest) ar.userObj;
2101 ResultReceiver result = (ResultReceiver) request.argument;
2102
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002103 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002104 Bundle bundle = new Bundle();
2105 int resultCode = 0;
2106 if (ar.exception != null) {
2107 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2108 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002109 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002110 } else if (ar.result == null) {
2111 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002112 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 } else {
2114 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002115 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2116 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002117 }
2118
2119 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002120 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 }
2122 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2123 result.send(resultCode, bundle);
2124 notifyRequester(request);
2125 break;
2126 }
2127
Michele Berionne5e411512020-11-13 02:36:59 +00002128 case CMD_PREPARE_UNATTENDED_REBOOT:
2129 request = (MainThreadRequest) msg.obj;
2130 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002131 UiccController.getInstance().getPinStorage()
2132 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002133 notifyRequester(request);
2134 break;
2135
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 default:
2137 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2138 break;
2139 }
2140 }
Jake Hambye994d462014-02-03 13:10:13 -08002141
Pengquan Menga1bb6272018-09-06 09:59:22 -07002142 private void notifyRequester(MainThreadRequest request) {
2143 synchronized (request) {
2144 request.notifyAll();
2145 }
2146 }
2147
Jake Hambye994d462014-02-03 13:10:13 -08002148 private void handleNullReturnEvent(Message msg, String command) {
2149 AsyncResult ar = (AsyncResult) msg.obj;
2150 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2151 if (ar.exception == null) {
2152 request.result = true;
2153 } else {
2154 request.result = false;
2155 if (ar.exception instanceof CommandException) {
2156 loge(command + ": CommandException: " + ar.exception);
2157 } else {
2158 loge(command + ": Unknown exception");
2159 }
2160 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002161 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 }
2164
2165 /**
2166 * Posts the specified command to be executed on the main thread,
2167 * waits for the request to complete, and returns the result.
2168 * @see #sendRequestAsync
2169 */
2170 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002171 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2172 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002173 }
2174
2175 /**
2176 * Posts the specified command to be executed on the main thread,
2177 * waits for the request to complete, and returns the result.
2178 * @see #sendRequestAsync
2179 */
2180 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2181 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002182 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002183 }
2184
2185 /**
2186 * Posts the specified command to be executed on the main thread,
2187 * waits for the request to complete, and returns the result.
2188 * @see #sendRequestAsync
2189 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002190 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002191 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2192 }
2193
2194 /**
2195 * Posts the specified command to be executed on the main thread,
2196 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2197 * if not timeout or null otherwise.
2198 * @see #sendRequestAsync
2199 */
2200 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2201 long timeoutInMs) {
2202 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002203 }
2204
2205 /**
2206 * Posts the specified command to be executed on the main thread,
2207 * waits for the request to complete, and returns the result.
2208 * @see #sendRequestAsync
2209 */
Nathan Harold92bed182018-10-12 18:16:49 -07002210 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002211 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002212 }
2213
2214 /**
2215 * Posts the specified command to be executed on the main thread,
2216 * waits for the request to complete, and returns the result.
2217 * @see #sendRequestAsync
2218 */
2219 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002220 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2221 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002222 }
2223
2224 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002225 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2226 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2227 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002228 * @see #sendRequestAsync
2229 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002230 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2231 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2233 throw new RuntimeException("This method will deadlock if called from the main thread.");
2234 }
2235
Nathan Harold92bed182018-10-12 18:16:49 -07002236 MainThreadRequest request = null;
2237 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2238 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2239 } else if (phone != null) {
2240 request = new MainThreadRequest(argument, phone, workSource);
2241 } else {
2242 request = new MainThreadRequest(argument, subId, workSource);
2243 }
2244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 Message msg = mMainThreadHandler.obtainMessage(command, request);
2246 msg.sendToTarget();
2247
Rambo Wang0f050d82021-02-12 11:43:36 -08002248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002250 if (timeoutInMs >= 0) {
2251 // Wait for at least timeoutInMs before returning null request result
2252 long now = SystemClock.elapsedRealtime();
2253 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002254 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002255 try {
2256 request.wait(deadline - now);
2257 } catch (InterruptedException e) {
2258 // Do nothing, go back and check if request is completed or timeout
2259 } finally {
2260 now = SystemClock.elapsedRealtime();
2261 }
2262 }
2263 } else {
2264 // Wait for the request to complete
2265 while (request.result == null) {
2266 try {
2267 request.wait();
2268 } catch (InterruptedException e) {
2269 // Do nothing, go back and wait until the request is complete
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272 }
2273 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002274 if (request.result == null) {
2275 Log.wtf(LOG_TAG,
2276 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 return request.result;
2279 }
2280
2281 /**
2282 * Asynchronous ("fire and forget") version of sendRequest():
2283 * Posts the specified command to be executed on the main thread, and
2284 * returns immediately.
2285 * @see #sendRequest
2286 */
2287 private void sendRequestAsync(int command) {
2288 mMainThreadHandler.sendEmptyMessage(command);
2289 }
2290
2291 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002292 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002293 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002294 */
2295 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002296 sendRequestAsync(command, argument, null, null);
2297 }
2298
2299 /**
2300 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2301 * @see {@link #sendRequest(int,Object)}
2302 */
2303 private void sendRequestAsync(
2304 int command, Object argument, Phone phone, WorkSource workSource) {
2305 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002306 Message msg = mMainThreadHandler.obtainMessage(command, request);
2307 msg.sendToTarget();
2308 }
2309
2310 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 * Initialize the singleton PhoneInterfaceManager instance.
2312 * This is only done once, at startup, from PhoneApp.onCreate().
2313 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002314 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 synchronized (PhoneInterfaceManager.class) {
2316 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002317 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 } else {
2319 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2320 }
2321 return sInstance;
2322 }
2323 }
2324
2325 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002326 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002329 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002330 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002332 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002334 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002335 mTelephonySharedPreferences =
2336 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002337 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002338 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002339 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002340 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002341 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 publish();
2343 }
2344
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002345 private Phone getDefaultPhone() {
2346 Phone thePhone = getPhone(getDefaultSubscription());
2347 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2348 }
2349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 private void publish() {
2351 if (DBG) log("publish: " + this);
2352
Peter Wangc035ce42020-01-08 21:00:22 -08002353 TelephonyFrameworkInitializer
2354 .getTelephonyServiceManager()
2355 .getTelephonyServiceRegisterer()
2356 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358
Stuart Scott584921c2015-01-15 17:10:34 -08002359 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002360 if (request.phone != null) {
2361 return request.phone;
2362 } else {
2363 return getPhoneFromSubId(request.subId);
2364 }
2365 }
2366
2367 private Phone getPhoneFromSubId(int subId) {
2368 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2369 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002370 }
2371
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002372 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002373 Phone phone = getPhoneFromRequest(request);
2374 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002375 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002376 }
2377
Wink Saville36469e72014-06-11 15:17:00 -07002378 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002379 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002380 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382
Kai Shif70f46f2021-03-03 13:59:46 -08002383 private void sendEraseModemConfig(@NonNull Phone phone) {
2384 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2385 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2386 }
2387
2388 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2389 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2390 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002391 }
2392
Peter Wang44b186e2020-01-13 23:33:09 -08002393 private boolean isImsAvailableOnDevice() {
2394 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2395 if (pm == null) {
2396 // For some reason package manger is not available.. This will fail internally anyway,
2397 // so do not throw error and allow.
2398 return true;
2399 }
2400 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2401 }
2402
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002404 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002405 }
2406
Wink Savilleb564aae2014-10-23 10:18:09 -07002407 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 if (DBG) log("dial: " + number);
2409 // No permission check needed here: This is just a wrapper around the
2410 // ACTION_DIAL intent, which is available to any app since it puts up
2411 // the UI before it does anything.
2412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 String url = createTelUrl(number);
2416 if (url == null) {
2417 return;
2418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420 // PENDING: should we just silently fail if phone is offhook or ringing?
2421 PhoneConstants.State state = mCM.getState(subId);
2422 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2423 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2424 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2425 mApp.startActivity(intent);
2426 }
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430 }
2431
2432 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002433 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002434 }
2435
Wink Savilleb564aae2014-10-23 10:18:09 -07002436 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 if (DBG) log("call: " + number);
2438
2439 // This is just a wrapper around the ACTION_CALL intent, but we still
2440 // need to do a permission check since we're calling startActivity()
2441 // from the context of the phone app.
2442 enforceCallPermission();
2443
Jordan Liu1617b712019-07-10 15:06:26 -07002444 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 != AppOpsManager.MODE_ALLOWED) {
2446 return;
2447 }
2448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 String url = createTelUrl(number);
2452 if (url == null) {
2453 return;
2454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 boolean isValid = false;
2457 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2458 if (slist != null) {
2459 for (SubscriptionInfo subInfoRecord : slist) {
2460 if (subInfoRecord.getSubscriptionId() == subId) {
2461 isValid = true;
2462 break;
2463 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002464 }
Wink Saville08874612014-08-31 19:19:58 -07002465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 if (!isValid) {
2467 return;
2468 }
Wink Saville08874612014-08-31 19:19:58 -07002469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2471 intent.putExtra(SUBSCRIPTION_KEY, subId);
2472 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2473 mApp.startActivity(intent);
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
2476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Wink Savilleb564aae2014-10-23 10:18:09 -07002479 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002480 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002481 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2482 }
2483
Wink Savilleb564aae2014-10-23 10:18:09 -07002484 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002485 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002486 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2487 }
2488
Wink Savilleb564aae2014-10-23 10:18:09 -07002489 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002494 Phone phone = getPhone(subId);
2495 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 checkSimPin.start();
2497 return checkSimPin.unlockSim(null, pin);
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
2500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002508 Phone phone = getPhone(subId);
2509 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 checkSimPuk.start();
2511 return checkSimPuk.unlockSim(puk, pin);
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
2517 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002518 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 * a synchronous one.
2520 */
2521 private static class UnlockSim extends Thread {
2522
2523 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002524 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525
2526 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002527 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2528 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529
2530 // For replies from SimCard interface
2531 private Handler mHandler;
2532
2533 // For async handler to identify request type
2534 private static final int SUPPLY_PIN_COMPLETE = 100;
2535
Michele Berionne5e411512020-11-13 02:36:59 +00002536 UnlockSim(int phoneId, IccCard simCard) {
2537 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 mSimCard = simCard;
2539 }
2540
2541 @Override
2542 public void run() {
2543 Looper.prepare();
2544 synchronized (UnlockSim.this) {
2545 mHandler = new Handler() {
2546 @Override
2547 public void handleMessage(Message msg) {
2548 AsyncResult ar = (AsyncResult) msg.obj;
2549 switch (msg.what) {
2550 case SUPPLY_PIN_COMPLETE:
2551 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2552 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002553 mRetryCount = msg.arg1;
2554 if (ar.exception != null) {
2555 if (ar.exception instanceof CommandException &&
2556 ((CommandException)(ar.exception)).getCommandError()
2557 == CommandException.Error.PASSWORD_INCORRECT) {
2558 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002559 } //When UiccCardApp dispose,handle message and return exception
2560 else if (ar.exception instanceof CommandException &&
2561 ((CommandException) (ar.exception)).getCommandError()
2562 == CommandException.Error.ABORTED) {
2563 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002564 } else {
2565 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2566 }
2567 } else {
2568 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 mDone = true;
2571 UnlockSim.this.notifyAll();
2572 }
2573 break;
2574 }
2575 }
2576 };
2577 UnlockSim.this.notifyAll();
2578 }
2579 Looper.loop();
2580 }
2581
2582 /*
2583 * Use PIN or PUK to unlock SIM card
2584 *
2585 * If PUK is null, unlock SIM card with PIN
2586 *
2587 * If PUK is not null, unlock SIM card with PUK and set PIN code
2588 */
Wink Saville9de0f752013-10-22 19:04:03 -07002589 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590
2591 while (mHandler == null) {
2592 try {
2593 wait();
2594 } catch (InterruptedException e) {
2595 Thread.currentThread().interrupt();
2596 }
2597 }
2598 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2599
2600 if (puk == null) {
2601 mSimCard.supplyPin(pin, callback);
2602 } else {
2603 mSimCard.supplyPuk(puk, pin, callback);
2604 }
2605
2606 while (!mDone) {
2607 try {
2608 Log.d(LOG_TAG, "wait for done");
2609 wait();
2610 } catch (InterruptedException e) {
2611 // Restore the interrupted status
2612 Thread.currentThread().interrupt();
2613 }
2614 }
2615 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002616 int[] resultArray = new int[2];
2617 resultArray[0] = mResult;
2618 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002619
2620 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002621 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002622 }
2623
Wink Saville9de0f752013-10-22 19:04:03 -07002624 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626 }
2627
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002628 /**
2629 * This method has been removed due to privacy and stability concerns.
2630 */
2631 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002633 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2634 return;
Wink Saville36469e72014-06-11 15:17:00 -07002635 }
2636
Nathan Harold1f889d82020-06-04 17:05:26 -07002637 @Override
2638 public void updateServiceLocationWithPackageName(String callingPackage) {
2639 mApp.getSystemService(AppOpsManager.class)
2640 .checkPackage(Binder.getCallingUid(), callingPackage);
2641
Nathan Haroldf096d982020-11-18 17:18:06 -08002642 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002643 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2644 // Callers targeting S have no business invoking this method.
2645 return;
2646 }
2647
2648 LocationAccessPolicy.LocationPermissionResult locationResult =
2649 LocationAccessPolicy.checkLocationPermission(mApp,
2650 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2651 .setCallingPackage(callingPackage)
2652 .setCallingFeatureId(null)
2653 .setCallingPid(Binder.getCallingPid())
2654 .setCallingUid(Binder.getCallingUid())
2655 .setMethod("updateServiceLocation")
2656 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2657 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2658 .build());
2659 // Apps that lack location permission have no business calling this method;
2660 // however, because no permission was declared in the public API, denials must
2661 // all be "soft".
2662 switch (locationResult) {
2663 case DENIED_HARD: /* fall through */
2664 case DENIED_SOFT:
2665 return;
2666 }
2667
2668 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 final long identity = Binder.clearCallingIdentity();
2670 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002671 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002673 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002680 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002681 @Override
2682 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002683 return isRadioOnWithFeature(callingPackage, null);
2684 }
2685
2686
2687 @Override
2688 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2689 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2690 callingFeatureId);
2691 }
2692
2693 @Deprecated
2694 @Override
2695 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2696 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002697 }
2698
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002700 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2701 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002703 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002704 return false;
2705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706
2707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 return isRadioOnForSubscriber(subId);
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
2712 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002713 }
2714
2715 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 final Phone phone = getPhone(subId);
2719 if (phone != null) {
2720 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2721 } else {
2722 return false;
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
2728
2729 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002730 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 }
Wink Saville36469e72014-06-11 15:17:00 -07002732
Wink Savilleb564aae2014-10-23 10:18:09 -07002733 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
2736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 final Phone phone = getPhone(subId);
2739 if (phone != null) {
2740 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 }
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
2747 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002748 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002749 }
2750
Wink Savilleb564aae2014-10-23 10:18:09 -07002751 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 final Phone phone = getPhone(subId);
2757 if (phone == null) {
2758 return false;
2759 }
2760 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2761 toggleRadioOnOffForSubscriber(subId);
2762 }
2763 return true;
2764 } finally {
2765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 }
Wink Saville36469e72014-06-11 15:17:00 -07002768
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002769 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002770 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002771 /*
2772 * If any of the Radios are available, it will need to be
2773 * shutdown. So return true if any Radio is available.
2774 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2778 Phone phone = PhoneFactory.getPhone(i);
2779 if (phone != null && phone.isRadioAvailable()) return true;
2780 }
2781 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2782 return false;
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002786 }
2787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002789 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 enforceModifyPermission();
2791
2792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2795 logv("Shutting down Phone " + i);
2796 shutdownRadioUsingPhoneId(i);
2797 }
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 }
2801 }
2802
2803 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002804 Phone phone = PhoneFactory.getPhone(phoneId);
2805 if (phone != null && phone.isRadioAvailable()) {
2806 phone.shutdownRadio();
2807 }
2808 }
2809
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812
2813 final long identity = Binder.clearCallingIdentity();
2814 try {
2815 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2816 if (defaultPhone != null) {
2817 defaultPhone.setRadioPower(turnOn);
2818 return true;
2819 } else {
2820 loge("There's no default phone.");
2821 return false;
2822 }
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002825 }
Wink Saville36469e72014-06-11 15:17:00 -07002826 }
2827
Wink Savilleb564aae2014-10-23 10:18:09 -07002828 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830
2831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 final Phone phone = getPhone(subId);
2834 if (phone != null) {
2835 phone.setRadioPower(turnOn);
2836 return true;
2837 } else {
2838 return false;
2839 }
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 }
2844
Wink Saville36469e72014-06-11 15:17:00 -07002845 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002847 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 int subId = mSubscriptionController.getDefaultDataSubId();
2853 final Phone phone = getPhone(subId);
2854 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002855 if (phone.isUsingNewDataStack()) {
2856 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002857 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002858 } else {
2859 phone.getDataEnabledSettings().setDataEnabled(
2860 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 return true;
2863 } else {
2864 return false;
2865 }
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 }
2870
Wink Saville36469e72014-06-11 15:17:00 -07002871 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002872 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002873 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875
2876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 int subId = mSubscriptionController.getDefaultDataSubId();
2879 final Phone phone = getPhone(subId);
2880 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002881 if (phone.isUsingNewDataStack()) {
2882 phone.getDataSettingsManager().setDataEnabled(
Sarah Chinecc78c42022-03-31 21:16:48 -07002883 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08002884 } else {
2885 phone.getDataEnabledSettings().setDataEnabled(
2886 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888 return true;
2889 } else {
2890 return false;
2891 }
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002898 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 final Phone phone = getPhone(subId);
2902 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002903 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 } else {
2905 return false;
2906 }
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
2912 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002913 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002914 }
2915
pkanwarae03a6b2016-11-06 20:37:09 -08002916 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 enforceCallPermission();
2918
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2922 return;
2923 }
2924 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2925 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
pkanwar32d516d2016-10-14 19:37:38 -07002929 };
2930
Wink Savilleb564aae2014-10-23 10:18:09 -07002931 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2937 return false;
2938 }
2939 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 }
2944
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002945 /**
2946 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2947 * tag on getCallState Binder call.
2948 */
2949 @Deprecated
2950 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002952 if (CompatChanges.isChangeEnabled(
2953 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2954 Binder.getCallingUid())) {
2955 // Do not allow this API to be called on API version 31+, it should only be
2956 // called on old apps using this Binder call directly.
2957 throw new SecurityException("This method can only be used for applications "
2958 + "targeting API version 30 or less.");
2959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 final long identity = Binder.clearCallingIdentity();
2961 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002962 Phone phone = getPhone(getDefaultSubscription());
2963 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2964 PhoneConstantConversions.convertCallState(phone.getState());
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
2968 }
2969
2970 @Override
2971 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2972 if (CompatChanges.isChangeEnabled(
2973 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2974 Binder.getCallingUid())) {
2975 // Check READ_PHONE_STATE for API version 31+
2976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2977 featureId, "getCallStateForSubscription")) {
2978 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2979 + "targeting API level 31+.");
2980 }
2981 }
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2986 PhoneConstantConversions.convertCallState(phone.getState());
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 }
2991
Sanket Padawe356d7632015-06-22 14:03:32 -07002992 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002993 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002994 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2995 }
2996
2997 @Override
2998 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 final long identity = Binder.clearCallingIdentity();
3000 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003001 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003003 if (phone.isUsingNewDataStack()) {
3004 return phone.getDataNetworkController().getInternetDataNetworkState();
3005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3007 } else {
3008 return PhoneConstantConversions.convertDataState(
3009 PhoneConstants.DataState.DISCONNECTED);
3010 }
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003014 }
3015
Sanket Padawe356d7632015-06-22 14:03:32 -07003016 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003017 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003018 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3019 }
3020
3021 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003022 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 final long identity = Binder.clearCallingIdentity();
3024 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003025 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003027 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 } else {
3029 return TelephonyManager.DATA_ACTIVITY_NONE;
3030 }
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003034 }
3035
3036 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003037 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003038 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003039 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003040
3041 LocationAccessPolicy.LocationPermissionResult locationResult =
3042 LocationAccessPolicy.checkLocationPermission(mApp,
3043 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3044 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003045 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003046 .setCallingPid(Binder.getCallingPid())
3047 .setCallingUid(Binder.getCallingUid())
3048 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003049 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003050 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3051 .build());
3052 switch (locationResult) {
3053 case DENIED_HARD:
3054 throw new SecurityException("Not allowed to access cell location");
3055 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003056 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3057 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 }
3059
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003064 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003065 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Svetoslav64fad262015-04-14 14:35:21 -07003069 }
3070
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003072 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003073 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3074 // registered cell info, so return a NULL country instead.
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003077 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3078 // Get default phone in this case.
3079 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3080 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003081 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003083 if (phone == null) return "";
3084 ServiceStateTracker sst = phone.getServiceStateTracker();
3085 if (sst == null) return "";
3086 LocaleTracker lt = sst.getLocaleTracker();
3087 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003088 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003092 }
3093
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003094 /**
3095 * This method was removed due to potential issues caused by performing partial
3096 * updates of service state, and lack of a credible use case.
3097 *
3098 * This has the ability to break the telephony implementation by disabling notification of
3099 * changes in device connectivity. DO NOT USE THIS!
3100 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003101 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 public void enableLocationUpdates() {
3103 mApp.enforceCallingOrSelfPermission(
3104 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 }
3106
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003107 /**
3108 * This method was removed due to potential issues caused by performing partial
3109 * updates of service state, and lack of a credible use case.
3110 *
3111 * This has the ability to break the telephony implementation by disabling notification of
3112 * changes in device connectivity. DO NOT USE THIS!
3113 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 @Override
3115 public void disableLocationUpdates() {
3116 mApp.enforceCallingOrSelfPermission(
3117 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 }
3119
3120 @Override
3121 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003122 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3123 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003124 try {
3125 mApp.getSystemService(AppOpsManager.class)
3126 .checkPackage(Binder.getCallingUid(), callingPackage);
3127 } catch (SecurityException e) {
3128 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3129 throw e;
3130 }
3131
Nathan Haroldf096d982020-11-18 17:18:06 -08003132 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003133 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3134 throw new SecurityException(
3135 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3136 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003137
Jordan Liu1617b712019-07-10 15:06:26 -07003138 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003139 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3140 return null;
3141 }
Svetoslav64fad262015-04-14 14:35:21 -07003142
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003143 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003145 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003146 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147
Nathan Haroldf180aac2018-06-01 18:43:55 -07003148 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3149 for (CellInfo ci : info) {
3150 if (ci instanceof CellInfoGsm) {
3151 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3152 } else if (ci instanceof CellInfoWcdma) {
3153 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003155 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003156 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003159 private List<CellInfo> getCachedCellInfo() {
3160 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3161 for (Phone phone : PhoneFactory.getPhones()) {
3162 List<CellInfo> info = phone.getAllCellInfo();
3163 if (info != null) cellInfos.addAll(info);
3164 }
3165 return cellInfos;
3166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167
3168 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003169 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003170 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003171 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003172
3173 LocationAccessPolicy.LocationPermissionResult locationResult =
3174 LocationAccessPolicy.checkLocationPermission(mApp,
3175 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3176 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003177 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003178 .setCallingPid(Binder.getCallingPid())
3179 .setCallingUid(Binder.getCallingUid())
3180 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003181 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003182 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3183 .build());
3184 switch (locationResult) {
3185 case DENIED_HARD:
3186 throw new SecurityException("Not allowed to access cell info");
3187 case DENIED_SOFT:
3188 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 }
3190
Nathan Haroldf096d982020-11-18 17:18:06 -08003191 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003192 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3193 return getCachedCellInfo();
3194 }
3195
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003196 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003197 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3201 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003202 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003203 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 if (info != null) cellInfos.addAll(info);
3205 }
3206 return cellInfos;
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 }
3210 }
3211
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003212 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003213 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3214 String callingFeatureId) {
3215 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3216 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003217 }
3218
3219 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003220 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3221 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003222 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003224 }
3225
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003226 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3227 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003229 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003230
3231 LocationAccessPolicy.LocationPermissionResult locationResult =
3232 LocationAccessPolicy.checkLocationPermission(mApp,
3233 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3234 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003235 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003236 .setCallingPid(Binder.getCallingPid())
3237 .setCallingUid(Binder.getCallingUid())
3238 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003239 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3240 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003241 .build());
3242 switch (locationResult) {
3243 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003244 if (TelephonyPermissions
3245 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003246 // Safetynet logging for b/154934934
3247 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3248 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003249 throw new SecurityException("Not allowed to access cell info");
3250 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003251 if (TelephonyPermissions
3252 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003253 // Safetynet logging for b/154934934
3254 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3255 }
Nathan Harold5320c422019-05-09 10:26:08 -07003256 try {
3257 cb.onCellInfo(new ArrayList<CellInfo>());
3258 } catch (RemoteException re) {
3259 // Drop without consequences
3260 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003261 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003262 }
3263
Nathan Harolda939a962019-05-09 10:13:47 -07003264
3265 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003266 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3267
3268 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3269 }
3270
3271 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003273 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275
3276 final long identity = Binder.clearCallingIdentity();
3277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003278 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 }
3283
Shishir Agrawala9f32182016-04-12 12:00:16 -07003284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003285 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003286 Phone phone = PhoneFactory.getPhone(slotIndex);
3287 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003288 return null;
3289 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003290 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003291 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003292 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003293 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003294 return null;
3295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 return phone.getImei();
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
3302 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003303 }
3304
3305 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003306 public String getTypeAllocationCodeForSlot(int slotIndex) {
3307 Phone phone = PhoneFactory.getPhone(slotIndex);
3308 String tac = null;
3309 if (phone != null) {
3310 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003311 try {
3312 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3313 } catch (IndexOutOfBoundsException e) {
3314 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3315 return null;
3316 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003317 }
3318 return tac;
3319 }
3320
3321 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003322 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003323 try {
3324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3325 } catch (SecurityException se) {
3326 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3327 throw new SecurityException("Package " + callingPackage + " does not belong to "
3328 + Binder.getCallingUid());
3329 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003330 Phone phone = PhoneFactory.getPhone(slotIndex);
3331 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003332 return null;
3333 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334
Jeff Davidson913390f2018-02-23 17:11:49 -08003335 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003336 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003337 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003338 return null;
3339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 return phone.getMeid();
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
Jack Yu2af8d712017-03-15 17:14:14 -07003347 }
3348
3349 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003350 public String getManufacturerCodeForSlot(int slotIndex) {
3351 Phone phone = PhoneFactory.getPhone(slotIndex);
3352 String manufacturerCode = null;
3353 if (phone != null) {
3354 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003355 try {
3356 manufacturerCode =
3357 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3358 } catch (IndexOutOfBoundsException e) {
3359 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3360 return null;
3361 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003362 }
3363 return manufacturerCode;
3364 }
3365
3366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003367 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3368 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003369 Phone phone = PhoneFactory.getPhone(slotIndex);
3370 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 return null;
3372 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003373 int subId = phone.getSubId();
3374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003375 mApp, subId, callingPackage, callingFeatureId,
3376 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003377 return null;
3378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 return phone.getDeviceSvn();
3383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003386 }
3387
fionaxu43304da2017-11-27 22:51:16 -08003388 @Override
3389 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 final Phone phone = getPhone(subId);
3393 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
fionaxu43304da2017-11-27 22:51:16 -08003397 }
3398
3399 @Override
3400 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 final Phone phone = getPhone(subId);
3404 return phone == null ? null : phone.getCarrierName();
3405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
fionaxu43304da2017-11-27 22:51:16 -08003408 }
3409
calvinpanffe225e2018-11-01 19:43:06 +08003410 @Override
chen xu0026ca62019-03-06 15:28:50 -08003411 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 final Phone phone = getPhone(subId);
3415 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003416 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 }
3421
3422 @Override
chen xu0026ca62019-03-06 15:28:50 -08003423 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003427 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
3431 }
3432
chen xu651eec72018-11-11 19:03:44 -08003433 @Override
chen xu864e11c2018-12-06 22:10:03 -08003434 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3435 if (!isSubscriptionMccMnc) {
3436 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3437 }
chen xu651eec72018-11-11 19:03:44 -08003438 final Phone phone = PhoneFactory.getPhone(slotIndex);
3439 if (phone == null) {
3440 return TelephonyManager.UNKNOWN_CARRIER_ID;
3441 }
3442 final long identity = Binder.clearCallingIdentity();
3443 try {
3444 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 //
3451 // Internal helper methods.
3452 //
3453
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003454 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003455 * Make sure the caller is the calling package itself
3456 *
3457 * @throws SecurityException if the caller is not the calling package
3458 */
3459 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3460 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003461 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3462 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003463 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003464 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003465 } catch (PackageManager.NameNotFoundException e) {
3466 // packageUid is -1
3467 }
3468 if (packageUid != callingUid) {
3469 throw new SecurityException(message + ": Package " + callingPackage
3470 + " does not belong to " + callingUid);
3471 }
3472 }
3473
3474 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3476 *
3477 * @throws SecurityException if the caller does not have the required permission
3478 */
3479 private void enforceModifyPermission() {
3480 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3481 }
3482
Shuo Qian3b6ee772019-11-13 17:43:31 -08003483 private void enforceActiveEmergencySessionPermission() {
3484 mApp.enforceCallingOrSelfPermission(
3485 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3486 }
3487
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488 /**
3489 * Make sure the caller has the CALL_PHONE permission.
3490 *
3491 * @throws SecurityException if the caller does not have the required permission
3492 */
3493 private void enforceCallPermission() {
3494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3495 }
3496
paulhu5a773602019-08-23 19:17:33 +08003497 private void enforceSettingsPermission() {
3498 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003499 }
3500
Michele Berionne5e411512020-11-13 02:36:59 +00003501 private void enforceRebootPermission() {
3502 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3503 }
3504
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 private String createTelUrl(String number) {
3506 if (TextUtils.isEmpty(number)) {
3507 return null;
3508 }
3509
Jake Hambye994d462014-02-03 13:10:13 -08003510 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 }
3512
Ihab Awadf9e92732013-12-05 18:02:52 -08003513 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3515 }
3516
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003517 private static void logv(String msg) {
3518 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3519 }
3520
Ihab Awadf9e92732013-12-05 18:02:52 -08003521 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3523 }
3524
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003527 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003528 }
3529
Sanket Padawe356d7632015-06-22 14:03:32 -07003530 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003531 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 final Phone phone = PhoneFactory.getPhone(slotIndex);
3535 if (phone == null) {
3536 return PhoneConstants.PHONE_TYPE_NONE;
3537 } else {
3538 return phone.getPhoneType();
3539 }
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543 }
3544
3545 /**
3546 * Returns the CDMA ERI icon index to display
3547 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003548 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003549 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3550 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3551 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003552 }
3553
Sanket Padawe356d7632015-06-22 14:03:32 -07003554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003555 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3556 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 mApp, subId, callingPackage, callingFeatureId,
3559 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003560 return -1;
3561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 final Phone phone = getPhone(subId);
3566 if (phone != null) {
3567 return phone.getCdmaEriIconIndex();
3568 } else {
3569 return -1;
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 }
3575
3576 /**
3577 * Returns the CDMA ERI icon mode,
3578 * 0 - ON
3579 * 1 - FLASHING
3580 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003582 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3583 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3584 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003585 }
3586
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003588 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3589 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 mApp, subId, callingPackage, callingFeatureId,
3592 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003593 return -1;
3594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 final Phone phone = getPhone(subId);
3599 if (phone != null) {
3600 return phone.getCdmaEriIconMode();
3601 } else {
3602 return -1;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003607 }
3608
3609 /**
3610 * Returns the CDMA ERI text,
3611 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003612 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003613 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3614 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3615 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003616 }
3617
Sanket Padawe356d7632015-06-22 14:03:32 -07003618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003619 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3620 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003622 mApp, subId, callingPackage, callingFeatureId,
3623 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003624 return null;
3625 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626
3627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 final Phone phone = getPhone(subId);
3630 if (phone != null) {
3631 return phone.getCdmaEriText();
3632 } else {
3633 return null;
3634 }
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003638 }
3639
3640 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003641 * Returns the CDMA MDN.
3642 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003643 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003644 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3646 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 return phone.getLine1Number();
3653 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 return null;
3656 }
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003659 }
3660 }
3661
3662 /**
3663 * Returns the CDMA MIN.
3664 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003665 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003666 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3668 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 final Phone phone = getPhone(subId);
3673 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3674 return phone.getCdmaMin();
3675 } else {
3676 return null;
3677 }
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003680 }
3681 }
3682
Hall Liud892bec2018-11-30 14:51:45 -08003683 @Override
3684 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3685 INumberVerificationCallback callback, String callingPackage) {
3686 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3687 != PERMISSION_GRANTED) {
3688 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3689 }
3690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3691
3692 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3693 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003694 throw new SecurityException("Calling package must be configured in the device config: "
3695 + "calling package: " + callingPackage
3696 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003697 }
3698
3699 if (range == null) {
3700 throw new NullPointerException("Range must be non-null");
3701 }
3702
3703 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003704 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003705
3706 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3707 }
3708
Junda Liuca05d5d2014-08-14 22:36:34 -07003709 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003710 * Returns true if CDMA provisioning needs to run.
3711 */
3712 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 final long identity = Binder.clearCallingIdentity();
3714 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003715 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003719 }
3720
3721 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003722 * Sets the voice mail number of a given subId.
3723 */
3724 @Override
3725 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003726 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3727 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728
3729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3732 new Pair<String, String>(alphaTag, number), new Integer(subId));
3733 return success;
3734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003737 }
3738
Ta-wei Yen87c49842016-05-13 21:19:52 -07003739 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003740 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003742 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3743 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003744 if (!TextUtils.equals(callingPackage, systemDialer)) {
3745 throw new SecurityException("caller must be system dialer");
3746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
3748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3751 if (phoneAccountHandle == null) {
3752 return null;
3753 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 } finally {
3756 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003757 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003758 }
3759
3760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3762 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003765 mApp, subId, callingPackage, callingFeatureId,
3766 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003767 return null;
3768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003770 final long identity = Binder.clearCallingIdentity();
3771 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003772 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003776 }
3777
3778 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003779 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3780 VisualVoicemailSmsFilterSettings settings) {
3781 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782
3783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003786 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003790 }
3791
3792 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003793 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003803 }
3804
3805 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003806 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3807 String callingPackage, int subId) {
3808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
3810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003813 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003817 }
3818
3819 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003820 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822
3823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003826 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003830 }
3831
3832 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003833 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3834 String callingAttributionTag, int subId, String number, int port, String text,
3835 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003836 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003837 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003838 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003839 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003840 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3841 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003842 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003843
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003844 /**
fionaxu0152e512016-11-14 13:36:14 -08003845 * Sets the voice activation state of a given subId.
3846 */
3847 @Override
3848 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3850 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851
3852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 final Phone phone = getPhone(subId);
3855 if (phone != null) {
3856 phone.setVoiceActivationState(activationState);
3857 } else {
3858 loge("setVoiceActivationState fails with invalid subId: " + subId);
3859 }
3860 } finally {
3861 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003862 }
3863 }
3864
3865 /**
3866 * Sets the data activation state of a given subId.
3867 */
3868 @Override
3869 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3871 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872
3873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 final Phone phone = getPhone(subId);
3876 if (phone != null) {
3877 phone.setDataActivationState(activationState);
3878 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003879 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880 }
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003883 }
3884 }
3885
3886 /**
3887 * Returns the voice activation state of a given subId.
3888 */
3889 @Override
3890 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892
fionaxu0152e512016-11-14 13:36:14 -08003893 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894 final long identity = Binder.clearCallingIdentity();
3895 try {
3896 if (phone != null) {
3897 return phone.getVoiceActivationState();
3898 } else {
3899 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3900 }
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003903 }
3904 }
3905
3906 /**
3907 * Returns the data activation state of a given subId.
3908 */
3909 @Override
3910 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912
fionaxu0152e512016-11-14 13:36:14 -08003913 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 if (phone != null) {
3917 return phone.getDataActivationState();
3918 } else {
3919 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3920 }
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003923 }
3924 }
3925
3926 /**
Wink Saville36469e72014-06-11 15:17:00 -07003927 * Returns the unread count of voicemails for a subId
3928 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003929 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003930 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3931 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003933 mApp, subId, callingPackage, callingFeatureId,
3934 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003935 return 0;
3936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 final Phone phone = getPhone(subId);
3940 if (phone != null) {
3941 return phone.getVoiceMessageCount();
3942 } else {
3943 return 0;
3944 }
3945 } finally {
3946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003948 }
3949
3950 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003951 * returns true, if the device is in a state where both voice and data
3952 * are supported simultaneously. This can change based on location or network condition.
3953 */
3954 @Override
3955 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 final Phone phone = getPhone(subId);
3959 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003963 }
3964
3965 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003966 * Send the dialer code if called from the current default dialer or the caller has
3967 * carrier privilege.
3968 * @param inputCode The dialer code to send
3969 */
3970 @Override
3971 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003974 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3975 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003976 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003977 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003978 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003983 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 } finally {
3985 Binder.restoreCallingIdentity(identity);
3986 }
fionaxu235cc5e2017-03-06 22:25:57 -08003987 }
3988
Pengquan Menga1bb6272018-09-06 09:59:22 -07003989 @Override
3990 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003991 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003992 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003993 mApp, subId, "getNetworkSelectionMode");
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 if (!isActiveSubscription(subId)) {
3997 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3998 }
3999 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4000 } finally {
4001 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004002 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004003 }
4004
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004006 public boolean isInEmergencySmsMode() {
4007 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 for (Phone phone : PhoneFactory.getPhones()) {
4011 if (phone.isInEmergencySmsMode()) {
4012 return true;
4013 }
4014 }
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
4017 }
4018 return false;
4019 }
4020
shilu366312e2019-12-17 09:28:10 -08004021 /**
4022 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4023 * @param subId The subscription to use to check the configuration.
4024 * @param c The callback that will be used to send the result.
4025 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004026 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004027 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4028 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004029 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004030 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004031
4032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4034 "IMS not available on device.");
4035 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 final long token = Binder.clearCallingIdentity();
4037 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004038 int slotId = getSlotIndexOrException(subId);
4039 verifyImsMmTelConfiguredOrThrow(slotId);
4040 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004041 } catch (ImsException e) {
4042 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 } finally {
4044 Binder.restoreCallingIdentity(token);
4045 }
4046 }
4047
shilu366312e2019-12-17 09:28:10 -08004048 /**
4049 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4050 * @param subId The subscription to use to check the configuration.
4051 * @param c The callback that will be used to send the result.
4052 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004054 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004055 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004056 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004057 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4058 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4059 }
Meng Wangafbc5852019-09-19 17:37:13 -07004060 final long token = Binder.clearCallingIdentity();
4061 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004062 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4063 .removeRegistrationCallbackForSubscription(c, subId);
4064 } catch (ImsException e) {
4065 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4066 + "is inactive, ignoring unregister.");
4067 // If the subscription is no longer active, just return, since the callback
4068 // will already have been removed internally.
4069 } finally {
4070 Binder.restoreCallingIdentity(token);
4071 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 }
4073
Brad Ebingera34a6c22019-10-22 17:36:18 -07004074 /**
4075 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4076 */
4077 @Override
4078 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4079 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4080 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4081 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4082 "IMS not available on device.");
4083 }
4084 final long token = Binder.clearCallingIdentity();
4085 try {
4086 Phone phone = getPhone(subId);
4087 if (phone == null) {
4088 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4089 + subId + "'");
4090 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4091 }
4092 phone.getImsRegistrationState(regState -> {
4093 try {
4094 consumer.accept((regState == null)
4095 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4096 } catch (RemoteException e) {
4097 // Ignore if the remote process is no longer available to call back.
4098 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4099 }
4100 });
4101 } finally {
4102 Binder.restoreCallingIdentity(token);
4103 }
4104 }
4105
4106 /**
4107 * Get the transport type for the IMS service registration state.
4108 */
4109 @Override
4110 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004111 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004112 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004113 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4114 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4115 "IMS not available on device.");
4116 }
4117 final long token = Binder.clearCallingIdentity();
4118 try {
4119 Phone phone = getPhone(subId);
4120 if (phone == null) {
4121 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4122 + subId + "'");
4123 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4124 }
4125 phone.getImsRegistrationTech(regTech -> {
4126 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4127 int regTechConverted = (regTech == null)
4128 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4129 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4130 regTechConverted);
4131 try {
4132 consumer.accept(regTechConverted);
4133 } catch (RemoteException e) {
4134 // Ignore if the remote process is no longer available to call back.
4135 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4136 }
4137 });
4138 } finally {
4139 Binder.restoreCallingIdentity(token);
4140 }
4141 }
4142
shilu366312e2019-12-17 09:28:10 -08004143 /**
4144 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4145 * @param subId The subscription to use to check the configuration.
4146 * @param c The callback that will be used to send the result.
4147 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004148 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004149 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4150 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004151 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004152 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004153 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4154 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4155 "IMS not available on device.");
4156 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 final long token = Binder.clearCallingIdentity();
4158 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004159 int slotId = getSlotIndexOrException(subId);
4160 verifyImsMmTelConfiguredOrThrow(slotId);
4161 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004162 } catch (ImsException e) {
4163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 } finally {
4165 Binder.restoreCallingIdentity(token);
4166 }
4167 }
4168
shilu366312e2019-12-17 09:28:10 -08004169 /**
4170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4171 * @param subId The subscription to use to check the configuration.
4172 * @param c The callback that will be used to send the result.
4173 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004175 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004176 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004177 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4179 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4180 }
Meng Wangafbc5852019-09-19 17:37:13 -07004181
4182 final long token = Binder.clearCallingIdentity();
4183 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004184 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004185 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004186 } catch (ImsException e) {
4187 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4188 + "is inactive, ignoring unregister.");
4189 // If the subscription is no longer active, just return, since the callback
4190 // will already have been removed internally.
4191 } finally {
4192 Binder.restoreCallingIdentity(token);
4193 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 }
4195
4196 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004197 public boolean isCapable(int subId, int capability, int regTech) {
4198 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 final long token = Binder.clearCallingIdentity();
4200 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004201 int slotId = getSlotIndexOrException(subId);
4202 verifyImsMmTelConfiguredOrThrow(slotId);
4203 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4204 } catch (com.android.ims.ImsException e) {
4205 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4206 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004207 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004208 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4209 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 } finally {
4211 Binder.restoreCallingIdentity(token);
4212 }
4213 }
4214
4215 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004216 public boolean isAvailable(int subId, int capability, int regTech) {
4217 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 final long token = Binder.clearCallingIdentity();
4219 try {
4220 Phone phone = getPhone(subId);
4221 if (phone == null) return false;
4222 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004223 } catch (com.android.ims.ImsException e) {
4224 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4225 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004226 } finally {
4227 Binder.restoreCallingIdentity(token);
4228 }
4229 }
4230
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004231 /**
4232 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4233 * subscription.
4234 * @param subId The subscription to use to check the configuration.
4235 * @param callback The callback that will be used to send the result.
4236 * @param capability The MmTelFeature capability that will be used to send the result.
4237 * @param transportType The transport type of the MmTelFeature capability.
4238 */
4239 @Override
4240 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4241 int transportType) {
4242 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004243 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4244 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4245 "IMS not available on device.");
4246 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004247 final long token = Binder.clearCallingIdentity();
4248 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004249 int slotId = getSlotIndex(subId);
4250 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4251 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4252 + subId + "'");
4253 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4254 }
4255 verifyImsMmTelConfiguredOrThrow(slotId);
4256 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4257 transportType, aBoolean -> {
4258 try {
4259 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4260 } catch (RemoteException e) {
4261 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4262 + "running. Ignore");
4263 }
4264 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004265 } catch (ImsException e) {
4266 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004267 } finally {
4268 Binder.restoreCallingIdentity(token);
4269 }
4270 }
4271
shilu366312e2019-12-17 09:28:10 -08004272 /**
4273 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4274 * @param subId The subscription to use to check the configuration.
4275 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 @Override
4277 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004278 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004279 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004280
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 final long token = Binder.clearCallingIdentity();
4282 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004284 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004286 } catch (ImsException e) {
4287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 } finally {
4289 Binder.restoreCallingIdentity(token);
4290 }
4291 }
4292
4293 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004294 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004296 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004300 // This setting doesn't require an active ImsService connection, so do not verify. The
4301 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004303 } catch (ImsException e) {
4304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308 }
4309
shilu366312e2019-12-17 09:28:10 -08004310 /**
4311 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4312 * @param subId The subscription to use to check the configuration.
4313 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004315 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004316 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004317 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 final long identity = Binder.clearCallingIdentity();
4319 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004320 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004321 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004323 } catch (ImsException e) {
4324 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
4328 }
4329
4330 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004331 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004333 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 final long identity = Binder.clearCallingIdentity();
4335 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004337 // This setting doesn't require an active ImsService connection, so do not verify. The
4338 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004339 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004340 } catch (ImsException e) {
4341 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
4345 }
4346
shilu366312e2019-12-17 09:28:10 -08004347 /**
4348 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4349 * @param subId The subscription to use to check the configuration.
4350 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 @Override
4352 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004353 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004354 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 final long identity = Binder.clearCallingIdentity();
4356 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004358 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004360 } catch (ImsException e) {
4361 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 } finally {
4363 Binder.restoreCallingIdentity(identity);
4364 }
4365 }
4366
4367 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004368 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004370 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 final long identity = Binder.clearCallingIdentity();
4372 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004374 // This setting doesn't require an active ImsService connection, so do not verify. The
4375 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 } catch (ImsException e) {
4378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
4382 }
4383
shilu366312e2019-12-17 09:28:10 -08004384 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004385 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4386 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4387 * @param subId The subscription to use to check the configuration.
4388 */
4389 @Override
4390 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004391 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004392 mApp, subId, "isCrossSimCallingEnabledByUser");
4393 final long identity = Binder.clearCallingIdentity();
4394 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004396 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004398 } catch (ImsException e) {
4399 throw new ServiceSpecificException(e.getCode());
4400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
4403 }
4404
4405 /**
4406 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4407 * Requires MODIFY_PHONE_STATE permission.
4408 * @param subId The subscription to use to check the configuration.
4409 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4410 * false otherwise
4411 */
4412 @Override
4413 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4415 "setCrossSimCallingEnabled");
4416 final long identity = Binder.clearCallingIdentity();
4417 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004418 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004419 // This setting doesn't require an active ImsService connection, so do not verify. The
4420 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004421 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004422 } catch (ImsException e) {
4423 throw new ServiceSpecificException(e.getCode());
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
4427 }
4428
4429 /**
shilu366312e2019-12-17 09:28:10 -08004430 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4431 * @param subId The subscription to use to check the configuration.
4432 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004434
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004436 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004437 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 final long identity = Binder.clearCallingIdentity();
4439 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004440 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004441 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004443 } catch (ImsException e) {
4444 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004445 } finally {
4446 Binder.restoreCallingIdentity(identity);
4447 }
4448 }
4449
4450 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004451 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004453 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 final long identity = Binder.clearCallingIdentity();
4455 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004457 // This setting doesn't require an active ImsService connection, so do not verify. The
4458 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004460 } catch (ImsException e) {
4461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
4465 }
4466
4467 @Override
4468 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4470 "setVoWiFiNonPersistent");
4471 final long identity = Binder.clearCallingIdentity();
4472 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004474 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004476 } catch (ImsException e) {
4477 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
4481 }
4482
shilu366312e2019-12-17 09:28:10 -08004483 /**
4484 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4485 * @param subId The subscription to use to check the configuration.
4486 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 @Override
4488 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004489 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004490 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 final long identity = Binder.clearCallingIdentity();
4492 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004494 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004496 } catch (ImsException e) {
4497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
4501 }
4502
4503 @Override
4504 public void setVoWiFiModeSetting(int subId, int mode) {
4505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4506 "setVoWiFiModeSetting");
4507 final long identity = Binder.clearCallingIdentity();
4508 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004509 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004510 // This setting doesn't require an active ImsService connection, so do not verify. The
4511 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004513 } catch (ImsException e) {
4514 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004515 } finally {
4516 Binder.restoreCallingIdentity(identity);
4517 }
4518 }
4519
4520 @Override
4521 public int getVoWiFiRoamingModeSetting(int subId) {
4522 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4523 final long identity = Binder.clearCallingIdentity();
4524 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004525 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004526 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004528 } catch (ImsException e) {
4529 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
4533 }
4534
4535 @Override
4536 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4538 "setVoWiFiRoamingModeSetting");
4539 final long identity = Binder.clearCallingIdentity();
4540 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004542 // This setting doesn't require an active ImsService connection, so do not verify. The
4543 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
4546 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
4550 }
4551
4552 @Override
4553 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4555 "setRttCapabilityEnabled");
4556 final long identity = Binder.clearCallingIdentity();
4557 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004559 // This setting doesn't require an active ImsService connection, so do not verify. The
4560 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004561 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004562 } catch (ImsException e) {
4563 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
4567 }
4568
shilu366312e2019-12-17 09:28:10 -08004569 /**
4570 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4571 * @param subId The subscription to use to check the configuration.
4572 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004573 @Override
4574 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004575 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004576 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 final long identity = Binder.clearCallingIdentity();
4578 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004580 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004581 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004582 } catch (ImsException e) {
4583 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
4587 }
4588
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004589 @Override
4590 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4591 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004592
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 final long identity = Binder.clearCallingIdentity();
4594 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004595 if (!isImsAvailableOnDevice()) {
4596 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4597 "IMS not available on device.");
4598 }
4599 int slotId = getSlotIndexOrException(subId);
4600 verifyImsMmTelConfiguredOrThrow(slotId);
4601 ImsManager.getInstance(mApp, slotId)
4602 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004603 } catch (ImsException e) {
4604 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
4608 }
4609
4610 @Override
4611 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4612 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004613
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004614 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4616 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4617 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004618 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004619 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004620 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004622 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4623 + "is inactive, ignoring unregister.");
4624 // If the subscription is no longer active, just return, since the callback will already
4625 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
4629 }
4630
joonhunshincffb7fc2021-11-28 07:32:01 +00004631 @Override
4632 public void registerFeatureProvisioningChangedCallback(int subId,
4633 IFeatureProvisioningCallback callback) {
4634 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4635 mApp, subId, "registerFeatureProvisioningChangedCallback");
4636
4637 final long identity = Binder.clearCallingIdentity();
4638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4639 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4640 }
4641
4642 ImsProvisioningController.getInstance()
4643 .addFeatureProvisioningChangedCallback(subId, callback);
4644
4645 Binder.restoreCallingIdentity(identity);
4646 }
4647
4648 @Override
4649 public void unregisterFeatureProvisioningChangedCallback(int subId,
4650 IFeatureProvisioningCallback callback) {
4651 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4652 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4653
4654 final long identity = Binder.clearCallingIdentity();
4655 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4656 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4657 }
4658
4659 ImsProvisioningController.getInstance()
4660 .removeFeatureProvisioningChangedCallback(subId, callback);
4661
4662 Binder.restoreCallingIdentity(identity);
4663 }
allenwtsu99c623b2020-01-03 18:24:23 +08004664
4665 private void checkModifyPhoneStatePermission(int subId, String message) {
4666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4667 message);
4668 }
4669
allenwtsu99c623b2020-01-03 18:24:23 +08004670 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004671 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004672 boolean isProvisioned) {
4673 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4674
4675 final long identity = Binder.clearCallingIdentity();
4676 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004677 ImsProvisioningController.getInstance()
4678 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4679 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
allenwtsu99c623b2020-01-03 18:24:23 +08004683 }
4684
4685
4686 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004687 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4688 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4689 mApp, subId, "getRcsProvisioningStatusForCapability");
4690
allenwtsu99c623b2020-01-03 18:24:23 +08004691 final long identity = Binder.clearCallingIdentity();
4692 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004693 return ImsProvisioningController.getInstance()
4694 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004700 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4702 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004703 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004704
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004707 ImsProvisioningController.getInstance()
4708 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004709 } finally {
4710 Binder.restoreCallingIdentity(identity);
4711 }
4712 }
4713
4714 @Override
4715 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004716 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4717 mApp, subId, "getProvisioningStatusForCapability");
4718
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004721 return ImsProvisioningController.getInstance()
4722 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004723
4724 } finally {
4725 Binder.restoreCallingIdentity(identity);
4726 }
4727 }
4728
4729 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004730 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4731 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4732 mApp, subId, "isProvisioningRequiredForCapability");
4733
4734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 return ImsProvisioningController.getInstance()
4737 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004740 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004741 }
4742
4743 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004744 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4745 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4746 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004747
joonhunshincffb7fc2021-11-28 07:32:01 +00004748 final long identity = Binder.clearCallingIdentity();
4749 try {
4750 return ImsProvisioningController.getInstance()
4751 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004755 }
4756
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004757 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004758 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4760 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4761 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004762 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4763 mApp, subId, "getImsProvisioningInt");
4764
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004768 int slotId = getSlotIndex(subId);
4769 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4770 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4771 + subId + "' for key:" + key);
4772 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4773 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004774
4775 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4776 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4777 return retVal;
4778 }
4779
calvinpanb5a34062021-02-08 19:59:36 +08004780 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004781 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004782 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4783 + subId + "' for key:" + key);
4784 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
4788 }
4789
4790 @Override
4791 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4793 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4794 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004795 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4796 mApp, subId, "getImsProvisioningString");
4797
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004798 final long identity = Binder.clearCallingIdentity();
4799 try {
4800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004801 int slotId = getSlotIndex(subId);
4802 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4803 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4804 + subId + "' for key:" + key);
4805 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4806 }
calvinpanb5a34062021-02-08 19:59:36 +08004807 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004808 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004809 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4810 + subId + "' for key:" + key);
4811 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004812 } finally {
4813 Binder.restoreCallingIdentity(identity);
4814 }
4815 }
4816
4817 @Override
4818 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004819 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4820 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4821 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4823 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004824
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004825 final long identity = Binder.clearCallingIdentity();
4826 try {
4827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004828 int slotId = getSlotIndex(subId);
4829 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4830 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4831 + subId + "' for key:" + key);
4832 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4833 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004834
4835 int retVal = ImsProvisioningController.getInstance()
4836 .setProvisioningValue(subId, key, value);
4837 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4838 return retVal;
4839 }
4840
calvinpanb5a34062021-02-08 19:59:36 +08004841 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4842 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004843 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004844 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004845 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004846 } finally {
4847 Binder.restoreCallingIdentity(identity);
4848 }
4849 }
4850
4851 @Override
4852 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4854 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4855 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4857 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004858 final long identity = Binder.clearCallingIdentity();
4859 try {
4860 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004861 int slotId = getSlotIndex(subId);
4862 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4863 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4864 + subId + "' for key:" + key);
4865 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4866 }
calvinpanb5a34062021-02-08 19:59:36 +08004867 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4868 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004869 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004870 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004871 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
4875 }
4876
Brad Ebinger919631e2021-06-02 17:46:35 -07004877 /**
4878 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4879 * for the given slot ID or no ImsResolver instance has been created.
4880 * @param slotId The slot ID that the IMS service is created for.
4881 * @throws ImsException If there is no ImsService configured for this slot.
4882 */
4883 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4884 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4885 ImsFeature.FEATURE_MMTEL)) {
4886 throw new ImsException("This subscription does not support MMTEL over IMS",
4887 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4888 }
4889 }
4890
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004891 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004892 int slotId = SubscriptionManager.getSlotIndex(subId);
4893 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004894 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4895 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004896 }
4897 return slotId;
4898 }
4899
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 private int getSlotIndex(int subId) {
4901 int slotId = SubscriptionManager.getSlotIndex(subId);
4902 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4903 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4904 }
4905 return slotId;
4906 }
4907
Wink Saville36469e72014-06-11 15:17:00 -07004908 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004909 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004910 */
4911 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004912 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4913 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004914 try {
4915 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4916 } catch (SecurityException se) {
4917 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4918 throw new SecurityException("Package " + callingPackage + " does not belong to "
4919 + Binder.getCallingUid());
4920 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004921 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004922 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004923 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004924 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004925 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004926 mApp, subId, callingPackage, callingFeatureId,
4927 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004928 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4929 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 final Phone phone = getPhone(subId);
4934 if (phone != null) {
4935 return phone.getServiceState().getDataNetworkType();
4936 } else {
4937 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4938 }
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004942 }
4943
4944 /**
4945 * Returns the data network type
4946 */
4947 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004948 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004949 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4950 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004951 }
4952
4953 /**
4954 * Returns the data network type for a subId
4955 */
4956 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004957 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4958 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004959 String functionName = "getDataNetworkTypeForSubscriber";
4960 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4961 mApp, functionName)) {
4962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4963 mApp, subId, callingPackage, callingFeatureId, functionName)) {
4964 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4965 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004966 }
4967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 final long identity = Binder.clearCallingIdentity();
4969 try {
4970 final Phone phone = getPhone(subId);
4971 if (phone != null) {
4972 return phone.getServiceState().getDataNetworkType();
4973 } else {
4974 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4975 }
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004979 }
4980
4981 /**
Wink Saville36469e72014-06-11 15:17:00 -07004982 * Returns the Voice network type for a subId
4983 */
4984 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004985 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4986 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004987 String functionName = "getVoiceNetworkTypeForSubscriber";
4988 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4989 mApp, functionName)) {
4990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4991 mApp, subId, callingPackage, callingFeatureId, functionName)) {
4992 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4993 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004994 }
4995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 final long identity = Binder.clearCallingIdentity();
4997 try {
4998 final Phone phone = getPhone(subId);
4999 if (phone != null) {
5000 return phone.getServiceState().getVoiceNetworkType();
5001 } else {
5002 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5003 }
5004 } finally {
5005 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005007 }
5008
5009 /**
5010 * @return true if a ICC card is present
5011 */
5012 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005013 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005014 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5015 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005016 }
5017
5018 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005019 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005020 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005021 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005022 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 final Phone phone = PhoneFactory.getPhone(slotIndex);
5026 if (phone != null) {
5027 return phone.getIccCard().hasIccCard();
5028 } else {
5029 return false;
5030 }
5031 } finally {
5032 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005034 }
5035
5036 /**
5037 * Return if the current radio is LTE on CDMA. This
5038 * is a tri-state return value as for a period of time
5039 * the mode may be unknown.
5040 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005041 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005042 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005043 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005044 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005046 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5047 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5048 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005049 }
5050
Sanket Padawe356d7632015-06-22 14:03:32 -07005051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005052 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5053 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005054 try {
5055 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5056 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005057 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5058 }
5059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060 final long identity = Binder.clearCallingIdentity();
5061 try {
5062 final Phone phone = getPhone(subId);
5063 if (phone == null) {
5064 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5065 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005066 return TelephonyProperties.lte_on_cdma_device()
5067 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 }
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005071 }
Wink Saville36469e72014-06-11 15:17:00 -07005072 }
5073
Wink Saville36469e72014-06-11 15:17:00 -07005074 /**
5075 * {@hide}
5076 * Returns Default subId, 0 in the case of single standby.
5077 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005078 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005079 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005080 }
5081
Shishir Agrawala9f32182016-04-12 12:00:16 -07005082 private int getSlotForDefaultSubscription() {
5083 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5084 }
5085
Wink Savilleb564aae2014-10-23 10:18:09 -07005086 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005087 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005088 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005089
Pengquan Menge92a50d2018-09-21 15:54:48 -07005090 private boolean isActiveSubscription(int subId) {
5091 return mSubscriptionController.isActiveSubId(subId);
5092 }
5093
Ihab Awadf2177b72013-11-25 13:33:23 -08005094 /**
5095 * @see android.telephony.TelephonyManager.WifiCallingChoices
5096 */
5097 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 final long identity = Binder.clearCallingIdentity();
5099 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005100 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5102 getWhenToMakeWifiCallsDefaultPreference());
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005106 }
5107
5108 /**
5109 * @see android.telephony.TelephonyManager.WifiCallingChoices
5110 */
5111 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 final long identity = Binder.clearCallingIdentity();
5113 try {
5114 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005115 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5117 } finally {
5118 Binder.restoreCallingIdentity(identity);
5119 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005120 }
5121
Sailesh Nepald1e68152013-12-12 19:08:02 -08005122 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005123 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005124 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005125 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005126
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005127 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5128 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5129 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005130 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005131 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5132 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005133 }
5134 return PhoneFactory.getPhone(phoneId);
5135 }
5136
Shishir Agrawal566b7612013-10-28 14:41:00 -07005137 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005138 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005139 @NonNull IccLogicalChannelRequest request) {
5140 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5141 /*message=*/ "iccOpenLogicalChannel");
5142
5143 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5144 // Verify that the callingPackage in the request belongs to the calling UID
5145 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5146
5147 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005148 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005149
Rambo Wanga1782702021-11-10 20:15:19 -08005150 private Phone getPhoneFromValidIccLogicalChannelRequest(
5151 @NonNull IccLogicalChannelRequest request, String message) {
5152 Phone phone;
5153 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5155 mApp, request.subId, message);
5156 phone = getPhoneFromSubId(request.subId);
5157 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5158 enforceModifyPermission();
5159 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5160 } else {
5161 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005162 }
Rambo Wanga1782702021-11-10 20:15:19 -08005163 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005164 }
5165
5166 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005167 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 final long identity = Binder.clearCallingIdentity();
5169 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005170 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5173 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005174 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5175 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 loge("The calling package is not allowed to access ISD-R.");
5177 throw new SecurityException(
5178 "The calling package is not allowed to access ISD-R.");
5179 }
Derek Tan740e1672017-06-27 14:56:27 -07005180 }
Derek Tan740e1672017-06-27 14:56:27 -07005181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005183 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5184 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 return response;
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005189 }
5190
5191 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005192 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5193 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5194 /*message=*/"iccCloseLogicalChannel");
5195
5196 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5197
5198 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005199 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005200
Rambo Wanga1782702021-11-10 20:15:19 -08005201 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5202 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005203 // before this feature is enabled, this API should only return false if
5204 // the operation fails instead of throwing runtime exception for
5205 // backward-compatibility.
5206 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5207 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 final long identity = Binder.clearCallingIdentity();
5209 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005210 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005211 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 }
Chen Xue9d737e2022-01-01 23:41:31 -08005213 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005214 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005215 Boolean success = false;
5216 if (result instanceof RuntimeException) {
5217 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005218 if (shouldThrowExceptionOnFailure) {
5219 throw (RuntimeException) result;
5220 } else {
5221 return false;
5222 }
Chen Xue9d737e2022-01-01 23:41:31 -08005223 } else if (result instanceof Boolean) {
5224 success = (Boolean) result;
5225 } else {
5226 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5227 }
Rambo Wanga1782702021-11-10 20:15:19 -08005228 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 return success;
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005232 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005233 }
5234
5235 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005236 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005237 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5239 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005240 if (DBG) {
5241 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5242 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5243 + p3 + " data=" + data);
5244 }
5245 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5246 command, p1, p2, p3, data);
5247 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005248
Jordan Liu4c733742019-02-28 12:03:40 -08005249 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005250 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5251 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005252 enforceModifyPermission();
5253 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005254 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5255 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5256 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005257 }
5258 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005259 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5260 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005261 }
5262
5263 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5264 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 final long identity = Binder.clearCallingIdentity();
5266 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005267 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 return "";
5269 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005272 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5273 null /* workSource */);
5274 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 // Append the returned status code to the end of the response payload.
5277 String s = Integer.toHexString(
5278 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5279 if (response.payload != null) {
5280 s = IccUtils.bytesToHexString(response.payload) + s;
5281 }
5282 return s;
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005285 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005286 }
Jake Hambye994d462014-02-03 13:10:13 -08005287
Evan Charltonc66da362014-05-16 14:06:40 -07005288 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005289 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5290 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5292 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005294 if (DBG) {
5295 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5296 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5297 }
5298 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5299 cla, command, p1, p2, p3, data);
5300 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005301
Jordan Liu4c733742019-02-28 12:03:40 -08005302 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005303 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5304 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005305 enforceModifyPermission();
5306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5307 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005308 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5309 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5310 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005311 }
5312
5313 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005314 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5315 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005316 }
5317
5318 // open APDU basic channel assuming the caller has sufficient permissions
5319 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5320 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5324 && TextUtils.equals(ISDR_AID, data)) {
5325 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005326 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5327 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 if (bestComponent == null
5329 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5330 loge("The calling package is not allowed to select ISD-R.");
5331 throw new SecurityException(
5332 "The calling package is not allowed to select ISD-R.");
5333 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005334 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005337 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5338 null /* workSource */);
5339 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 // Append the returned status code to the end of the response payload.
5342 String s = Integer.toHexString(
5343 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5344 if (response.payload != null) {
5345 s = IccUtils.bytesToHexString(response.payload) + s;
5346 }
5347 return s;
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005350 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005351 }
5352
5353 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005354 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005355 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5357 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 if (DBG) {
5362 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5363 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5364 }
5365
5366 IccIoResult response =
5367 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5368 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5369 subId);
5370
5371 if (DBG) {
5372 log("Exchange SIM_IO [R]" + response);
5373 }
5374
5375 byte[] result = null;
5376 int length = 2;
5377 if (response.payload != null) {
5378 length = 2 + response.payload.length;
5379 result = new byte[length];
5380 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5381 } else {
5382 result = new byte[length];
5383 }
5384
5385 result[length - 1] = (byte) response.sw2;
5386 result[length - 2] = (byte) response.sw1;
5387 return result;
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005390 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005391 }
5392
Nathan Haroldb3014052017-01-25 15:57:32 -08005393 /**
5394 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5395 * on a particular subscription
5396 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005397 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5398 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005400 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005401 return null;
5402 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403
5404 final long identity = Binder.clearCallingIdentity();
5405 try {
5406 if (appType != TelephonyManager.APPTYPE_USIM
5407 && appType != TelephonyManager.APPTYPE_SIM) {
5408 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5409 return null;
5410 }
5411 Object response = sendRequest(
5412 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5413 if (response instanceof String[]) {
5414 return (String[]) response;
5415 }
yincheng zhao2737e882019-09-06 17:06:54 -07005416 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005418 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 } finally {
5420 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005421 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005422 }
5423
yincheng zhao2737e882019-09-06 17:06:54 -07005424 /**
5425 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5426 * subscription.
5427 *
5428 * @param subId the id of the subscription.
5429 * @param appType the uicc app type, must be USIM or SIM.
5430 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5431 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005432 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005433 * @return number of fplmns that is successfully written to the SIM.
5434 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005435 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5436 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5438 mApp, subId, "setForbiddenPlmns");
5439
yincheng zhao2737e882019-09-06 17:06:54 -07005440 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5441 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5442 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5443 }
5444 if (fplmns == null) {
5445 throw new IllegalArgumentException("Fplmn List provided is null");
5446 }
5447 for (String fplmn : fplmns) {
5448 if (!CellIdentity.isValidPlmn(fplmn)) {
5449 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5450 }
5451 }
5452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 Object response = sendRequest(
5455 CMD_SET_FORBIDDEN_PLMNS,
5456 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5457 subId);
5458 return (int) response;
5459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
5462 }
5463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005465 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5467 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 final long identity = Binder.clearCallingIdentity();
5470 try {
5471 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5472 if (response.payload == null) {
5473 return "";
5474 }
Evan Charltonc66da362014-05-16 14:06:40 -07005475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 // Append the returned status code to the end of the response payload.
5477 String s = Integer.toHexString(
5478 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5479 s = IccUtils.bytesToHexString(response.payload) + s;
5480 return s;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
Evan Charltonc66da362014-05-16 14:06:40 -07005484 }
5485
Jake Hambye994d462014-02-03 13:10:13 -08005486 /**
5487 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5488 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5489 *
5490 * @param itemID the ID of the item to read
5491 * @return the NV item as a String, or null on error.
5492 */
5493 @Override
5494 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005495 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5497 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498
5499 final long identity = Binder.clearCallingIdentity();
5500 try {
5501 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005502 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5504 return value;
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Jake Hambye994d462014-02-03 13:10:13 -08005508 }
5509
5510 /**
5511 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5512 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5513 *
5514 * @param itemID the ID of the item to read
5515 * @param itemValue the value to write, as a String
5516 * @return true on success; false on any failure
5517 */
5518 @Override
5519 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5522 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5527 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005528 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5530 return success;
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Jake Hambye994d462014-02-03 13:10:13 -08005534 }
5535
5536 /**
5537 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5538 * Used for device configuration by some CDMA operators.
5539 *
5540 * @param preferredRoamingList byte array containing the new PRL
5541 * @return true on success; false on any failure
5542 */
5543 @Override
5544 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5546 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547
5548 final long identity = Binder.clearCallingIdentity();
5549 try {
5550 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5551 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5552 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5553 return success;
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
Jake Hambye994d462014-02-03 13:10:13 -08005557 }
5558
5559 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005560 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005561 * Used for device configuration by some CDMA operators.
5562 *
chen xu6dac5ab2018-10-26 17:39:23 -07005563 * @param slotIndex - device slot.
5564 *
Jake Hambye994d462014-02-03 13:10:13 -08005565 * @return true on success; false on any failure
5566 */
5567 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005568 public boolean resetModemConfig(int slotIndex) {
5569 Phone phone = PhoneFactory.getPhone(slotIndex);
5570 if (phone != null) {
5571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5572 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573
chen xu6dac5ab2018-10-26 17:39:23 -07005574 final long identity = Binder.clearCallingIdentity();
5575 try {
5576 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5577 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5578 return success;
5579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 }
chen xu6dac5ab2018-10-26 17:39:23 -07005583 return false;
5584 }
5585
5586 /**
5587 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5588 *
5589 * @param slotIndex - device slot.
5590 *
5591 * @return true on success; false on any failure
5592 */
5593 @Override
5594 public boolean rebootModem(int slotIndex) {
5595 Phone phone = PhoneFactory.getPhone(slotIndex);
5596 if (phone != null) {
5597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5598 mApp, phone.getSubId(), "rebootModem");
5599
5600 final long identity = Binder.clearCallingIdentity();
5601 try {
5602 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5603 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5604 return success;
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
5608 }
5609 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005610 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005611
Brad Ebinger51f743a2017-01-23 13:50:20 -08005612 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005613 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5614 * {@link #disableIms(int)}.
5615 * @param slotIndex device slot.
5616 */
5617 public void resetIms(int slotIndex) {
5618 enforceModifyPermission();
5619
5620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 if (mImsResolver == null) {
5623 // may happen if the does not support IMS.
5624 return;
5625 }
5626 mImsResolver.disableIms(slotIndex);
5627 mImsResolver.enableIms(slotIndex);
5628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
5631 }
5632
5633 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005634 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5635 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005636 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005637 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005638 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005642 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005643 // may happen if the device does not support IMS.
5644 return;
5645 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005646 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005650 }
5651
5652 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005653 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5654 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005655 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005656 public void disableIms(int slotId) {
5657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005661 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005662 // may happen if the device does not support IMS.
5663 return;
5664 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005665 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005669 }
5670
5671 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005672 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5673 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005674 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005675 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005676 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005677 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005681 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005682 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5683 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005684 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005685 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005689 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005690 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005691 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5692 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005693 @Override
5694 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005695 enforceModifyPermission();
5696
5697 final long identity = Binder.clearCallingIdentity();
5698 try {
5699 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005700 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
5704 }
5705
5706 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005707 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005708 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005709 */
5710 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005715 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005716 // may happen if the device does not support IMS.
5717 return null;
5718 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005719 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 } finally {
5721 Binder.restoreCallingIdentity(identity);
5722 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005723 }
5724
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005725 /**
5726 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005727 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005728 */
5729 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731
5732 final long identity = Binder.clearCallingIdentity();
5733 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005734 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005735 // may happen if the device does not support IMS.
5736 return null;
5737 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005742 }
5743
Brad Ebinger884c07b2018-02-15 16:17:40 -08005744 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005745 * Sets the ImsService Package Name that Telephony will bind to.
5746 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005747 * @param slotIndex the slot ID that the ImsService should bind for.
5748 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005749 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005750 * @param featureTypes An integer array of feature types associated with a packageName.
5751 * @param packageName The name of the package that the current configuration will be replaced
5752 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005753 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005754 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005755 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5756 int[] featureTypes, String packageName) {
5757 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5760 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005761 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 final long identity = Binder.clearCallingIdentity();
5764 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005765 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005766 // may happen if the device does not support IMS.
5767 return false;
5768 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005769 Map<Integer, String> featureConfig = new HashMap<>();
5770 for (int featureType : featureTypes) {
5771 featureConfig.put(featureType, packageName);
5772 }
5773 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5774 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005778 }
5779
5780 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005781 * Clears any carrier ImsService overrides for the slot index specified that were previously
5782 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5783 *
5784 * This should only be used for testing.
5785 *
5786 * @param slotIndex the slot ID that the ImsService should bind for.
5787 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5788 */
5789 @Override
5790 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5791 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5793 "clearCarrierImsServiceOverride");
5794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5795 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5796 "clearCarrierImsServiceOverride");
5797
5798 final long identity = Binder.clearCallingIdentity();
5799 try {
5800 if (mImsResolver == null) {
5801 // may happen if the device does not support IMS.
5802 return false;
5803 }
5804 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
5808 }
5809
5810 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005812 *
5813 * @param slotId The slot that the ImsService is associated with.
5814 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5815 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005816 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005817 * @return the package name of the ImsService configuration.
5818 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5820 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005821 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005823 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5825 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 final long identity = Binder.clearCallingIdentity();
5828 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005829 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005830 // may happen if the device does not support IMS.
5831 return "";
5832 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005833 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5835 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005839 }
5840
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005841 /**
5842 * Get the MmTelFeature state associated with the requested subscription id.
5843 * @param subId The subscription that the MmTelFeature is associated with.
5844 * @param callback A callback with an integer containing the
5845 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5846 */
5847 @Override
5848 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5849 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005850 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5851 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5852 "IMS not available on device.");
5853 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005854 final long token = Binder.clearCallingIdentity();
5855 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005856 int slotId = getSlotIndex(subId);
5857 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5858 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5859 + subId + "'");
5860 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5861 }
5862 verifyImsMmTelConfiguredOrThrow(slotId);
5863 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5864 try {
5865 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5866 } catch (RemoteException e) {
5867 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5868 + "Ignore");
5869 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005870 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005871 } catch (ImsException e) {
5872 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005873 } finally {
5874 Binder.restoreCallingIdentity(token);
5875 }
5876 }
5877
Daniel Brightbb5840b2021-01-12 15:48:18 -08005878 /**
5879 * Sets the ims registration state on all valid {@link Phone}s.
5880 */
5881 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005882 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883
5884 final long identity = Binder.clearCallingIdentity();
5885 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005886 // NOTE: Before S, this method only set the default phone.
5887 for (final Phone phone : PhoneFactory.getPhones()) {
5888 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5889 phone.setImsRegistrationState(registered);
5890 }
5891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
Wink Saville36469e72014-06-11 15:17:00 -07005895 }
5896
5897 /**
Stuart Scott54788802015-03-30 13:18:01 -07005898 * Set the network selection mode to automatic.
5899 *
5900 */
5901 @Override
5902 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5904 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905
5906 final long identity = Binder.clearCallingIdentity();
5907 try {
shilufc958392020-01-20 11:36:01 -08005908 if (!isActiveSubscription(subId)) {
5909 return;
5910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005912 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5913 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 } finally {
5915 Binder.restoreCallingIdentity(identity);
5916 }
Stuart Scott54788802015-03-30 13:18:01 -07005917 }
5918
Jack Yud10cdd42020-09-28 20:28:01 -07005919 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005920 * Ask the radio to connect to the input network and change selection mode to manual.
5921 *
5922 * @param subId the id of the subscription.
5923 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5924 * the operator to attach to.
5925 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5926 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5927 * normal network selection next time.
5928 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005929 */
5930 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005931 public boolean setNetworkSelectionModeManual(
5932 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5934 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005935
5936 if (!isActiveSubscription(subId)) {
5937 return false;
5938 }
5939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 final long identity = Binder.clearCallingIdentity();
5941 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005942 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005944 if (DBG) {
5945 log("setNetworkSelectionModeManual: subId: " + subId
5946 + " operator: " + operatorInfo);
5947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5949 } finally {
5950 Binder.restoreCallingIdentity(identity);
5951 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005952 }
shilu84f6e8b2019-12-19 13:58:01 -08005953 /**
5954 * Get the manual network selection
5955 *
5956 * @param subId the id of the subscription.
5957 *
5958 * @return the previously saved user selected PLMN
5959 */
5960 @Override
5961 public String getManualNetworkSelectionPlmn(int subId) {
5962 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005963 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005964 mApp, subId, "getManualNetworkSelectionPlmn");
5965
5966 final long identity = Binder.clearCallingIdentity();
5967 try {
5968 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005969 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005970 }
5971
5972 final Phone phone = getPhone(subId);
5973 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005974 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005975 }
5976 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5977 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5978 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
5982 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005983
5984 /**
5985 * Scans for available networks.
5986 */
5987 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005988 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5989 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5991 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005992 LocationAccessPolicy.LocationPermissionResult locationResult =
5993 LocationAccessPolicy.checkLocationPermission(mApp,
5994 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5995 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005996 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005997 .setCallingPid(Binder.getCallingPid())
5998 .setCallingUid(Binder.getCallingUid())
5999 .setMethod("getCellNetworkScanResults")
6000 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006001 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6002 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006003 .build());
6004 switch (locationResult) {
6005 case DENIED_HARD:
6006 throw new SecurityException("Not allowed to access scan results -- location");
6007 case DENIED_SOFT:
6008 return null;
6009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
Pengquan Menga1bb6272018-09-06 09:59:22 -07006011 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 try {
6013 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006014 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006019 }
6020
6021 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006022 * Get the call forwarding info, given the call forwarding reason.
6023 */
6024 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006025 public void getCallForwarding(int subId, int callForwardingReason,
6026 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006027 enforceReadPrivilegedPermission("getCallForwarding");
6028 long identity = Binder.clearCallingIdentity();
6029 try {
6030 if (DBG) {
6031 log("getCallForwarding: subId " + subId
6032 + " callForwardingReason" + callForwardingReason);
6033 }
Hall Liu27d24262020-09-18 19:04:59 -07006034
6035 Phone phone = getPhone(subId);
6036 if (phone == null) {
6037 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006038 callback.onError(
6039 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006040 } catch (RemoteException e) {
6041 // ignore
6042 }
6043 return;
6044 }
6045
6046 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6047 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6048 @Override
6049 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6050 try {
6051 callback.onCallForwardingInfoAvailable(info);
6052 } catch (RemoteException e) {
6053 // ignore
6054 }
6055 }
6056
6057 @Override
6058 public void onError(int error) {
6059 try {
6060 callback.onError(error);
6061 } catch (RemoteException e) {
6062 // ignore
6063 }
6064 }
6065 });
6066 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006067 } finally {
6068 Binder.restoreCallingIdentity(identity);
6069 }
6070 }
6071
6072 /**
6073 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6074 * reason, the number to forward, and the timeout before the forwarding is attempted.
6075 */
6076 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006077 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6078 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006079 enforceModifyPermission();
6080 long identity = Binder.clearCallingIdentity();
6081 try {
6082 if (DBG) {
6083 log("setCallForwarding: subId " + subId
6084 + " callForwardingInfo" + callForwardingInfo);
6085 }
Hall Liu27d24262020-09-18 19:04:59 -07006086
6087 Phone phone = getPhone(subId);
6088 if (phone == null) {
6089 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006090 callback.accept(
6091 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006092 } catch (RemoteException e) {
6093 // ignore
6094 }
6095 return;
6096 }
6097
6098 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6099 FunctionalUtils.ignoreRemoteException(callback::accept));
6100
6101 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006102 } finally {
6103 Binder.restoreCallingIdentity(identity);
6104 }
6105 }
6106
6107 /**
Hall Liu27d24262020-09-18 19:04:59 -07006108 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006109 */
6110 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006111 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006112 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006113 long identity = Binder.clearCallingIdentity();
6114 try {
Hall Liu27d24262020-09-18 19:04:59 -07006115 Phone phone = getPhone(subId);
6116 if (phone == null) {
6117 try {
6118 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6119 } catch (RemoteException e) {
6120 // ignore
6121 }
6122 return;
6123 }
SongFerngWang0e767992021-03-31 22:08:45 +08006124 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6125 PersistableBundle c = configManager.getConfigForSubId(subId);
6126 boolean requireUssd = c.getBoolean(
6127 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006128
Shuo Qian4a594052020-01-23 11:59:30 -08006129 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006130 if (requireUssd) {
6131 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6132 getSubscriptionCarrierId(subId));
6133 String newUssdCommand = "";
6134 try {
6135 newUssdCommand = carrierXmlParser.getFeature(
6136 CarrierXmlParser.FEATURE_CALL_WAITING)
6137 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6138 } catch (NullPointerException e) {
6139 loge("Failed to generate USSD number" + e);
6140 }
6141 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6142 mMainThreadHandler, callback, carrierXmlParser,
6143 CarrierXmlParser.SsEntry.SSAction.QUERY);
6144 final String ussdCommand = newUssdCommand;
6145 Executors.newSingleThreadExecutor().execute(() -> {
6146 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6147 });
6148 } else {
6149 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6150 callback::accept);
6151 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6152 }
Shuo Qian4a594052020-01-23 11:59:30 -08006153 } finally {
6154 Binder.restoreCallingIdentity(identity);
6155 }
6156 }
6157
6158 /**
Hall Liu27d24262020-09-18 19:04:59 -07006159 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006160 */
6161 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006162 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006163 enforceModifyPermission();
6164 long identity = Binder.clearCallingIdentity();
6165 try {
Hall Liu27d24262020-09-18 19:04:59 -07006166 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6167
6168 Phone phone = getPhone(subId);
6169 if (phone == null) {
6170 try {
6171 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6172 } catch (RemoteException e) {
6173 // ignore
6174 }
6175 return;
6176 }
6177
SongFerngWang0e767992021-03-31 22:08:45 +08006178 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6179 PersistableBundle c = configManager.getConfigForSubId(subId);
6180 boolean requireUssd = c.getBoolean(
6181 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006182
SongFerngWang0e767992021-03-31 22:08:45 +08006183 if (DBG) log("getCallWaitingStatus: subId " + subId);
6184 if (requireUssd) {
6185 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6186 getSubscriptionCarrierId(subId));
6187 CarrierXmlParser.SsEntry.SSAction ssAction =
6188 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6189 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6190 String newUssdCommand = "";
6191 try {
6192 newUssdCommand = carrierXmlParser.getFeature(
6193 CarrierXmlParser.FEATURE_CALL_WAITING)
6194 .makeCommand(ssAction, null);
6195 } catch (NullPointerException e) {
6196 loge("Failed to generate USSD number" + e);
6197 }
6198 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6199 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6200 final String ussdCommand = newUssdCommand;
6201 Executors.newSingleThreadExecutor().execute(() -> {
6202 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6203 });
6204 } else {
6205 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6206 FunctionalUtils.ignoreRemoteException(callback::accept));
6207
6208 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6209 }
Shuo Qian4a594052020-01-23 11:59:30 -08006210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
6213 }
6214
6215 /**
yinxub1bed742017-04-17 11:45:04 -07006216 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006217 *
yinxub1bed742017-04-17 11:45:04 -07006218 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006219 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6220 * location related information which will be sent if the caller already possess
6221 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006222 * @param request contains the radio access networks with bands/channels to scan
6223 * @param messenger callback messenger for scan results or errors
6224 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006225 * @return the id of the requested scan which can be used to stop the scan.
6226 */
6227 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006228 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6229 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006230 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6232 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006233 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006234 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6235 if (!renounceFineLocationAccess) {
6236 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6237 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6238 .setCallingPackage(callingPackage)
6239 .setCallingFeatureId(callingFeatureId)
6240 .setCallingPid(Binder.getCallingPid())
6241 .setCallingUid(Binder.getCallingUid())
6242 .setMethod("requestNetworkScan")
6243 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6244 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6245 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6246 .build());
6247 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006248 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006249 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6250 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006251 if (e != null) {
6252 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6253 throw e;
6254 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006255 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006256 return TelephonyScanManager.INVALID_SCAN_ID;
6257 }
6258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 }
Hall Liu912dfd32019-04-25 14:02:26 -07006260 int callingUid = Binder.getCallingUid();
6261 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006262 final long identity = Binder.clearCallingIdentity();
6263 try {
6264 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006265 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006266 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006267 } finally {
6268 Binder.restoreCallingIdentity(identity);
6269 }
yinxu504e1392017-04-12 16:03:22 -07006270 }
6271
Hall Liub2ac8ef2019-02-28 15:56:23 -08006272 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006273 NetworkScanRequest request, int subId, String callingPackage) {
6274 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006275 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6276 boolean hasNetworkScanPermission =
6277 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6278 == PERMISSION_GRANTED;
6279
6280 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6281 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6282 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006283 }
6284
6285 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6286 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006287 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6288 return new SecurityException("Specific channels must not be"
6289 + " scanned without location access.");
6290 }
6291 }
6292 }
6293
Hall Liub2ac8ef2019-02-28 15:56:23 -08006294 return null;
6295 }
6296
yinxu504e1392017-04-12 16:03:22 -07006297 /**
6298 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006299 *
6300 * @param subId id of the subscription
6301 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006302 */
6303 @Override
6304 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6306 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307
Hall Liu912dfd32019-04-25 14:02:26 -07006308 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 final long identity = Binder.clearCallingIdentity();
6310 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006311 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
yinxu504e1392017-04-12 16:03:22 -07006315 }
6316
6317 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006318 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006319 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006320 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006321 */
6322 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006323 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006324 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006325 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006326 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006330 if (DBG) log("getAllowedNetworkTypesBitmask");
6331 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6332 int networkTypesBitmask = (result != null ? result[0] : -1);
6333 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6334 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006338 }
6339
6340 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006341 * Get the allowed network types for certain reason.
6342 *
6343 * @param subId the id of the subscription.
6344 * @param reason the reason the allowed network type change is taking place
6345 * @return the allowed network types.
6346 */
6347 @Override
6348 public long getAllowedNetworkTypesForReason(int subId,
6349 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006350 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006351 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006352 final long identity = Binder.clearCallingIdentity();
6353 try {
6354 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
6358 }
6359
6360 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006361 * Enable/Disable E-UTRA-NR Dual Connectivity
6362 * @param subId subscription id of the sim card
6363 * @param nrDualConnectivityState expected NR dual connectivity state
6364 * This can be passed following states
6365 * <ol>
6366 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6367 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6368 * <li>Disable NR dual connectivity and force secondary cell to be released
6369 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6370 * </ol>
6371 * @return operation result.
6372 */
6373 @Override
6374 public int setNrDualConnectivityState(int subId,
6375 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6377 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006378 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006379 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6380 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6381 }
6382
Sooraj Sasindran37444802020-08-11 10:40:43 -07006383 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6387 nrDualConnectivityState, subId,
6388 workSource);
6389 if (DBG) log("enableNRDualConnectivity result: " + result);
6390 return result;
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
6394 }
6395
6396 /**
6397 * Is E-UTRA-NR Dual Connectivity enabled
6398 * @return true if dual connectivity is enabled else false
6399 */
6400 @Override
6401 public boolean isNrDualConnectivityEnabled(int subId) {
6402 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006403 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006404 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006405 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006406 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6407 return false;
6408 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6413 null, subId, workSource);
6414 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6415 return isEnabled;
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
6419 }
6420
6421 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006422 * Set the allowed network types of the device and
6423 * provide the reason triggering the allowed network change.
6424 *
6425 * @param subId the id of the subscription.
6426 * @param reason the reason the allowed network type change is taking place
6427 * @param allowedNetworkTypes the allowed network types.
6428 * @return true on success; false on any failure.
6429 */
6430 @Override
6431 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006432 @TelephonyManager.AllowedNetworkTypesReason int reason,
6433 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6435 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006436 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006437 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6438 return false;
6439 }
6440 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6441 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006442 return false;
6443 }
6444
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006445 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6446 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6447
6448
6449 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6450 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6451 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006452 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006453
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006454 final long identity = Binder.clearCallingIdentity();
6455 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006456 Boolean success = (Boolean) sendRequest(
6457 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6458 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6459
6460 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6461 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006462 } finally {
6463 Binder.restoreCallingIdentity(identity);
6464 }
6465 }
6466
6467 /**
Miaoa84611c2019-03-15 09:21:10 +08006468 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006469 *
Miaoa84611c2019-03-15 09:21:10 +08006470 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006471 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006472 * @hide
6473 */
6474 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006475 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006476 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006478 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479 try {
Miaoa84611c2019-03-15 09:21:10 +08006480 if (phone != null) {
6481 return phone.hasMatchedTetherApnSetting();
6482 } else {
6483 return false;
6484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006487 }
Junda Liu475951f2014-11-07 16:45:03 -08006488 }
6489
6490 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006491 * Get the user enabled state of Mobile Data.
6492 *
6493 * TODO: remove and use isUserDataEnabled.
6494 * This can't be removed now because some vendor codes
6495 * calls through ITelephony directly while they should
6496 * use TelephonyManager.
6497 *
6498 * @return true on enabled
6499 */
6500 @Override
6501 public boolean getDataEnabled(int subId) {
6502 return isUserDataEnabled(subId);
6503 }
6504
6505 /**
6506 * Get whether mobile data is enabled per user setting.
6507 *
6508 * There are other factors deciding whether mobile data is actually enabled, but they are
6509 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006510 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006511 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6512 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006513 *
6514 * @return {@code true} if data is enabled else {@code false}
6515 */
6516 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006517 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006518 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006519 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006520 try {
6521 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6522 functionName);
6523 } catch (Exception e) {
6524 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6525 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006526 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006528 mApp, subId, functionName);
6529
Robert Greenwalt646120a2014-05-23 11:54:03 -07006530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 int phoneId = mSubscriptionController.getPhoneId(subId);
6535 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6536 Phone phone = PhoneFactory.getPhone(phoneId);
6537 if (phone != null) {
6538 boolean retVal = phone.isUserDataEnabled();
6539 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6540 return retVal;
6541 } else {
6542 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6543 return false;
6544 }
6545 } finally {
6546 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006547 }
6548 }
6549
6550 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006551 * Checks if the device is capable of mobile data by considering whether whether the
6552 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6553 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006554 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006555 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006556 */
6557 @Override
6558 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006559 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006560 try {
6561 try {
6562 mApp.enforceCallingOrSelfPermission(
6563 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006564 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006565 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006566 try {
6567 mApp.enforceCallingOrSelfPermission(
6568 android.Manifest.permission.READ_PHONE_STATE,
6569 functionName);
6570 } catch (Exception e2) {
6571 mApp.enforceCallingOrSelfPermission(
6572 permission.READ_BASIC_PHONE_STATE, functionName);
6573 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006574 }
6575 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006576 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578
6579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 Phone phone = PhoneFactory.getPhone(phoneId);
6583 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006584 boolean retVal;
6585 if (phone.isUsingNewDataStack()) {
Sarah Chin2c094c52022-03-09 13:57:52 -08006586 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006587 } else {
6588 retVal = phone.getDataEnabledSettings().isDataEnabled();
6589 }
6590 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 return retVal;
6592 } else {
6593 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6594 return false;
6595 }
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006598 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006599 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006600
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006601 /**
6602 * Check if data is enabled for a specific reason
6603 * @param subId Subscription index
6604 * @param reason the reason the data enable change is taking place
6605 * @return {@code true} if the overall data is enabled; {@code false} if not.
6606 */
6607 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006608 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006609 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006610 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006611 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006612 try {
6613 mApp.enforceCallingOrSelfPermission(
6614 android.Manifest.permission.ACCESS_NETWORK_STATE,
6615 functionName);
6616 } catch (Exception e) {
6617 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6618 functionName);
6619 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006620 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006621 try {
6622 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006623 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006624 } catch (Exception e2) {
6625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006626 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006627 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006628 }
6629
6630
6631 final long identity = Binder.clearCallingIdentity();
6632 try {
6633 int phoneId = mSubscriptionController.getPhoneId(subId);
6634 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006635 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006636 + " reason=" + reason);
6637 }
6638 Phone phone = PhoneFactory.getPhone(phoneId);
6639 if (phone != null) {
6640 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006641 if (phone.isUsingNewDataStack()) {
6642 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006643 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006644 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6645 retVal = phone.isUserDataEnabled();
6646 } else {
6647 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6648 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006649 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006650 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006651 return retVal;
6652 } else {
6653 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006654 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006655 + subId + " retVal=false");
6656 }
6657 return false;
6658 }
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
6661 }
6662 }
6663
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006664 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006665 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006666 // No permission needed; this only lets the caller inspect their own status.
6667 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006668 }
Junda Liu29340342014-07-10 15:23:27 -07006669
6670 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006671 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006672 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006673 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6674 }
6675
6676 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6677 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006678 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006679 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006680 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6681 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006682 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6683 if (cpt == null) {
6684 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006685 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6686 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006687 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006688 }
6689
6690 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006691 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006692 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006693 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006694 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006695 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006696 Phone phone = getPhone(subId);
6697 if (phone == null) {
6698 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6699 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6700 }
6701 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6702 if (cpt == null) {
6703 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006704 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6705 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006706 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006707 }
6708
6709 @Override
6710 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006711 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006712 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6713 }
6714
6715 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006716 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006717 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006718 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006719 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006720 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6721 Phone phone = PhoneFactory.getPhone(phoneId);
6722 if (phone == null) {
6723 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006724 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006725 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6726 if (cpt == null) {
6727 continue;
6728 }
6729 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006730 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6731 break;
6732 }
6733 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006734 return result;
Junda Liu29340342014-07-10 15:23:27 -07006735 }
Derek Tan89e89d42014-07-08 17:00:10 -07006736
6737 @Override
Junda Liue64de782015-04-16 17:19:16 -07006738 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006739 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006740 Phone phone = PhoneFactory.getPhone(phoneId);
6741 if (phone == null) {
6742 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006743 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006744 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6745 if (cpt == null) {
6746 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006747 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006748 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006749 }
6750
Amith Yamasani6e118872016-02-19 12:53:51 -08006751 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006752 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006753 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006754 Phone phone = PhoneFactory.getPhone(phoneId);
6755 if (phone == null) {
6756 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006757 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006758 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6759 if (cpt == null) {
6760 return Collections.emptyList();
6761 }
6762 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006763 }
6764
chen xuf7e9fe82019-05-09 19:31:02 -07006765 @Override
6766 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006767 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006768 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006769 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006770 try {
6771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6772 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6773 }
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006776 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006777 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006778 }
6779
Rambo Wang6812ffb2022-03-15 16:54:17 -07006780 @Override
6781 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6782 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6783
6784 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6785 if (phone == null) {
6786 return null;
6787 }
6788 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6789 if (cpt == null) {
6790 return null;
6791 }
6792 return cpt.getCarrierServicePackageName();
6793 }
6794
Wink Savilleb564aae2014-10-23 10:18:09 -07006795 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006796 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006797 UiccPort port = phone == null ? null : phone.getUiccPort();
6798 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006799 return null;
6800 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006801 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006802 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006803 return null;
6804 }
6805 return iccId;
6806 }
6807
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006808 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006809 public void setCallComposerStatus(int subId, int status) {
6810 enforceModifyPermission();
6811
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 Phone phone = getPhone(subId);
6815 if (phone != null) {
6816 Phone defaultPhone = phone.getImsPhone();
6817 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6818 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6819 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006820 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6821 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006822 }
6823 }
Shuo Qian284ae752020-12-22 19:10:14 -08006824 } catch (ImsException e) {
6825 throw new ServiceSpecificException(e.getCode());
6826 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006827 Binder.restoreCallingIdentity(identity);
6828 }
6829 }
6830
6831 @Override
6832 public int getCallComposerStatus(int subId) {
6833 enforceReadPrivilegedPermission("getCallComposerStatus");
6834
6835 final long identity = Binder.clearCallingIdentity();
6836 try {
6837 Phone phone = getPhone(subId);
6838 if (phone != null) {
6839 Phone defaultPhone = phone.getImsPhone();
6840 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6841 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6842 return imsPhone.getCallComposerStatus();
6843 }
6844 }
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
6847 }
6848 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6849 }
6850
6851 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006852 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6853 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006854 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006855 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 final long identity = Binder.clearCallingIdentity();
6858 try {
6859 final String iccId = getIccId(subId);
6860 final Phone phone = getPhone(subId);
6861 if (phone == null) {
6862 return false;
6863 }
6864 final String subscriberId = phone.getSubscriberId();
6865
6866 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006867 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 + subscriberId + " to " + number);
6869 }
6870
6871 if (TextUtils.isEmpty(iccId)) {
6872 return false;
6873 }
6874
6875 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6876
6877 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6878 if (alphaTag == null) {
6879 editor.remove(alphaTagPrefKey);
6880 } else {
6881 editor.putString(alphaTagPrefKey, alphaTag);
6882 }
6883
6884 // Record both the line number and IMSI for this ICCID, since we need to
6885 // track all merged IMSIs based on line number
6886 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6887 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6888 if (number == null) {
6889 editor.remove(numberPrefKey);
6890 editor.remove(subscriberPrefKey);
6891 } else {
6892 editor.putString(numberPrefKey, number);
6893 editor.putString(subscriberPrefKey, subscriberId);
6894 }
6895
6896 editor.commit();
6897 return true;
6898 } finally {
6899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006900 }
Derek Tan7226c842014-07-02 17:42:23 -07006901 }
6902
6903 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006904 public String getLine1NumberForDisplay(int subId, String callingPackage,
6905 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006906 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006908 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006909 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006910 return null;
6911 }
Derek Tan97ebb422014-09-05 16:55:38 -07006912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 final long identity = Binder.clearCallingIdentity();
6914 try {
6915 String iccId = getIccId(subId);
6916 if (iccId != null) {
6917 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6918 if (DBG_MERGE) {
6919 log("getLine1NumberForDisplay returning "
6920 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6921 }
6922 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6925 return null;
6926 } finally {
6927 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006928 }
Derek Tan7226c842014-07-02 17:42:23 -07006929 }
6930
6931 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006932 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6933 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006935 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006936 return null;
6937 }
Derek Tan97ebb422014-09-05 16:55:38 -07006938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 String iccId = getIccId(subId);
6942 if (iccId != null) {
6943 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6944 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6945 }
6946 return null;
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006949 }
Derek Tan7226c842014-07-02 17:42:23 -07006950 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006951
6952 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006953 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6954 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006955 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6956 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006958 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006959 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006960 return null;
6961 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006962
Jordan Liub49b04b2019-05-06 14:45:15 -07006963 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6964 // the process, where TelephonyManager was instantiated.
6965 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006966 final long identity = Binder.clearCallingIdentity();
6967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006968 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 final TelephonyManager tele = TelephonyManager.from(context);
6970 final SubscriptionManager sub = SubscriptionManager.from(context);
6971
6972 // Figure out what subscribers are currently active
6973 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006974
Jordan Liub49b04b2019-05-06 14:45:15 -07006975 // Only consider subs which match the current subId
6976 // This logic can be simplified. See b/131189269 for progress.
6977 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006978 activeSubscriberIds.add(tele.getSubscriberId(subId));
6979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980
6981 // First pass, find a number override for an active subscriber
6982 String mergeNumber = null;
6983 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6984 for (String key : prefs.keySet()) {
6985 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6986 final String subscriberId = (String) prefs.get(key);
6987 if (activeSubscriberIds.contains(subscriberId)) {
6988 final String iccId = key.substring(
6989 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6990 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6991 mergeNumber = (String) prefs.get(numberKey);
6992 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006993 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 + " for active subscriber " + subscriberId);
6995 }
6996 if (!TextUtils.isEmpty(mergeNumber)) {
6997 break;
6998 }
6999 }
7000 }
7001 }
7002
7003 // Shortcut when no active merged subscribers
7004 if (TextUtils.isEmpty(mergeNumber)) {
7005 return null;
7006 }
7007
7008 // Second pass, find all subscribers under that line override
7009 final ArraySet<String> result = new ArraySet<>();
7010 for (String key : prefs.keySet()) {
7011 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7012 final String number = (String) prefs.get(key);
7013 if (mergeNumber.equals(number)) {
7014 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7015 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7016 final String subscriberId = (String) prefs.get(subscriberKey);
7017 if (!TextUtils.isEmpty(subscriberId)) {
7018 result.add(subscriberId);
7019 }
7020 }
7021 }
7022 }
7023
7024 final String[] resultArray = result.toArray(new String[result.size()]);
7025 Arrays.sort(resultArray);
7026 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007027 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7029 }
7030 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007031 } finally {
7032 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007033 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007034 }
7035
7036 @Override
zoey chen38003472019-12-13 17:16:31 +08007037 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7038 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007039
7040 final long identity = Binder.clearCallingIdentity();
7041 try {
7042 final TelephonyManager telephonyManager = mApp.getSystemService(
7043 TelephonyManager.class);
7044 String subscriberId = telephonyManager.getSubscriberId(subId);
7045 if (subscriberId == null) {
7046 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007047 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007048 + subId);
7049 }
7050 return null;
7051 }
7052
7053 final SubscriptionInfo info = SubscriptionController.getInstance()
7054 .getSubscriptionInfo(subId);
7055 final ParcelUuid groupUuid = info.getGroupUuid();
7056 // If it doesn't belong to any group, return just subscriberId of itself.
7057 if (groupUuid == null) {
7058 return new String[]{subscriberId};
7059 }
7060
7061 // Get all subscriberIds from the group.
7062 final List<String> mergedSubscriberIds = new ArrayList<>();
7063 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007064 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007065 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007066 for (SubscriptionInfo subInfo : groupInfos) {
7067 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7068 if (subscriberId != null) {
7069 mergedSubscriberIds.add(subscriberId);
7070 }
7071 }
7072
7073 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7074 } finally {
7075 Binder.restoreCallingIdentity(identity);
7076
7077 }
7078 }
7079
7080 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007081 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007082 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007083 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084
7085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 final Phone phone = getPhone(subId);
7088 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7089 } finally {
7090 Binder.restoreCallingIdentity(identity);
7091 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007092 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007093
7094 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007095 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007096 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7097 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007098 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7099 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100
7101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 final Phone phone = getPhone(subId);
7104 if (phone == null) {
7105 return false;
7106 }
7107 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7108 cdmaNonRoamingList);
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007111 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007112 }
7113
7114 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007115 @Deprecated
7116 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7117 enforceModifyPermission();
7118
7119 int returnValue = 0;
7120 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007121 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007122 if(result.exception == null) {
7123 if (result.result != null) {
7124 byte[] responseData = (byte[])(result.result);
7125 if(responseData.length > oemResp.length) {
7126 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7127 responseData.length + "bytes. Buffer Size is " +
7128 oemResp.length + "bytes.");
7129 }
7130 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7131 returnValue = responseData.length;
7132 }
7133 } else {
7134 CommandException ex = (CommandException) result.exception;
7135 returnValue = ex.getCommandError().ordinal();
7136 if(returnValue > 0) returnValue *= -1;
7137 }
7138 } catch (RuntimeException e) {
7139 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7140 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7141 if(returnValue > 0) returnValue *= -1;
7142 }
7143
7144 return returnValue;
7145 }
7146
7147 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007148 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007149 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007150 try {
7151 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007152 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007153 mApp, phone.getSubId(), "getRadioAccessFamily");
7154 } catch (SecurityException e) {
7155 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7156 throw e;
7157 }
chen xub97461a2018-10-26 14:17:57 -07007158 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007159 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007160 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 final long identity = Binder.clearCallingIdentity();
7163 try {
chen xub97461a2018-10-26 14:17:57 -07007164 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007165 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007166 mApp, phone.getSubId(), "getRadioAccessFamily");
7167 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
chen xub97461a2018-10-26 14:17:57 -07007171 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007172 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007173
7174 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007175 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007176 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007177 try {
7178 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7179 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007180 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007181 }
7182 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007183 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007184 }
7185 RoleManager rm = mApp.getSystemService(RoleManager.class);
7186 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7187 if (!dialerRoleHolders.contains(callingPackage)) {
7188 throw new SecurityException("App must be the dialer role holder to"
7189 + " upload a call composer pic");
7190 }
7191
7192 Executors.newSingleThreadExecutor().execute(() -> {
7193 ByteArrayOutputStream output = new ByteArrayOutputStream(
7194 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7195 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7196 boolean readUntilEnd = false;
7197 int totalBytesRead = 0;
7198 byte[] buffer = new byte[16 * 1024];
7199 while (true) {
7200 int numRead;
7201 try {
7202 numRead = input.read(buffer);
7203 } catch (IOException e) {
7204 try {
7205 fd.checkError();
7206 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7207 null);
7208 } catch (IOException e1) {
7209 // This means that the other side closed explicitly with an error. If this
7210 // happens, log and ignore.
7211 loge("Remote end of call composer picture pipe closed: " + e1);
7212 }
7213 break;
7214 }
7215 if (numRead == -1) {
7216 readUntilEnd = true;
7217 break;
7218 }
7219 totalBytesRead += numRead;
7220 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7221 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7222 try {
7223 input.close();
7224 } catch (IOException e) {
7225 // ignore
7226 }
7227 break;
7228 }
7229 output.write(buffer, 0, numRead);
7230 }
7231 // Generally, the remote end will close the file descriptors. The only case where we
7232 // close is above, where the picture size is too big.
7233
7234 try {
7235 fd.checkError();
7236 } catch (IOException e) {
7237 loge("Remote end for call composer closed with an error: " + e);
7238 return;
7239 }
7240
Hall Liuaa4211e2021-01-20 15:43:39 -08007241 if (!readUntilEnd) {
7242 loge("Did not finish reading entire image; aborting");
7243 return;
7244 }
Hall Liu82694d52020-12-11 18:22:04 -08007245
Hall Liuaa4211e2021-01-20 15:43:39 -08007246 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7247 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7248 new CallComposerPictureTransfer.Factory() {},
7249 imageData,
7250 (result) -> {
7251 if (result.first != null) {
7252 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7253 Bundle outputResult = new Bundle();
7254 outputResult.putParcelable(
7255 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7256 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7257 outputResult);
7258 } else {
7259 callback.send(result.second, null);
7260 }
7261 }
7262 );
Hall Liu82694d52020-12-11 18:22:04 -08007263 });
7264 }
7265
7266 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007267 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007268 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007269 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007273 ImsManager.getInstance(defaultPhone.getContext(),
7274 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275 } finally {
7276 Binder.restoreCallingIdentity(identity);
7277 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007278 }
7279
7280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007281 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007282 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7284 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007285 return false;
7286 }
Svet Ganovb320e182015-04-16 12:30:10 -07007287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 // Check the user preference and the system-level IMS setting. Even if the user has
7291 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7292 // In the long run, we may instead need to check if there exists a connection service
7293 // which can support video calling.
7294 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007295 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296 return imsManager.isVtEnabledByPlatform()
7297 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7298 && imsManager.isVtEnabledByUser();
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007302 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007303
Andrew Leea1239f22015-03-02 17:44:07 -08007304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007305 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7306 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007308 mApp, subId, callingPackage, callingFeatureId,
7309 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 return false;
7311 }
7312
7313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 CarrierConfigManager configManager =
7316 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007317 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7319 } finally {
7320 Binder.restoreCallingIdentity(identity);
7321 }
Andrew Leea1239f22015-03-02 17:44:07 -08007322 }
7323
7324 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007325 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007327 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328 return false;
7329 }
7330
7331 final long identity = Binder.clearCallingIdentity();
7332 try {
7333 CarrierConfigManager configManager =
7334 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007335 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007336 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
Andrew Leea1239f22015-03-02 17:44:07 -08007340 }
7341
Andrew Lee9431b832015-03-09 18:46:45 -07007342 @Override
7343 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007344 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007345 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007346 }
7347
7348 @Override
7349 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 final long identity = Binder.clearCallingIdentity();
7351 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007352 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
Andrew Lee9431b832015-03-09 18:46:45 -07007356 }
7357
Hall Liuf6668912018-10-31 17:05:23 -07007358 /**
7359 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7360 * support for the feature and device firmware support.
7361 *
7362 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7363 */
7364 @Override
7365 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007367 final Phone phone = getPhone(subscriptionId);
7368 if (phone == null) {
7369 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7370 return false;
7371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007373 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7375 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007376 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 return isCarrierSupported && isDeviceSupported;
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
Hall Liu98187582018-01-22 19:15:32 -08007381 }
7382
Hall Liuf6668912018-10-31 17:05:23 -07007383 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007384 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7385 * RTT setting, will return true if the device and carrier both support RTT.
7386 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007387 */
7388 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 final long identity = Binder.clearCallingIdentity();
7390 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007391 boolean isRttSupported = isRttSupported(subscriptionId);
7392 boolean isUserRttSettingOn = Settings.Secure.getInt(
7393 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7394 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7395 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7396 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 } finally {
7398 Binder.restoreCallingIdentity(identity);
7399 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007400 }
7401
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007402 @Deprecated
7403 @Override
7404 public String getDeviceId(String callingPackage) {
7405 return getDeviceIdWithFeature(callingPackage, null);
7406 }
7407
Sanket Padawe7310cc72015-01-14 09:53:20 -08007408 /**
7409 * Returns the unique device ID of phone, for example, the IMEI for
7410 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7411 *
7412 * <p>Requires Permission:
7413 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7414 */
7415 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007416 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007417 try {
7418 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7419 } catch (SecurityException se) {
7420 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7421 throw new SecurityException("Package " + callingPackage + " does not belong to "
7422 + Binder.getCallingUid());
7423 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007424 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007425 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007426 return null;
7427 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007428 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007429 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007430 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007431 return null;
7432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433
7434 final long identity = Binder.clearCallingIdentity();
7435 try {
7436 return phone.getDeviceId();
7437 } finally {
7438 Binder.restoreCallingIdentity(identity);
7439 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007440 }
7441
Ping Sunc67b7c22016-03-02 19:16:45 +08007442 /**
7443 * {@hide}
7444 * Returns the IMS Registration Status on a particular subid
7445 *
7446 * @param subId
7447 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007448 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007449 Phone phone = getPhone(subId);
7450 if (phone != null) {
7451 return phone.isImsRegistered();
7452 } else {
7453 return false;
7454 }
7455 }
7456
Santos Cordon7a1885b2015-02-03 11:15:19 -08007457 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007458 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007459 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007461 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007462 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7463 }
7464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
7470 }
7471
7472 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007473 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007474 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007475 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007476 mApp,
7477 subscriptionId,
7478 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007479 final long identity = Binder.clearCallingIdentity();
7480 try {
7481 Phone phone = getPhone(subscriptionId);
7482 if (phone == null) {
7483 return null;
7484 }
7485 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
7489 }
7490
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007491 /**
7492 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007493 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007494 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 final long identity = Binder.clearCallingIdentity();
7496 try {
7497 Phone phone = getPhone(subId);
7498 if (phone != null) {
7499 return phone.isWifiCallingEnabled();
7500 } else {
7501 return false;
7502 }
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007505 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007506 }
7507
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007508 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007509 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007510 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007511 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 final long identity = Binder.clearCallingIdentity();
7513 try {
7514 Phone phone = getPhone(subId);
7515 if (phone != null) {
7516 return phone.isVideoEnabled();
7517 } else {
7518 return false;
7519 }
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007522 }
7523 }
7524
7525 /**
7526 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7527 * defined in {@link ImsRegistrationImplBase}.
7528 */
7529 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 final long identity = Binder.clearCallingIdentity();
7531 try {
7532 Phone phone = getPhone(subId);
7533 if (phone != null) {
7534 return phone.getImsRegistrationTech();
7535 } else {
7536 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7537 }
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007540 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007541 }
7542
Stuart Scott8eef64f2015-04-08 15:13:54 -07007543 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007544 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007545 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007546 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7547 return;
7548 }
Kai Shif70f46f2021-03-03 13:59:46 -08007549 Phone defaultPhone = getDefaultPhone();
7550 if (defaultPhone != null) {
7551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7552 mApp, getDefaultPhone().getSubId(), "factoryReset");
7553 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007554 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007555
Svet Ganovcc087f82015-05-12 20:35:54 -07007556 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007557 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7558 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007559 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007560 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007561 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007562 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007563 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007564 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007565 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007566 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007567 // There has been issues when Sms raw table somehow stores orphan
7568 // fragments. They lead to garbled message when new fragments come
7569 // in and combined with those stale ones. In case this happens again,
7570 // user can reset all network settings which will clean up this table.
7571 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007572 // Clean up IMS settings as well here.
7573 int slotId = getSlotIndex(subId);
7574 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7575 ImsManager.getInstance(mApp, slotId).factoryReset();
7576 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007577
Kai Shif70f46f2021-03-03 13:59:46 -08007578 if (defaultPhone == null) {
7579 return;
7580 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007581 // Erase modem config if erase modem on network setting is enabled.
7582 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7583 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7584 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007585 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007586 }
Kai Shif70f46f2021-03-03 13:59:46 -08007587
7588 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007589 } finally {
7590 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007591 }
7592 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007593
SongFerngWangfd89b102021-05-27 22:44:54 +08007594 @VisibleForTesting
7595 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7596 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7597 return;
7598 }
7599 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7600 RILConstants.PREFERRED_NETWORK_MODE);
7601 SubscriptionManager.setSubscriptionProperty(subId,
7602 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7603 "user=" + defaultNetworkType);
7604 phone.loadAllowedNetworksFromSubscriptionDatabase();
7605 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7606 defaultNetworkType, null);
7607 }
7608
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007609 private void cleanUpSmsRawTable(Context context) {
7610 ContentResolver resolver = context.getContentResolver();
7611 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7612 resolver.delete(uri, null, null);
7613 }
7614
Narayan Kamath1c496c22015-04-16 14:40:19 +01007615 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007616 public String getSimLocaleForSubscriber(int subId) {
7617 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7618 final Phone phone = getPhone(subId);
7619 if (phone == null) {
7620 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007621 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 final long identity = Binder.clearCallingIdentity();
7624 try {
chen xu5d3637b2019-01-21 23:31:38 -08007625 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007626 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007627 if (info == null) {
7628 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7629 return null;
7630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 // Try and fetch the locale from the carrier properties or from the SIM language
7632 // preferences (EF-PL and EF-LI)...
7633 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007635 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7636 if (localeFromDefaultSim != null) {
7637 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7638 if (DBG) log("Using locale from subId: " + subId + " locale: "
7639 + localeFromDefaultSim);
7640 return localeFromDefaultSim.toLanguageTag();
7641 } else {
7642 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 }
7644 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 // The SIM language preferences only store a language (e.g. fr = French), not an
7647 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7648 // the SIM and carrier preferences does not include a country we add the country
7649 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007650 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007652 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653 return mccLocale.toLanguageTag();
7654 }
7655
7656 if (DBG) log("No locale found - returning null");
7657 return null;
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007661 }
7662
7663 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007664 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007665 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007666 }
7667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668 /**
7669 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7670 */
7671 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007672 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007673 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007674 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007675
Gary Jian3aa9a762022-01-24 16:41:19 +08007676 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7677 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007678
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007679 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007680 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7681 * representing the state of the modem.
7682 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007683 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7684 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007685 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007686 */
7687 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007688 public void requestModemActivityInfo(ResultReceiver result) {
7689 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691
7692 final long identity = Binder.clearCallingIdentity();
7693 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007694 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 } finally {
7696 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007697 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007698 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007699
Siddharth Rayb8114062018-06-17 15:02:38 -07007700 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7701 // less than total activity duration.
7702 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7703 if (info == null) {
7704 return false;
7705 }
7706 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007707 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7708 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7709
Siddharth Rayb8114062018-06-17 15:02:38 -07007710 return (info.isValid()
7711 && (info.getSleepTimeMillis() <= activityDurationMs)
7712 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007713 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007714 && (totalTxTimeMs <= activityDurationMs));
7715 }
7716
Gary Jian3aa9a762022-01-24 16:41:19 +08007717 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7718 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7719 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7720 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7721
7722 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7723 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7724 }
7725
7726 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7727 mLastModemActivityInfo.setReceiveTimeMillis(
7728 rat,
7729 freq,
7730 info.getReceiveTimeMillis(rat, freq)
7731 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7732 }
7733
7734 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7735 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7736 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7737 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7738
7739 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7740 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7741 }
7742 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7743 mLastModemActivityInfo.setReceiveTimeMillis(
7744 rat,
7745 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7746 }
7747
7748 /**
7749 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7750 * @param info recent ModemActivityInfo
7751 */
7752 private void mergeModemActivityInfo(ModemActivityInfo info) {
7753 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7754 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7755 boolean matched;
7756 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7757 matched = false;
7758 int rat = info.getSpecificInfoRat(i);
7759 int freq = info.getSpecificInfoFrequencyRange(i);
7760 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7761 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7762 //if it already exists
7763 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7764 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7765 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7766 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7767 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7768 updateLastModemActivityInfo(info, rat, freq);
7769 matched = true;
7770 }
7771 } else {
7772 updateLastModemActivityInfo(info, rat);
7773 matched = true;
7774 }
7775 }
7776 }
7777
7778 if (!matched) {
7779 mDeltaSpecificInfo =
7780 new ActivityStatsTechSpecificInfo(
7781 rat,
7782 freq,
7783 info.getTransmitTimeMillis(rat, freq),
7784 (int) info.getReceiveTimeMillis(rat, freq));
7785 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7786 }
7787 }
7788 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7789 mLastModemActivitySpecificInfo =
7790 new ActivityStatsTechSpecificInfo[merged.size()];
7791 merged.toArray(mLastModemActivitySpecificInfo);
7792
7793 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7794 mLastModemActivityInfo.setSleepTimeMillis(
7795 info.getSleepTimeMillis()
7796 + mLastModemActivityInfo.getSleepTimeMillis());
7797 mLastModemActivityInfo.setIdleTimeMillis(
7798 info.getIdleTimeMillis()
7799 + mLastModemActivityInfo.getIdleTimeMillis());
7800 }
7801
Jack Yu85bd38a2015-11-09 11:34:32 -08007802 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007803 * Returns the service state information on specified subscription.
7804 */
7805 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007806 public ServiceState getServiceStateForSubscriber(int subId,
7807 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7808 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007810 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007811 return null;
7812 }
7813
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007814 boolean hasFinePermission = false;
7815 boolean hasCoarsePermission = false;
7816 if (!renounceFineLocationAccess) {
7817 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7818 LocationAccessPolicy.checkLocationPermission(mApp,
7819 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7820 .setCallingPackage(callingPackage)
7821 .setCallingFeatureId(callingFeatureId)
7822 .setCallingPid(Binder.getCallingPid())
7823 .setCallingUid(Binder.getCallingUid())
7824 .setMethod("getServiceStateForSubscriber")
7825 .setLogAsInfo(true)
7826 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7827 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7828 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7829 .build());
7830 hasFinePermission =
7831 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7832 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007833
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007834 if (!renounceCoarseLocationAccess) {
7835 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7836 LocationAccessPolicy.checkLocationPermission(mApp,
7837 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7838 .setCallingPackage(callingPackage)
7839 .setCallingFeatureId(callingFeatureId)
7840 .setCallingPid(Binder.getCallingPid())
7841 .setCallingUid(Binder.getCallingUid())
7842 .setMethod("getServiceStateForSubscriber")
7843 .setLogAsInfo(true)
7844 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7845 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7846 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7847 .build());
7848 hasCoarsePermission =
7849 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7850 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007851
Jack Yu479f40e2020-10-27 21:29:25 -07007852 final Phone phone = getPhone(subId);
7853 if (phone == null) {
7854 return null;
7855 }
7856
Jordan Liu0f2bc442020-11-18 16:47:37 -08007857 final long identity = Binder.clearCallingIdentity();
7858
Jack Yu479f40e2020-10-27 21:29:25 -07007859 boolean isCallingPackageDataService = phone.getDataServicePackages()
7860 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007862 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7863 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7864 Rlog.d(LOG_TAG,
7865 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7866 return null;
7867 }
7868
Hall Liuf19c44f2018-11-27 14:38:17 -08007869 ServiceState ss = phone.getServiceState();
7870
7871 // Scrub out the location info in ServiceState depending on what level of access
7872 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007873 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007874 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7875 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876 } finally {
7877 Binder.restoreCallingIdentity(identity);
7878 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007879 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007880
7881 /**
7882 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7883 *
7884 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7885 * voicemail ringtone.
7886 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7887 * PhoneAccount.
7888 */
7889 @Override
7890 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7894 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007895 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7899 } finally {
7900 Binder.restoreCallingIdentity(identity);
7901 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007902 }
7903
7904 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007905 * Sets the per-account voicemail ringtone.
7906 *
7907 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7908 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7909 *
7910 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7911 * voicemail ringtone.
7912 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7913 * PhoneAccount.
7914 */
7915 @Override
7916 public void setVoicemailRingtoneUri(String callingPackage,
7917 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007918 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007919 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007920 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7921 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7923 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7924 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7930 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007931 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 }
7933 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007936 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007937 }
7938
7939 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007940 * Returns whether vibration is set for voicemail notification in Phone settings.
7941 *
7942 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7943 * voicemail vibration setting.
7944 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7945 */
7946 @Override
7947 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 final long identity = Binder.clearCallingIdentity();
7949 try {
7950 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7951 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007952 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007959 }
7960
Youhan Wange64578a2016-05-02 15:32:42 -07007961 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007962 * Sets the per-account voicemail vibration.
7963 *
7964 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7965 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7966 *
7967 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7968 * voicemail vibration setting.
7969 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7970 * specific PhoneAccount.
7971 */
7972 @Override
7973 public void setVoicemailVibrationEnabled(String callingPackage,
7974 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007975 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007977 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7978 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7980 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7981 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007982 }
7983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7987 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 }
7990 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007993 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007994 }
7995
7996 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007997 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7998 *
7999 * @throws SecurityException if the caller does not have the required permission
8000 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008001 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008002 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008003 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008004 }
8005
8006 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008007 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8008 * permission.
8009 *
8010 * @throws SecurityException if the caller does not have the required permission
8011 */
8012 private void enforceSendSmsPermission() {
8013 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8014 }
8015
8016 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008017 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008018 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008019 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008020 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008021 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 final long identity = Binder.clearCallingIdentity();
8023 try {
8024 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008025 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 if (componentName == null) {
8027 throw new SecurityException(
8028 "Caller not current active visual voicemail package[null]");
8029 }
8030 String vvmPackage = componentName.getPackageName();
8031 if (!callingPackage.equals(vvmPackage)) {
8032 throw new SecurityException("Caller not current active visual voicemail package["
8033 + vvmPackage + "]");
8034 }
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008037 }
8038 }
8039
8040 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008041 * Return the application ID for the app type.
8042 *
8043 * @param subId the subscription ID that this request applies to.
8044 * @param appType the uicc app type.
8045 * @return Application ID for specificied app type, or null if no uicc.
8046 */
8047 @Override
8048 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008049 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008050 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051
8052 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008053 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 if (phone == null) {
8055 return null;
8056 }
8057 String aid = null;
8058 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008059 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 .getApplicationByType(appType).getAid();
8061 } catch (Exception e) {
8062 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8063 }
8064 return aid;
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008067 }
Youhan Wange64578a2016-05-02 15:32:42 -07008068 }
8069
Youhan Wang4001d252016-05-11 10:29:41 -07008070 /**
8071 * Return the Electronic Serial Number.
8072 *
8073 * @param subId the subscription ID that this request applies to.
8074 * @return ESN or null if error.
8075 */
8076 @Override
8077 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008078 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008079 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080
8081 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008082 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 if (phone == null) {
8084 return null;
8085 }
8086 String esn = null;
8087 try {
8088 esn = phone.getEsn();
8089 } catch (Exception e) {
8090 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8091 }
8092 return esn;
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008095 }
Youhan Wang4001d252016-05-11 10:29:41 -07008096 }
8097
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008098 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008099 * Return the Preferred Roaming List Version.
8100 *
8101 * @param subId the subscription ID that this request applies to.
8102 * @return PRLVersion or null if error.
8103 */
8104 @Override
8105 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008106 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008107 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108
8109 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008110 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 if (phone == null) {
8112 return null;
8113 }
8114 String cdmaPrlVersion = null;
8115 try {
8116 cdmaPrlVersion = phone.getCdmaPrlVersion();
8117 } catch (Exception e) {
8118 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8119 }
8120 return cdmaPrlVersion;
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008123 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008124 }
8125
8126 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008127 * Get snapshot of Telephony histograms
8128 * @return List of Telephony histograms
8129 * @hide
8130 */
8131 @Override
8132 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8134 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135
8136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 return RIL.getTelephonyRILTimingHistograms();
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008142 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008143
8144 /**
8145 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008146 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8147 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008148 * Require system privileges. In the future we may add this to carrier APIs.
8149 *
Michele Berionne482f8202018-11-27 18:57:59 -08008150 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008151 */
8152 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008153 @TelephonyManager.SetCarrierRestrictionResult
8154 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008155 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008157
Michele Berionne482f8202018-11-27 18:57:59 -08008158 if (carrierRestrictionRules == null) {
8159 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008160 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 final long identity = Binder.clearCallingIdentity();
8163 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008164 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008165 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008169 }
8170
8171 /**
8172 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008173 * Get the allowed carrier list and the excluded carrier list, including the priority between
8174 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008175 * Require system privileges. In the future we may add this to carrier APIs.
8176 *
Michele Berionne482f8202018-11-27 18:57:59 -08008177 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008178 */
8179 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008180 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008181 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008182 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183
8184 final long identity = Binder.clearCallingIdentity();
8185 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008186 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8187 if (response instanceof CarrierRestrictionRules) {
8188 return (CarrierRestrictionRules) response;
8189 }
8190 // Response is an Exception of some kind,
8191 // which is signalled to the user as a NULL retval
8192 return null;
8193 } catch (Exception e) {
8194 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8195 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 } finally {
8197 Binder.restoreCallingIdentity(identity);
8198 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008199 }
8200
fionaxu59545b42016-05-25 15:53:37 -07008201 /**
fionaxu59545b42016-05-25 15:53:37 -07008202 * Action set from carrier signalling broadcast receivers to enable/disable radio
8203 * @param subId the subscription ID that this action applies to.
8204 * @param enabled control enable or disable radio.
8205 * {@hide}
8206 */
8207 @Override
8208 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8209 enforceModifyPermission();
8210 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008211
8212 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008213 if (phone == null) {
8214 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8215 return;
8216 }
8217 try {
8218 phone.carrierActionSetRadioEnabled(enabled);
8219 } catch (Exception e) {
8220 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 } finally {
8222 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008223 }
8224 }
8225
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008226 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008227 * Enable or disable Voice over NR (VoNR)
8228 * @param subId the subscription ID that this action applies to.
8229 * @param enabled enable or disable VoNR.
8230 * @return operation result.
8231 */
8232 @Override
8233 public int setVoNrEnabled(int subId, boolean enabled) {
8234 enforceModifyPermission();
8235 final Phone phone = getPhone(subId);
8236
8237 final long identity = Binder.clearCallingIdentity();
8238 if (phone == null) {
8239 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8240 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8241 }
8242
8243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8244 try {
8245 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8246 workSource);
8247 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008248
8249 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8250 if (DBG) {
8251 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8252 }
8253 SubscriptionManager.setSubscriptionProperty(
8254 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8255 (enabled ? "1" : "0"));
8256 }
8257
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008258 return result;
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
8261 }
8262 }
8263
8264 /**
8265 * Is voice over NR enabled
8266 * @return true if VoNR is enabled else false
8267 */
8268 @Override
8269 public boolean isVoNrEnabled(int subId) {
8270 enforceReadPrivilegedPermission("isVoNrEnabled");
8271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8272 final long identity = Binder.clearCallingIdentity();
8273 try {
8274 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8275 null, subId, workSource);
8276 if (DBG) log("isVoNrEnabled: " + isEnabled);
8277 return isEnabled;
8278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
8281 }
8282
8283 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008284 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8285 * network status based on which carrier apps could apply actions accordingly,
8286 * enable/disable default url handler for example.
8287 *
8288 * @param subId the subscription ID that this action applies to.
8289 * @param report control start/stop reporting the default network status.
8290 * {@hide}
8291 */
8292 @Override
8293 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8294 enforceModifyPermission();
8295 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296
8297 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008298 if (phone == null) {
8299 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8300 return;
8301 }
8302 try {
8303 phone.carrierActionReportDefaultNetworkStatus(report);
8304 } catch (Exception e) {
8305 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 } finally {
8307 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008308 }
8309 }
8310
8311 /**
fionaxud9622282017-07-17 17:51:30 -07008312 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8313 * @param subId the subscription ID that this action applies to.
8314 * {@hide}
8315 */
8316 @Override
8317 public void carrierActionResetAll(int subId) {
8318 enforceModifyPermission();
8319 final Phone phone = getPhone(subId);
8320 if (phone == null) {
8321 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8322 return;
8323 }
8324 try {
8325 phone.carrierActionResetAll();
8326 } catch (Exception e) {
8327 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8328 }
8329 }
8330
8331 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008332 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8333 * bug report is being generated.
8334 */
8335 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008336 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008337 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8338 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008339 writer.println("Permission Denial: can't dump Phone from pid="
8340 + Binder.getCallingPid()
8341 + ", uid=" + Binder.getCallingUid()
8342 + "without permission "
8343 + android.Manifest.permission.DUMP);
8344 return;
8345 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008346 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008347 }
Jack Yueb89b242016-06-22 13:27:47 -07008348
Brad Ebingerdac2f002018-04-03 15:17:52 -07008349 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008350 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8351 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8352 @NonNull String[] args) {
8353 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8354 this, in.getFileDescriptor(), out.getFileDescriptor(),
8355 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008356 }
8357
Jack Yueb89b242016-06-22 13:27:47 -07008358 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008359 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008360 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008361 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008362 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008363 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008364 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008365 */
8366 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008367 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008368 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008369 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8370 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8371 try {
8372 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008373 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008374 } catch (SecurityException se) {
8375 enforceModifyPermission();
8376 }
8377 } else {
8378 enforceModifyPermission();
8379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380
8381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 Phone phone = getPhone(subId);
8384 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008385 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8386 phone.carrierActionSetMeteredApnsEnabled(enabled);
8387 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008388 if (phone.isUsingNewDataStack()) {
Sarah Chinecc78c42022-03-31 21:16:48 -07008389 phone.getDataSettingsManager().setDataEnabled(
8390 reason, enabled, callingPackage);
Jack Yu99e87332021-12-17 23:14:15 -08008391 } else {
8392 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8393 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 }
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008398 }
8399 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008400
8401 /**
8402 * Get Client request stats
8403 * @return List of Client Request Stats
8404 * @hide
8405 */
8406 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008407 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8408 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008409 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008410 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008411 return null;
8412 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008413 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008415 final long identity = Binder.clearCallingIdentity();
8416 try {
8417 if (phone != null) {
8418 return phone.getClientRequestStats();
8419 }
8420
8421 return null;
8422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008425 }
8426
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008427 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008428 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008429 if (uid == Process.ROOT_UID && packageName == null) {
8430 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8431 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8432 // exception. ROOT_UID seems not to have a valid package name returned by
8433 // PackageManager, so just fake it here to avoid issues when running telephony shell
8434 // commands that plumb through the RIL as root, like so:
8435 // $ adb root
8436 // $ adb shell cmd phone ...
8437 packageName = "root";
8438 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008439 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008440 }
Jack Yueb4124c2017-02-16 15:32:43 -08008441
8442 /**
Grace Chen70990072017-03-24 17:21:30 -07008443 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008444 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008445 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008446 * @param state State of SIM (power down, power up, pass through)
8447 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8448 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8449 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008450 *
8451 **/
8452 @Override
Grace Chen70990072017-03-24 17:21:30 -07008453 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008454 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008455 Phone phone = PhoneFactory.getPhone(slotIndex);
8456
vagdeviaf9a5b92018-08-15 16:01:53 -07008457 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459 final long identity = Binder.clearCallingIdentity();
8460 try {
8461 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008462 phone.setSimPowerState(state, null, workSource);
8463 }
8464 } finally {
8465 Binder.restoreCallingIdentity(identity);
8466 }
8467 }
8468
8469 /**
8470 * Set SIM card power state.
8471 *
8472 * @param slotIndex SIM slot id.
8473 * @param state State of SIM (power down, power up, pass through)
8474 * @param callback callback to trigger after success or failure
8475 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8476 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8477 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8478 *
8479 **/
8480 @Override
8481 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8482 IIntegerConsumer callback) {
8483 enforceModifyPermission();
8484 Phone phone = PhoneFactory.getPhone(slotIndex);
8485
8486 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8487
8488 final long identity = Binder.clearCallingIdentity();
8489 try {
8490 if (phone != null) {
8491 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8492 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493 }
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008496 }
8497 }
Shuo Qiandd210312017-04-12 22:11:33 +00008498
Tyler Gunn65d45c22017-06-05 11:22:26 -07008499 private boolean isUssdApiAllowed(int subId) {
8500 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008501 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008502 if (configManager == null) {
8503 return false;
8504 }
8505 PersistableBundle pb = configManager.getConfigForSubId(subId);
8506 if (pb == null) {
8507 return false;
8508 }
8509 return pb.getBoolean(
8510 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8511 }
8512
Shuo Qiandd210312017-04-12 22:11:33 +00008513 /**
8514 * Check if phone is in emergency callback mode
8515 * @return true if phone is in emergency callback mode
8516 * @param subId sub id
8517 */
goneil9c5f4872017-12-05 14:07:56 -08008518 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008519 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008520 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008521 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008522
8523 final long identity = Binder.clearCallingIdentity();
8524 try {
8525 if (phone != null) {
8526 return phone.isInEcm();
8527 } else {
8528 return false;
8529 }
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008532 }
8533 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008534
8535 /**
8536 * Get the current signal strength information for the given subscription.
8537 * Because this information is not updated when the device is in a low power state
8538 * it should not be relied-upon to be current.
8539 * @param subId Subscription index
8540 * @return the most recent cached signal strength info from the modem
8541 */
8542 @Override
8543 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 Phone p = getPhone(subId);
8547 if (p == null) {
8548 return null;
8549 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008551 return p.getSignalStrength();
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008555 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008556
Pengquan Meng77b7f132018-08-22 14:49:57 -07008557 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008558 * Get the current modem radio state for the given slot.
8559 * @param slotIndex slot index.
8560 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008561 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008562 * @return the current radio power state from the modem
8563 */
8564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008565 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008566 Phone phone = PhoneFactory.getPhone(slotIndex);
8567 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8569 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008570 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8571 }
8572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 return phone.getRadioPowerState();
8576 } finally {
8577 Binder.restoreCallingIdentity(identity);
8578 }
8579 }
8580 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8581 }
8582
8583 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008584 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8585 *
8586 * <p>Requires one of the following permissions:
8587 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008588 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008589 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8590 * privileges.
8591 *
8592 * @param subId subscription id
8593 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8594 * {@code false}.
8595 */
8596 @Override
8597 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008598 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008599 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008600 try {
8601 mApp.enforceCallingOrSelfPermission(
8602 android.Manifest.permission.ACCESS_NETWORK_STATE,
8603 functionName);
8604 } catch (Exception e) {
8605 mApp.enforceCallingOrSelfPermission(
8606 permission.READ_BASIC_PHONE_STATE, functionName);
8607 }
Shuo Qian093013d2020-08-13 15:42:55 -07008608 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008609 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008610 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008611 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008612
Pengquan Menga1bb6272018-09-06 09:59:22 -07008613 boolean isEnabled = false;
8614 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008615 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008616 Phone phone = getPhone(subId);
8617 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008618 } finally {
8619 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008620 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008621 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008622 }
8623
8624
8625 /**
8626 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8627 *
8628 * <p> Requires permission:
8629 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8630 * privileges.
8631 *
8632 * @param subId subscription id
8633 * @param isEnabled {@code true} means enable, {@code false} means disable.
8634 */
8635 @Override
8636 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8638 mApp, subId, "setDataRoamingEnabled");
8639
Pengquan Menga1bb6272018-09-06 09:59:22 -07008640 final long identity = Binder.clearCallingIdentity();
8641 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008642 Phone phone = getPhone(subId);
8643 if (phone != null) {
8644 phone.setDataRoamingEnabled(isEnabled);
8645 }
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008648 }
8649 }
8650
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008651 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008652 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008653 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008654 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008655 mApp, subId, "isManualNetworkSelectionAllowed");
8656
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008657 boolean isAllowed = true;
8658 final long identity = Binder.clearCallingIdentity();
8659 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008660 Phone phone = getPhone(subId);
8661 if (phone != null) {
8662 isAllowed = phone.isCspPlmnEnabled();
8663 }
8664 } finally {
8665 Binder.restoreCallingIdentity(identity);
8666 }
8667 return isAllowed;
8668 }
8669
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008670 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8671 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008672 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008673 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008674 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008675 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8676 if (phone == null) {
8677 return false;
8678 }
8679 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8680 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8681 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008682 }
8683
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008684 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008685 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008686 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008687 mApp.getSystemService(AppOpsManager.class)
8688 .checkPackage(Binder.getCallingUid(), callingPackage);
8689
Jordan Liu1e142fc2019-04-22 15:10:43 -07008690 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008691 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008692 try {
8693 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008694 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008695 } catch (SecurityException e) {
8696 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8697 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008698 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008699 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008700 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008701 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008702 }
sandeepjsb6c87872021-09-27 15:34:44 +00008703 // checking compatibility, if calling app's target SDK is T and beyond.
8704 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8705 Binder.getCallingUid())) {
8706 isIccIdAccessRestricted = true;
8707 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008708 final long identity = Binder.clearCallingIdentity();
8709 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008710 UiccController uiccController = UiccController.getInstance();
8711 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008712 if (hasReadPermission) {
8713 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008714 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008715
8716 // Remove private info if the caller doesn't have access
8717 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8718 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008719 //setting the value after compatibility check
8720 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008721 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8722 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008723 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008724 if (card == null) {
8725 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008726 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008727 continue;
8728 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008729 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8730 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008731 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008732 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008733 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008734 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8735 for (UiccPortInfo portInfo : portInfos) {
8736 UiccPort port = uiccController.getUiccPortForSlot(
8737 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8738 if (port == null) {
8739 // assume no access if port is null
8740 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8741 continue;
8742 }
8743 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8744 uiccPortInfos.add(portInfo);
8745 } else {
8746 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8747 }
8748 }
8749 filteredInfos.add(new UiccCardInfo(
8750 cardInfo.isEuicc(),
8751 cardInfo.getCardId(),
8752 null,
8753 cardInfo.getPhysicalSlotIndex(),
8754 cardInfo.isRemovable(),
8755 cardInfo.isMultipleEnabledProfilesSupported(),
8756 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008757 }
8758 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
8762 }
8763
sandeepjsb6c87872021-09-27 15:34:44 +00008764 /**
8765 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8766 * generally private and require carrier privileges to view.
8767 *
8768 * @hide
8769 */
8770 @NonNull
8771 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8772 List<UiccPortInfo> portinfo = new ArrayList<>();
8773 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8774 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8775 }
8776 return new UiccCardInfo(
8777 cardInfo.isEuicc(),
8778 cardInfo.getCardId(),
8779 null,
8780 cardInfo.getPhysicalSlotIndex(),
8781 cardInfo.isRemovable(),
8782 cardInfo.isMultipleEnabledProfilesSupported(),
8783 portinfo
8784 );
8785 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008786
sandeepjsb6c87872021-09-27 15:34:44 +00008787 /**
8788 * @hide
8789 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8790 * These values are generally private and require carrier privileges to view.
8791 */
8792 @NonNull
8793 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8794 return new UiccPortInfo(
8795 UiccPortInfo.ICCID_REDACTED,
8796 portInfo.getPortIndex(),
8797 portInfo.getLogicalSlotIndex(),
8798 portInfo.isActive()
8799 );
8800 }
8801 @Override
8802 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008803 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008804 mApp.getSystemService(AppOpsManager.class)
8805 .checkPackage(Binder.getCallingUid(), callingPackage);
8806
sandeepjsb6c87872021-09-27 15:34:44 +00008807 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008808
Aman Guptaf3c90b32022-03-17 04:54:16 +00008809 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8810 // we are reading iccId which is PII data.
8811 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008812
8813 // checking compatibility, if calling app's target SDK is T and beyond.
8814 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8815 Binder.getCallingUid())) {
8816 isLogicalSlotAccessRestricted = true;
8817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008818 final long identity = Binder.clearCallingIdentity();
8819 try {
8820 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008821 if (slots == null || slots.length == 0) {
8822 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008823 return null;
8824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008825 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8826 for (int i = 0; i < slots.length; i++) {
8827 UiccSlot slot = slots[i];
8828 if (slot == null) {
8829 continue;
8830 }
8831
Jordan Liu7be7e652019-05-06 18:55:02 +00008832 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008833 UiccCard card = slot.getUiccCard();
8834 if (card != null) {
8835 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008836 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008837 cardId = slot.getEid();
8838 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008839 // If cardId is null, use iccId of default port as cardId.
8840 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008842 }
8843
Jordan Liu857451f2019-05-09 16:35:35 -07008844 if (cardId != null) {
8845 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8846 // if cardId is an EID, it's all digits so this is fine
8847 cardId = IccUtils.stripTrailingFs(cardId);
8848 }
8849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008850 int cardState = 0;
8851 switch (slot.getCardState()) {
8852 case CARDSTATE_ABSENT:
8853 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8854 break;
8855 case CARDSTATE_PRESENT:
8856 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8857 break;
8858 case CARDSTATE_ERROR:
8859 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8860 break;
8861 case CARDSTATE_RESTRICTED:
8862 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8863 break;
8864 default:
8865 break;
8866
8867 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008868 List<UiccPortInfo> portInfos = new ArrayList<>();
8869 int[] portIndexes = slot.getPortList();
8870 for (int portIdx : portIndexes) {
8871 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008872 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008873 portInfos.add(new UiccPortInfo(iccId, portIdx,
8874 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008876 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877 slot.isEuicc(),
8878 cardId,
8879 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008880 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008881 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008882 //setting the value after compatibility check
8883 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 }
8885 return infos;
8886 } finally {
8887 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008888 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008889 }
8890
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008891 /* Returns null if doesn't have read permission or carrier privilege access. */
8892 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8893 boolean hasReadPermission) {
8894 String iccId = slot.getIccId(portIndex);
8895 if (hasReadPermission) { // if has read permission
8896 return iccId;
8897 } else {
8898 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8899 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8900 // if no read permission, checking carrier privilege access
8901 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8902 return iccId;
8903 }
8904 }
8905 }
8906 // No read permission or carrier privilege access.
8907 return UiccPortInfo.ICCID_REDACTED;
8908 }
8909
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008910 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008911 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008912 public boolean switchSlots(int[] physicalSlots) {
8913 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008914
8915 final long identity = Binder.clearCallingIdentity();
8916 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008917 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8918 for (int i = 0; i < physicalSlots.length; i++) {
8919 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8920 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8921 physicalSlots[i], i));
8922 }
8923 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008924 } finally {
8925 Binder.restoreCallingIdentity(identity);
8926 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008927 }
Jack Yu4c988042018-02-27 15:30:01 -08008928
8929 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008930 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8931 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8932 enforceModifyPermission();
8933
8934 final long identity = Binder.clearCallingIdentity();
8935 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008936 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00008937 } finally {
8938 Binder.restoreCallingIdentity(identity);
8939 }
8940 }
8941
8942 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008943 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008944 final long identity = Binder.clearCallingIdentity();
8945 try {
8946 return UiccController.getInstance().getCardIdForDefaultEuicc();
8947 } finally {
8948 Binder.restoreCallingIdentity(identity);
8949 }
8950 }
8951
Pengquan Meng85728fb2018-03-12 16:31:21 -07008952 /**
goneil47ffb6e2018-04-06 15:40:58 -07008953 * A test API to reload the UICC profile.
8954 *
8955 * <p>Requires that the calling app has permission
8956 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8957 * @hide
8958 */
8959 @Override
8960 public void refreshUiccProfile(int subId) {
8961 enforceModifyPermission();
8962
8963 final long identity = Binder.clearCallingIdentity();
8964 try {
8965 Phone phone = getPhone(subId);
8966 if (phone == null) {
8967 return;
8968 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008969 UiccPort uiccPort = phone.getUiccPort();
8970 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008971 return;
8972 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008973 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008974 if (uiccProfile == null) {
8975 return;
8976 }
8977 uiccProfile.refresh();
8978 } finally {
8979 Binder.restoreCallingIdentity(identity);
8980 }
8981 }
8982
8983 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008984 * Returns false if the mobile data is disabled by default, otherwise return true.
8985 */
8986 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008987 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008988 }
8989
8990 /**
8991 * Returns true if the data roaming is enabled by default, i.e the system property
8992 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8993 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8994 */
8995 private boolean getDefaultDataRoamingEnabled(int subId) {
8996 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008997 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008998 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008999 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9000 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9001 return isDataRoamingEnabled;
9002 }
9003
9004 /**
9005 * Returns the default network type for the given {@code subId}, if the default network type is
9006 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9007 */
9008 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009009 List<Integer> list = TelephonyProperties.default_network();
9010 int phoneId = mSubscriptionController.getPhoneId(subId);
9011 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9012 return list.get(phoneId);
9013 }
9014 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009015 }
fionaxua13278b2018-03-21 00:08:13 -07009016
9017 @Override
9018 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009019 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009021
9022 final long identity = Binder.clearCallingIdentity();
9023 try {
9024 final Phone phone = getPhone(subId);
9025 if (phone == null) {
9026 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9027 return;
9028 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009029 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9030 if (cpt != null) {
9031 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9032 }
9033 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009034 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9035 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009036 if (carrierPrivilegeRules == null) {
9037 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9038 } else {
9039 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 } finally {
9042 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009043 }
fionaxua13278b2018-03-21 00:08:13 -07009044 }
9045
9046 @Override
9047 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009048 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049
9050 final long identity = Binder.clearCallingIdentity();
9051 try {
9052 final Phone phone = getPhone(subId);
9053 if (phone == null) {
9054 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9055 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9056 }
9057 return phone.getCarrierIdListVersion();
9058 } finally {
9059 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009060 }
fionaxua13278b2018-03-21 00:08:13 -07009061 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009062
9063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009064 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9065 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009067 mApp, subId, callingPackage, callingFeatureId,
9068 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009069 return -1;
9070 }
9071
9072 final long identity = Binder.clearCallingIdentity();
9073 try {
9074 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9075 } finally {
9076 Binder.restoreCallingIdentity(identity);
9077 }
9078 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009079
9080 @Override
9081 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009082 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009083 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009084 mApp, subId, "getCdmaRoamingMode");
9085
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
9088 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
9092 }
9093
9094 @Override
9095 public boolean setCdmaRoamingMode(int subId, int mode) {
9096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9097 mApp, subId, "setCdmaRoamingMode");
9098
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
9101 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9102 } finally {
9103 Binder.restoreCallingIdentity(identity);
9104 }
9105 }
9106
9107 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009108 public int getCdmaSubscriptionMode(int subId) {
9109 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009110 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009111 mApp, subId, "getCdmaSubscriptionMode");
9112
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
9115 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9116 } finally {
9117 Binder.restoreCallingIdentity(identity);
9118 }
9119 }
9120
9121 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009122 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9124 mApp, subId, "setCdmaSubscriptionMode");
9125
9126 final long identity = Binder.clearCallingIdentity();
9127 try {
9128 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9129 } finally {
9130 Binder.restoreCallingIdentity(identity);
9131 }
9132 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009133
sqianc5eccab2018-10-19 18:46:41 -07009134 @Override
sqian8c685422019-02-22 15:55:18 -08009135 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009136 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009138 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9139 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009140 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9141 }
9142 final long identity = Binder.clearCallingIdentity();
9143 try {
sqian854d44b2018-12-12 16:48:18 -08009144 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9145 for (Phone phone: PhoneFactory.getPhones()) {
9146 if (phone.getEmergencyNumberTracker() != null
9147 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9148 emergencyNumberListInternal.put(
9149 phone.getSubId(),
9150 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9151 }
sqian11b7a0e2018-12-05 18:48:28 -08009152 }
sqian854d44b2018-12-12 16:48:18 -08009153 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009154 } finally {
9155 Binder.restoreCallingIdentity(identity);
9156 }
sqianc5eccab2018-10-19 18:46:41 -07009157 }
9158
9159 @Override
sqian8c685422019-02-22 15:55:18 -08009160 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009161 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009162 if (!exactMatch) {
9163 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009164 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009165 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009166 }
9167 final long identity = Binder.clearCallingIdentity();
9168 try {
sqian854d44b2018-12-12 16:48:18 -08009169 for (Phone phone: PhoneFactory.getPhones()) {
9170 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009171 && phone.getEmergencyNumberTracker()
9172 .isEmergencyNumber(number, exactMatch)) {
9173 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009174 }
sqian11b7a0e2018-12-05 18:48:28 -08009175 }
9176 return false;
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 }
9181
sqianf4ca7ed2019-01-15 18:32:07 -08009182 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009183 * Start emergency callback mode for GsmCdmaPhone for testing.
9184 */
9185 @Override
9186 public void startEmergencyCallbackMode() {
9187 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9188 "startEmergencyCallbackMode");
9189 enforceModifyPermission();
9190 final long identity = Binder.clearCallingIdentity();
9191 try {
9192 for (Phone phone : PhoneFactory.getPhones()) {
9193 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9194 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9195 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9196 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9197 gsmCdmaPhone.obtainMessage(
9198 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9199 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9200 }
9201 }
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
9204 }
9205 }
9206
9207 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009208 * Update emergency number list for test mode.
9209 */
9210 @Override
9211 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9212 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9213 "updateEmergencyNumberListTestMode");
9214
9215 final long identity = Binder.clearCallingIdentity();
9216 try {
9217 for (Phone phone: PhoneFactory.getPhones()) {
9218 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9219 if (tracker != null) {
9220 tracker.executeEmergencyNumberTestModeCommand(action, num);
9221 }
9222 }
9223 } finally {
9224 Binder.restoreCallingIdentity(identity);
9225 }
9226 }
9227
9228 /**
9229 * Get the full emergency number list for test mode.
9230 */
9231 @Override
9232 public List<String> getEmergencyNumberListTestMode() {
9233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9234 "getEmergencyNumberListTestMode");
9235
9236 final long identity = Binder.clearCallingIdentity();
9237 try {
9238 Set<String> emergencyNumbers = new HashSet<>();
9239 for (Phone phone: PhoneFactory.getPhones()) {
9240 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9241 if (tracker != null) {
9242 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9243 emergencyNumbers.add(num.getNumber());
9244 }
9245 }
9246 }
9247 return new ArrayList<>(emergencyNumbers);
9248 } finally {
9249 Binder.restoreCallingIdentity(identity);
9250 }
9251 }
9252
chen xud6b45bd2018-10-30 22:27:10 -07009253 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009254 public int getEmergencyNumberDbVersion(int subId) {
9255 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9256
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
9259 final Phone phone = getPhone(subId);
9260 if (phone == null) {
9261 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9262 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9263 }
9264 return phone.getEmergencyNumberDbVersion();
9265 } finally {
9266 Binder.restoreCallingIdentity(identity);
9267 }
9268 }
9269
9270 @Override
9271 public void notifyOtaEmergencyNumberDbInstalled() {
9272 enforceModifyPermission();
9273
9274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 for (Phone phone: PhoneFactory.getPhones()) {
9277 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9278 if (tracker != null) {
9279 tracker.updateOtaEmergencyNumberDatabase();
9280 }
9281 }
9282 } finally {
9283 Binder.restoreCallingIdentity(identity);
9284 }
9285 }
9286
9287 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009288 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009289 enforceActiveEmergencySessionPermission();
9290
9291 final long identity = Binder.clearCallingIdentity();
9292 try {
9293 for (Phone phone: PhoneFactory.getPhones()) {
9294 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9295 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009296 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9297 }
9298 }
9299 } finally {
9300 Binder.restoreCallingIdentity(identity);
9301 }
9302 }
9303
9304 @Override
9305 public void resetOtaEmergencyNumberDbFilePath() {
9306 enforceActiveEmergencySessionPermission();
9307
9308 final long identity = Binder.clearCallingIdentity();
9309 try {
9310 for (Phone phone: PhoneFactory.getPhones()) {
9311 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9312 if (tracker != null) {
9313 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009314 }
9315 }
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
9320
9321 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009322 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9323 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9324 Phone phone = getPhone(subId);
9325 if (phone == null) {
9326 return null;
9327 }
9328 final long identity = Binder.clearCallingIdentity();
9329 try {
9330 UiccProfile profile = UiccController.getInstance()
9331 .getUiccProfileForPhone(phone.getPhoneId());
9332 if (profile != null) {
9333 return profile.getCertsFromCarrierPrivilegeAccessRules();
9334 }
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 return null;
9339 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009340
9341 /**
9342 * Enable or disable a modem stack.
9343 */
9344 @Override
9345 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9346 enforceModifyPermission();
9347
9348 final long identity = Binder.clearCallingIdentity();
9349 try {
9350 Phone phone = PhoneFactory.getPhone(slotIndex);
9351 if (phone == null) {
9352 return false;
9353 } else {
9354 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9355 }
9356 } finally {
9357 Binder.restoreCallingIdentity(identity);
9358 }
9359 }
Michelecea4cf22018-12-21 15:00:11 -08009360
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009361 /**
9362 * Whether a modem stack is enabled or not.
9363 */
9364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009365 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9366 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009367 Phone phone = PhoneFactory.getPhone(slotIndex);
9368 if (phone == null) return false;
9369
9370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009371 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9372 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009373 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9374 }
9375
9376 final long identity = Binder.clearCallingIdentity();
9377 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009378 try {
9379 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9380 } catch (NoSuchElementException ex) {
9381 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9382 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
Michelecea4cf22018-12-21 15:00:11 -08009388 @Override
Michele0ea7d782019-03-19 14:58:42 -07009389 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009390 enforceModifyPermission();
9391
9392 final long identity = Binder.clearCallingIdentity();
9393 try {
9394 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009395 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009396 .commit();
9397 } finally {
9398 Binder.restoreCallingIdentity(identity);
9399 }
9400 }
9401
9402 @Override
Michele0ea7d782019-03-19 14:58:42 -07009403 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009404 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009406 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9407 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009408 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009409 }
Michelecea4cf22018-12-21 15:00:11 -08009410
9411 final long identity = Binder.clearCallingIdentity();
9412 try {
Michele0ea7d782019-03-19 14:58:42 -07009413 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009414 } finally {
9415 Binder.restoreCallingIdentity(identity);
9416 }
9417 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009418
Michele0ea7d782019-03-19 14:58:42 -07009419 @TelephonyManager.IsMultiSimSupportedResult
9420 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009421 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9422 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9423 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009424 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9425 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009426 }
9427 // Check if the hardware supports multisim functionality. If usage of multisim is not
9428 // supported by the modem, indicate that it is restricted.
9429 PhoneCapability staticCapability =
9430 mPhoneConfigurationManager.getStaticPhoneCapability();
9431 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009432 loge("isMultiSimSupportedInternal: no static configuration available");
9433 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009434 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009435 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009436 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9437 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009438 }
9439 // Check if support of multiple SIMs is restricted by carrier
9440 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009441 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009442 }
9443
Michele0ea7d782019-03-19 14:58:42 -07009444 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009445 }
9446
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009447 /**
9448 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009449 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9450 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9451 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009452 * @param numOfSims number of active sims we want to switch to
9453 */
9454 @Override
9455 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009456 if (numOfSims == 1) {
9457 enforceModifyPermission();
9458 } else {
9459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9460 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9461 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009462 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009463
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009464 try {
Michele30b57b22019-03-01 12:01:14 -08009465 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009466 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009467 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9468 return;
9469 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009470 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9471 } finally {
9472 Binder.restoreCallingIdentity(identity);
9473 }
9474 }
9475
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009476 @Override
9477 public boolean isApplicationOnUicc(int subId, int appType) {
9478 enforceReadPrivilegedPermission("isApplicationOnUicc");
9479 Phone phone = getPhone(subId);
9480 if (phone == null) {
9481 return false;
9482 }
9483 final long identity = Binder.clearCallingIdentity();
9484 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009485 UiccPort uiccPort = phone.getUiccPort();
9486 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009487 return false;
9488 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009489 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009490 if (uiccProfile == null) {
9491 return false;
9492 }
9493 if (TelephonyManager.APPTYPE_SIM <= appType
9494 && appType <= TelephonyManager.APPTYPE_ISIM) {
9495 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9496 }
9497 return false;
9498 } finally {
9499 Binder.restoreCallingIdentity(identity);
9500 }
9501 }
9502
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009503 /**
chen xub4baa772019-04-03 10:23:41 -07009504 * Get whether making changes to modem configurations will trigger reboot.
9505 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009506 */
9507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009508 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9509 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009511 mApp, subId, callingPackage, callingFeatureId,
9512 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009513 return false;
9514 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009515 final long identity = Binder.clearCallingIdentity();
9516 try {
9517 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9518 } finally {
9519 Binder.restoreCallingIdentity(identity);
9520 }
9521 }
9522
Nathan Harold29f5f052019-02-15 13:41:57 -08009523 private void updateModemStateMetrics() {
9524 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9525 // TODO: check the state for each modem if the api is ready.
9526 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9527 }
9528
Pengquan Meng3889a572019-01-23 11:16:29 -08009529 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009530 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009531 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009532 // Verify that the callingPackage belongs to the calling UID
9533 mApp.getSystemService(AppOpsManager.class)
9534 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009535 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009536 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009537 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009538 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9539 if (slotInfos != null) {
9540 for (int i = 0; i < slotInfos.length; i++) {
9541 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9542 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9543 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9544 portInfo.getLogicalSlotIndex()));
9545 }
9546 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009547 }
9548 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009549 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009550 } finally {
9551 Binder.restoreCallingIdentity(identity);
9552 }
9553 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009554
9555 /**
9556 * Get the IRadio HAL Version
9557 */
9558 @Override
9559 public int getRadioHalVersion() {
9560 Phone phone = getDefaultPhone();
9561 if (phone == null) return -1;
9562 HalVersion hv = phone.getHalVersion();
9563 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9564 return hv.major * 100 + hv.minor;
9565 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009566
9567 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009568 * Get the current calling package name.
9569 * @return the current calling package name
9570 */
9571 @Override
9572 public String getCurrentPackageName() {
9573 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9574 }
9575
9576 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009577 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9578 * corresponding network requests on a subId.
9579 *
9580 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009581 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009582 * 2) APN is un-metered for this subscription, or
9583 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009584 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009585 *
9586 * @return whether data is allowed for a apn type.
9587 *
9588 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009589 */
9590 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009591 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009592 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9593 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009594
9595 // Now that all security checks passes, perform the operation as ourselves.
9596 final long identity = Binder.clearCallingIdentity();
9597 try {
9598 Phone phone = getPhone(subId);
9599 if (phone == null) return false;
9600
Jack Yu27422a52022-03-21 10:38:05 -07009601 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009602 boolean isDataEnabled;
9603 if (phone.isUsingNewDataStack()) {
Jack Yu27422a52022-03-21 10:38:05 -07009604 isMetered = phone.getDataNetworkController().getDataConfigManager()
9605 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9606 phone.getServiceState().getDataRoaming());
Jack Yu99e87332021-12-17 23:14:15 -08009607 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9608 } else {
Jack Yu27422a52022-03-21 10:38:05 -07009609 isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009610 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9611 }
9612 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009613 } finally {
9614 Binder.restoreCallingIdentity(identity);
9615 }
9616 }
9617
9618 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009619 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009620 enforceReadPrivilegedPermission("isApnMetered");
9621
9622 // Now that all security checks passes, perform the operation as ourselves.
9623 final long identity = Binder.clearCallingIdentity();
9624 try {
9625 Phone phone = getPhone(subId);
9626 if (phone == null) return true; // By default return true.
Jack Yu27422a52022-03-21 10:38:05 -07009627 if (phone.isUsingNewDataStack()) {
9628 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9629 DataUtils.apnTypeToNetworkCapability(apnType),
9630 phone.getServiceState().getDataRoaming());
9631 }
Malcolm Chene5ad5792019-04-18 13:51:02 -07009632
Jack Yu41407ee2019-05-13 16:54:09 -07009633 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009634 } finally {
9635 Binder.restoreCallingIdentity(identity);
9636 }
9637 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009638
9639 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009640 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9641 int subscriptionId, IBooleanConsumer resultCallback) {
9642 enforceModifyPermission();
9643 long token = Binder.clearCallingIdentity();
9644 try {
9645 Phone phone = getPhone(subscriptionId);
9646 if (phone == null) {
9647 try {
9648 if (resultCallback != null) {
9649 resultCallback.accept(false);
9650 }
9651 } catch (RemoteException e) {
9652 // ignore
9653 }
9654 return;
9655 }
9656 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9657 Pair.create(specifiers, (x) -> {
9658 try {
9659 if (resultCallback != null) {
9660 resultCallback.accept(x);
9661 }
9662 } catch (RemoteException e) {
9663 // ignore
9664 }
9665 });
9666 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9667 } finally {
9668 Binder.restoreCallingIdentity(token);
9669 }
9670 }
9671
9672 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009673 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9674 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009675 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009676 mApp, subId, "getSystemSelectionChannels");
9677 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9678 final long identity = Binder.clearCallingIdentity();
9679 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009680 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9681 if (result instanceof IllegalStateException) {
9682 throw (IllegalStateException) result;
9683 }
9684 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009685 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9686 return specifiers;
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
9691
9692 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009693 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009694 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009695 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009696 }
9697
9698 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009699 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9700 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009701 if (callingPackage == null) {
9702 callingPackage = getCurrentPackageName();
9703 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009704 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9705 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009706 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9707 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009708 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9709 }
9710 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9711 Intent intent = new Intent();
9712 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9713 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9714 // Bring up choose default SMS subscription dialog right now
9715 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9716 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9717 mApp.startActivity(intent);
9718 }
chen xud5ca2d52019-05-28 15:20:57 -07009719
9720 @Override
9721 public String getMmsUAProfUrl(int subId) {
9722 //TODO investigate if this API should require proper permission check in R b/133791609
9723 final long identity = Binder.clearCallingIdentity();
9724 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009725 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9726 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9727 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9728 return carrierUAProfUrl;
9729 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009730 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9731 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009732 } finally {
9733 Binder.restoreCallingIdentity(identity);
9734 }
9735 }
9736
9737 @Override
9738 public String getMmsUserAgent(int subId) {
9739 //TODO investigate if this API should require proper permission check in R b/133791609
9740 final long identity = Binder.clearCallingIdentity();
9741 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009742 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9743 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9744 if (!TextUtils.isEmpty(carrierUserAgent)) {
9745 return carrierUserAgent;
9746 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009747 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9748 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009749 } finally {
9750 Binder.restoreCallingIdentity(identity);
9751 }
9752 }
Jack Yub07d4972019-05-28 16:12:25 -07009753
9754 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009755 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9756 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009757
Jack Yub07d4972019-05-28 16:12:25 -07009758 final long identity = Binder.clearCallingIdentity();
9759 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009760 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009761 if (phone == null) return false;
9762
Hall Liua62f5da2020-09-25 10:42:19 -07009763 switch (policy) {
9764 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009765 if (phone.isUsingNewDataStack()) {
9766 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9767 } else {
9768 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9769 }
Hall Liua62f5da2020-09-25 10:42:19 -07009770 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009771 if (phone.isUsingNewDataStack()) {
9772 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9773 } else {
9774 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9775 }
Hall Liua62f5da2020-09-25 10:42:19 -07009776 default:
9777 throw new IllegalArgumentException(policy + " is not a valid policy");
9778 }
Jack Yub07d4972019-05-28 16:12:25 -07009779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
9783
9784 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009785 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009786 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009787 enforceModifyPermission();
9788
changbettyd5c246e2019-12-24 15:40:37 +08009789 final long identity = Binder.clearCallingIdentity();
9790 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009791 Phone phone = getPhone(subscriptionId);
9792 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009793
Hall Liua62f5da2020-09-25 10:42:19 -07009794 switch (policy) {
9795 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009796 if (phone.isUsingNewDataStack()) {
9797 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9798 } else {
9799 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9800 }
Hall Liua62f5da2020-09-25 10:42:19 -07009801 break;
9802 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009803 if (phone.isUsingNewDataStack()) {
9804 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9805 } else {
9806 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9807 }
Hall Liua62f5da2020-09-25 10:42:19 -07009808 break;
9809 default:
9810 throw new IllegalArgumentException(policy + " is not a valid policy");
9811 }
changbettyd5c246e2019-12-24 15:40:37 +08009812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 }
9816
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009817 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009818 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009819 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9820 * otherwise.
9821 */
9822 @Override
9823 public void setCepEnabled(boolean isCepEnabled) {
9824 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9825
9826 final long identity = Binder.clearCallingIdentity();
9827 try {
9828 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9829 for (Phone phone : PhoneFactory.getPhones()) {
9830 Phone defaultPhone = phone.getImsPhone();
9831 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9832 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9833 ImsPhoneCallTracker imsPhoneCallTracker =
9834 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9835 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9836 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9837 + imsPhone.getMsisdn());
9838 }
9839 }
9840 } finally {
9841 Binder.restoreCallingIdentity(identity);
9842 }
9843 }
allenwtsu46dcc572020-01-08 18:24:03 +08009844
9845 /**
9846 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9847 *
9848 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9849 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9850 * before being read.
9851 */
9852 @Override
9853 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9854 isCompressed) {
9855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9856 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9858 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9859 }
9860 if (!isImsAvailableOnDevice()) {
9861 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9862 "IMS not available on device.");
9863 }
9864
9865 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009866 try {
Hui Wang761a6682020-10-31 05:12:53 +00009867 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9868 } finally {
9869 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009870 }
9871 }
zoey chene02881a2019-12-30 16:11:23 +08009872
9873 @Override
9874 public boolean isIccLockEnabled(int subId) {
9875 enforceReadPrivilegedPermission("isIccLockEnabled");
9876
9877 // Now that all security checks passes, perform the operation as ourselves.
9878 final long identity = Binder.clearCallingIdentity();
9879 try {
9880 Phone phone = getPhone(subId);
9881 if (phone != null && phone.getIccCard() != null) {
9882 return phone.getIccCard().getIccLockEnabled();
9883 } else {
9884 return false;
9885 }
9886 } finally {
9887 Binder.restoreCallingIdentity(identity);
9888 }
9889 }
9890
9891 /**
9892 * Set the ICC pin lock enabled or disabled.
9893 *
9894 * @return an integer representing the status of IccLock enabled or disabled in the following
9895 * three cases:
9896 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9897 * successfully.
9898 * - Positive number and zero for remaining password attempts.
9899 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9900 *
9901 */
9902 @Override
9903 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9904 enforceModifyPermission();
9905
9906 Phone phone = getPhone(subId);
9907 if (phone == null) {
9908 return 0;
9909 }
9910 // Now that all security checks passes, perform the operation as ourselves.
9911 final long identity = Binder.clearCallingIdentity();
9912 try {
9913 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9914 new Pair<Boolean, String>(enabled, password), phone, null);
9915 return attemptsRemaining;
9916
9917 } catch (Exception e) {
9918 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9919 } finally {
9920 Binder.restoreCallingIdentity(identity);
9921 }
9922 return 0;
9923 }
9924
9925 /**
9926 * Change the ICC password used in ICC pin lock.
9927 *
9928 * @return an integer representing the status of IccLock changed in the following three cases:
9929 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9930 * - Positive number and zero for remaining password attempts.
9931 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9932 *
9933 */
9934 @Override
9935 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9936 enforceModifyPermission();
9937
9938 Phone phone = getPhone(subId);
9939 if (phone == null) {
9940 return 0;
9941 }
9942 // Now that all security checks passes, perform the operation as ourselves.
9943 final long identity = Binder.clearCallingIdentity();
9944 try {
9945 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9946 new Pair<String, String>(oldPassword, newPassword), phone, null);
9947 return attemptsRemaining;
9948
9949 } catch (Exception e) {
9950 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9951 } finally {
9952 Binder.restoreCallingIdentity(identity);
9953 }
9954 return 0;
9955 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009956
9957 /**
9958 * Request for receiving user activity notification
9959 */
9960 @Override
9961 public void requestUserActivityNotification() {
9962 if (!mNotifyUserActivity.get()
9963 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9964 mNotifyUserActivity.set(true);
9965 }
9966 }
9967
9968 /**
9969 * Called when userActivity is signalled in the power manager.
9970 * This is safe to call from any thread, with any window manager locks held or not.
9971 */
9972 @Override
9973 public void userActivity() {
9974 // ***************************************
9975 // * Inherited from PhoneWindowManager *
9976 // ***************************************
9977 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9978 // WITH ITS LOCKS HELD.
9979 //
9980 // This code must be VERY careful about the locks
9981 // it acquires.
9982 // In fact, the current code acquires way too many,
9983 // and probably has lurking deadlocks.
9984
9985 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9986 throw new SecurityException("Only the OS may call notifyUserActivity()");
9987 }
9988
9989 if (mNotifyUserActivity.getAndSet(false)) {
9990 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9991 USER_ACTIVITY_NOTIFICATION_DELAY);
9992 }
9993 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009994
9995 @Override
9996 public boolean canConnectTo5GInDsdsMode() {
9997 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9998 }
Jack Yud10cdd42020-09-28 20:28:01 -07009999
10000 @Override
10001 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10002 String callingFeatureId) {
10003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10004 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10005 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10006 }
10007
10008 Phone phone = getPhone(subId);
10009 if (phone == null) {
10010 throw new RuntimeException("phone is not available");
10011 }
10012 // Now that all security checks passes, perform the operation as ourselves.
10013 final long identity = Binder.clearCallingIdentity();
10014 try {
10015 return phone.getEquivalentHomePlmns();
10016 } finally {
10017 Binder.restoreCallingIdentity(identity);
10018 }
10019 }
Daniel Bright59e67312020-11-13 11:49:37 -080010020
10021 @Override
10022 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010023 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10024 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010025 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010026 if (radioInterfaceCapabilities == null) {
10027 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010028 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010029 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010030 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010031
Hui Wang641e81c2020-10-12 12:14:23 -070010032 @Override
10033 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10034 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010035 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10036 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10037 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10038 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10039 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010040 if (DBG) {
10041 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10042 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10043 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10044 }
10045
10046 if (!SubscriptionManager.isValidSubscriptionId(subId)
10047 || appType < TelephonyManager.APPTYPE_UNKNOWN
10048 || appType > TelephonyManager.APPTYPE_ISIM
10049 || nafUrl == null || securityProtocol == null || callback == null) {
10050 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10051 if (callback != null) {
10052 try {
10053 callback.onAuthenticationFailure(
10054 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10055 } catch (RemoteException exception) {
10056 log("Fail to notify onAuthenticationFailure due to " + exception);
10057 }
10058 return;
10059 }
10060 }
10061
10062 final long token = Binder.clearCallingIdentity();
10063 try {
10064 getGbaManager(subId).bootstrapAuthenticationRequest(
10065 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10066 forceBootStrapping, callback));
10067 } finally {
10068 Binder.restoreCallingIdentity(token);
10069 }
10070 }
10071
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010072 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010073 * Attempts to set the radio power state for all phones for thermal reason.
10074 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010075 * requested radio power state will actually be set. See {@link
10076 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10077 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010078 * @param enable {@code true} if trying to turn radio on.
10079 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10080 * false}.
10081 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010082 private boolean setRadioPowerForThermal(boolean enable) {
10083 boolean isPhoneAvailable = false;
10084 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10085 Phone phone = PhoneFactory.getPhone(i);
10086 if (phone != null) {
10087 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10088 isPhoneAvailable = true;
10089 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010090 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010091
10092 // return true if successfully informed the phone object about the thermal radio power
10093 // request.
10094 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010095 }
10096
10097 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010098 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010099 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10100 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10101 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10102 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10103 throw new IllegalArgumentException("modem does not support data throttling");
10104 }
10105
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010106 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10107 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010108 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010109 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10110 }
10111
Sarah Chinecc78c42022-03-31 21:16:48 -070010112 setDataEnabledForReason(
10113 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010115 if (isDataThrottlingSupported) {
10116 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010117 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010118 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10119 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10120 } else if (thermalMitigationResult
10121 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010122 log("Modem likely does not support data throttling on secondary carrier. Data " +
10123 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10124 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010125 }
10126 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010127 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010128
10129 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010130 }
10131
Jack Nudelman644b91a2021-03-12 14:09:48 -080010132 private static List<String> getThermalMitigationAllowlist(Context context) {
10133 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10134 for (String pckg : context.getResources()
10135 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10136 sThermalMitigationAllowlistedPackages.add(pckg);
10137 }
10138 }
10139
10140 return sThermalMitigationAllowlistedPackages;
10141 }
10142
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010143 private boolean isAnyPhoneInEmergencyState() {
10144 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10145 if (tm.isInEmergencyCall()) {
10146 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10147 return true;
10148 }
10149 for (Phone phone : PhoneFactory.getPhones()) {
10150 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10151 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10152 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10153 + phone.isInEcm());
10154 return true;
10155 }
10156 }
10157
10158 return false;
10159 }
10160
Jack Nudelman644b91a2021-03-12 14:09:48 -080010161 /**
10162 * Used by shell commands to add an authorized package name for thermal mitigation.
10163 * @param packageName name of package to be allowlisted
10164 * @param context
10165 */
10166 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10167 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10168 sThermalMitigationAllowlistedPackages.add(packageName);
10169 }
10170
10171 /**
10172 * Used by shell commands to remove an authorized package name for thermal mitigation.
10173 * @param packageName name of package to remove from allowlist
10174 * @param context
10175 */
10176 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10177 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10178 sThermalMitigationAllowlistedPackages.remove(packageName);
10179 }
10180
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010181 /**
10182 * Thermal mitigation request to control functionalities at modem.
10183 *
10184 * @param subId the id of the subscription.
10185 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010186 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010187 *
10188 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10189 */
10190 @Override
10191 @ThermalMitigationResult
10192 public int sendThermalMitigationRequest(
10193 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010194 ThermalMitigationRequest thermalMitigationRequest,
10195 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010196 enforceModifyPermission();
10197
Jack Nudelman644b91a2021-03-12 14:09:48 -080010198 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10199 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10200 .contains(callingPackage)) {
10201 throw new SecurityException("Calling package must be configured in the device config. "
10202 + "calling package: " + callingPackage);
10203 }
10204
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010205 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10206 final long identity = Binder.clearCallingIdentity();
10207
10208 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10209 try {
10210 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10211 switch (thermalMitigationAction) {
10212 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10213 thermalMitigationResult =
10214 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010215 thermalMitigationRequest.getDataThrottlingRequest(),
10216 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010217 break;
10218 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10219 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10220 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10221 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10222 }
10223
10224 // Ensure that radio is on. If not able to power on due to phone being
10225 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010226 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010227 thermalMitigationResult =
10228 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10229 break;
10230 }
10231
10232 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010233 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010234 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10235 break;
10236 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10237 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10238 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10239 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10240 }
10241
10242 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10243 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010244 Phone phone = getPhone(subId);
10245 if (phone == null) {
10246 thermalMitigationResult =
10247 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10248 break;
10249 }
10250
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010251 TelephonyConnectionService service =
10252 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010253 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010254 Log.e(LOG_TAG, "An emergency call is pending");
10255 thermalMitigationResult =
10256 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10257 break;
10258 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010259 thermalMitigationResult =
10260 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10261 break;
10262 }
10263 } else {
10264 thermalMitigationResult =
10265 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10266 break;
10267 }
10268
10269 // Turn radio off. If not able to power off due to phone being unavailable,
10270 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010271 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010272 thermalMitigationResult =
10273 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10274 break;
10275 }
10276 thermalMitigationResult =
10277 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10278 break;
10279 default:
10280 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10281 + "not exist. Requested action: " + thermalMitigationAction);
10282 }
10283 } catch (IllegalArgumentException e) {
10284 throw e;
10285 } catch (Exception e) {
10286 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10287 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10288 } finally {
10289 Binder.restoreCallingIdentity(identity);
10290 }
10291
10292 if (DBG) {
10293 log("thermalMitigationRequest returning with thermalMitigationResult: "
10294 + thermalMitigationResult);
10295 }
10296
10297 return thermalMitigationResult;
10298 }
Hui Wang641e81c2020-10-12 12:14:23 -070010299
10300 /**
10301 * Set the GbaService Package Name that Telephony will bind to.
10302 *
10303 * @param subId The sim that the GbaService is associated with.
10304 * @param packageName The name of the package to be replaced with.
10305 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10306 */
10307 @Override
10308 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10309 enforceModifyPermission();
10310
10311 final long identity = Binder.clearCallingIdentity();
10312 try {
10313 return getGbaManager(subId).overrideServicePackage(packageName);
10314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
10318
10319 /**
10320 * Return the package name of the currently bound GbaService.
10321 *
10322 * @param subId The sim that the GbaService is associated with.
10323 * @return the package name of the GbaService configuration, null if GBA is not supported.
10324 */
10325 @Override
10326 public String getBoundGbaService(int subId) {
10327 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10328
10329 final long identity = Binder.clearCallingIdentity();
10330 try {
10331 return getGbaManager(subId).getServicePackage();
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
10336
10337 /**
10338 * Set the release time for telephony to unbind GbaService.
10339 *
10340 * @param subId The sim that the GbaService is associated with.
10341 * @param interval The release time to unbind GbaService by millisecond.
10342 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10343 */
10344 @Override
10345 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10346 enforceModifyPermission();
10347
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 return getGbaManager(subId).overrideReleaseTime(interval);
10351 } finally {
10352 Binder.restoreCallingIdentity(identity);
10353 }
10354 }
10355
10356 /**
10357 * Return the release time for telephony to unbind GbaService.
10358 *
10359 * @param subId The sim that the GbaService is associated with.
10360 * @return The release time to unbind GbaService by millisecond.
10361 */
10362 @Override
10363 public int getGbaReleaseTime(int subId) {
10364 enforceReadPrivilegedPermission("getGbaReleaseTime");
10365
10366 final long identity = Binder.clearCallingIdentity();
10367 try {
10368 return getGbaManager(subId).getReleaseTime();
10369 } finally {
10370 Binder.restoreCallingIdentity(identity);
10371 }
10372 }
10373
10374 private GbaManager getGbaManager(int subId) {
10375 GbaManager instance = GbaManager.getInstance(subId);
10376 if (instance == null) {
10377 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10378 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10379 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10380 }
10381 return instance;
10382 }
Hui Wang761a6682020-10-31 05:12:53 +000010383
10384 /**
10385 * indicate whether the device and the carrier can support
10386 * RCS VoLTE single registration.
10387 */
10388 @Override
10389 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010390 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10391 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10392 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10393 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010394
10395 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10396 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10397 }
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10402 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010403 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10404 if (isCapable != null) {
10405 return isCapable;
10406 }
Hui Wang761a6682020-10-31 05:12:53 +000010407 }
Hui Wang67af90e2021-06-04 16:57:15 -070010408 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10409 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
10415 /**
10416 * Register RCS provisioning callback.
10417 */
10418 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010419 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010420 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010421 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010422 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010423 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10424 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010425
10426 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10427 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10428 }
10429 if (!isImsAvailableOnDevice()) {
10430 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10431 "IMS not available on device.");
10432 }
10433
10434 final long identity = Binder.clearCallingIdentity();
10435 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010436 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010437 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010438 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10439 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010440 }
Hui Wang761a6682020-10-31 05:12:53 +000010441 } finally {
10442 Binder.restoreCallingIdentity(identity);
10443 }
10444 }
10445
10446 /**
10447 * Unregister RCS provisioning callback.
10448 */
10449 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010450 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010451 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010452 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010453 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010454 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10455 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010456
10457 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10458 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10459 }
10460 if (!isImsAvailableOnDevice()) {
10461 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10462 "IMS not available on device.");
10463 }
10464
10465 final long identity = Binder.clearCallingIdentity();
10466 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010467 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010468 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
10473
10474 /**
10475 * trigger RCS reconfiguration.
10476 */
10477 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010478 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10479 "triggerRcsReconfiguration",
10480 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010481
10482 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10483 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10484 }
10485 if (!isImsAvailableOnDevice()) {
10486 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10487 "IMS not available on device.");
10488 }
10489
10490 final long identity = Binder.clearCallingIdentity();
10491 try {
10492 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
10497
10498 /**
10499 * Provide the client configuration parameters of the RCS application.
10500 */
10501 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010502 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10503 "setRcsClientConfiguration",
10504 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010505
10506 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10507 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10508 }
10509 if (!isImsAvailableOnDevice()) {
10510 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10511 "IMS not available on device.");
10512 }
10513
10514 final long identity = Binder.clearCallingIdentity();
10515
10516 try {
10517 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10518 if (configBinder == null) {
10519 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010520 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10521 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010522 } else {
10523 configBinder.setRcsClientConfiguration(rcc);
10524 }
joonhunshin3e154242021-09-17 06:33:39 +000010525
10526 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10527 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010528 } catch (RemoteException e) {
10529 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010530 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10531 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
10537 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010538 * Enables or disables the test mode for RCS VoLTE single registration.
10539 */
10540 @Override
10541 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10543 "setRcsSingleRegistrationTestModeEnabled");
10544
10545 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10546 }
10547
10548 /**
10549 * Gets the test mode for RCS VoLTE single registration.
10550 */
10551 @Override
10552 public boolean getRcsSingleRegistrationTestModeEnabled() {
10553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10554 "getRcsSingleRegistrationTestModeEnabled");
10555
10556 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10557 }
10558
10559 /**
Hui Wang761a6682020-10-31 05:12:53 +000010560 * Overrides the config of RCS VoLTE single registration enabled for the device.
10561 */
10562 @Override
10563 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10565 "setDeviceSingleRegistrationEnabledOverride");
10566 enforceModifyPermission();
10567
10568 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10569 : Boolean.parseBoolean(enabledStr);
10570 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010571 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010572 }
10573
10574 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010575 * Sends a device to device communication message. Only usable via shell.
10576 * @param message message to send.
10577 * @param value message value.
10578 */
10579 @Override
10580 public void sendDeviceToDeviceMessage(int message, int value) {
10581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010582 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010583 enforceModifyPermission();
10584
10585 final long identity = Binder.clearCallingIdentity();
10586 try {
10587 TelephonyConnectionService service =
10588 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10589 if (service == null) {
10590 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10591 return;
10592 }
10593 service.sendTestDeviceToDeviceMessage(message, value);
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
Tyler Gunnbabbda02021-02-10 11:05:02 -080010599 /**
10600 * Sets the specified device to device transport active.
10601 * @param transport The transport to set active.
10602 */
10603 @Override
10604 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10606 "setActiveDeviceToDeviceTransport");
10607 enforceModifyPermission();
10608
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 TelephonyConnectionService service =
10612 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10613 if (service == null) {
10614 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10615 return;
10616 }
10617 service.setActiveDeviceToDeviceTransport(transport);
10618 } finally {
10619 Binder.restoreCallingIdentity(identity);
10620 }
10621 }
Tyler Gunn92479152021-01-20 16:30:10 -080010622
Tyler Gunnd4339262021-05-03 14:46:49 -070010623 @Override
10624 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10626 "setDeviceToDeviceForceEnabled");
10627
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 Arrays.stream(PhoneFactory.getPhones()).forEach(
10631 p -> {
10632 Phone thePhone = p.getImsPhone();
10633 if (thePhone != null && thePhone instanceof ImsPhone) {
10634 ImsPhone imsPhone = (ImsPhone) thePhone;
10635 CallTracker tracker = imsPhone.getCallTracker();
10636 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10637 ImsPhoneCallTracker imsPhoneCallTracker =
10638 (ImsPhoneCallTracker) tracker;
10639 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10640 }
10641 }
10642 }
10643 );
10644 } finally {
10645 Binder.restoreCallingIdentity(identity);
10646 }
10647 }
10648
Tyler Gunn92479152021-01-20 16:30:10 -080010649 /**
Hui Wang761a6682020-10-31 05:12:53 +000010650 * Gets the config of RCS VoLTE single registration enabled for the device.
10651 */
10652 @Override
10653 public boolean getDeviceSingleRegistrationEnabled() {
10654 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10655 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10656 }
10657
10658 /**
10659 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10660 */
10661 @Override
10662 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10664 "setCarrierSingleRegistrationEnabledOverride");
10665 enforceModifyPermission();
10666
10667 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10668 : Boolean.parseBoolean(enabledStr);
10669 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10670 subId, enabled);
10671 }
10672
10673 /**
10674 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10675 */
10676 @Override
10677 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10678 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10679 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10680 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010681
10682 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010683 * Overrides the ims feature validation result
10684 */
10685 @Override
10686 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10688 "setImsFeatureValidationOverride");
10689
10690 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10691 : Boolean.parseBoolean(enabledStr);
10692 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10693 subId, enabled);
10694 }
10695
10696 /**
10697 * Gets the ims feature validation override value
10698 */
10699 @Override
10700 public boolean getImsFeatureValidationOverride(int subId) {
10701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10702 "getImsFeatureValidationOverride");
10703 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10704 }
10705
10706 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010707 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10708 * their mobile plan.
10709 */
10710 @Override
10711 public String getMobileProvisioningUrl() {
10712 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10713 final long identity = Binder.clearCallingIdentity();
10714 try {
10715 return getDefaultPhone().getMobileProvisioningUrl();
10716 } finally {
10717 Binder.restoreCallingIdentity(identity);
10718 }
10719 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010720
James.cf Linbcdf8b32021-01-14 16:44:13 +080010721 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010722 * Get the EAB contact from the EAB database.
10723 */
10724 @Override
10725 public String getContactFromEab(String contact) {
10726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10727 enforceModifyPermission();
10728 final long identity = Binder.clearCallingIdentity();
10729 try {
10730 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10731 } finally {
10732 Binder.restoreCallingIdentity(identity);
10733 }
10734 }
10735
10736 /**
Calvin Pana1434322021-07-01 19:27:01 +080010737 * Get the EAB capability from the EAB database.
10738 */
10739 @Override
10740 public String getCapabilityFromEab(String contact) {
10741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10742 enforceModifyPermission();
10743 final long identity = Binder.clearCallingIdentity();
10744 try {
10745 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749 }
10750
10751 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010752 * Remove the EAB contacts from the EAB database.
10753 */
10754 @Override
10755 public int removeContactFromEab(int subId, String contacts) {
10756 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10757 enforceModifyPermission();
10758 final long identity = Binder.clearCallingIdentity();
10759 try {
10760 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10761 } finally {
10762 Binder.restoreCallingIdentity(identity);
10763 }
10764 }
10765
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010766 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010767 public boolean getDeviceUceEnabled() {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 return mApp.getDeviceUceEnabled();
10772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
10776
10777 @Override
10778 public void setDeviceUceEnabled(boolean isEnabled) {
10779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
10782 mApp.setDeviceUceEnabled(isEnabled);
10783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
10787
Brad Ebinger14d467f2021-02-12 06:18:28 +000010788 /**
10789 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10790 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10791 */
10792 // Used for SHELL command only right now.
10793 @Override
10794 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10795 List<String> featureTags) {
10796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10797 "addUceRegistrationOverrideShell");
10798 final long identity = Binder.clearCallingIdentity();
10799 try {
10800 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10801 new ArraySet<>(featureTags));
10802 } catch (ImsException e) {
10803 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
10808
10809 /**
10810 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10811 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10812 */
10813 // Used for SHELL command only right now.
10814 @Override
10815 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10816 List<String> featureTags) {
10817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10818 "removeUceRegistrationOverrideShell");
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10822 new ArraySet<>(featureTags));
10823 } catch (ImsException e) {
10824 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10825 } finally {
10826 Binder.restoreCallingIdentity(identity);
10827 }
10828 }
10829
10830 /**
10831 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10832 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10833 */
10834 // Used for SHELL command only right now.
10835 @Override
10836 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10838 "clearUceRegistrationOverrideShell");
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10842 } catch (ImsException e) {
10843 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10844 } finally {
10845 Binder.restoreCallingIdentity(identity);
10846 }
10847 }
10848
10849 /**
10850 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10851 */
10852 // Used for SHELL command only right now.
10853 @Override
10854 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10856 "getLatestRcsContactUceCapabilityShell");
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10860 } catch (ImsException e) {
10861 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10862 } finally {
10863 Binder.restoreCallingIdentity(identity);
10864 }
10865 }
10866
10867 /**
10868 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10869 * device does not have an active PUBLISH.
10870 */
10871 // Used for SHELL command only right now.
10872 @Override
10873 public String getLastUcePidfXmlShell(int subId) {
10874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10875 final long identity = Binder.clearCallingIdentity();
10876 try {
10877 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10878 } catch (ImsException e) {
10879 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10880 } finally {
10881 Binder.restoreCallingIdentity(identity);
10882 }
10883 }
10884
James.cf Line8713a42021-04-29 16:04:26 +080010885 /**
10886 * Remove UCE requests cannot be sent to the network status.
10887 */
10888 // Used for SHELL command only right now.
10889 @Override
10890 public boolean removeUceRequestDisallowedStatus(int subId) {
10891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10892 final long identity = Binder.clearCallingIdentity();
10893 try {
10894 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10895 } catch (ImsException e) {
10896 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
10901
James.cf Lin18bb9002021-05-25 01:37:38 +080010902 /**
10903 * Remove UCE requests cannot be sent to the network status.
10904 */
10905 // Used for SHELL command only.
10906 @Override
10907 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10912 } catch (ImsException e) {
10913 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010918
James.cf Lin4b784aa2021-01-31 03:25:15 +080010919 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010920 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10921 String callingPackage) {
10922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10923 mApp, subId, "setSignalStrengthUpdateRequest");
10924
10925 final int callingUid = Binder.getCallingUid();
10926 // Verify that tha callingPackage belongs to the calling UID
10927 mApp.getSystemService(AppOpsManager.class)
10928 .checkPackage(callingUid, callingPackage);
10929
Rambo Wang3607f502021-02-01 21:51:40 -080010930 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010931
10932 final long identity = Binder.clearCallingIdentity();
10933 try {
10934 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10935 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10936
10937 if (result instanceof IllegalStateException) {
10938 throw (IllegalStateException) result;
10939 }
10940 } finally {
10941 Binder.restoreCallingIdentity(identity);
10942 }
10943 }
10944
10945 @Override
10946 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10947 String callingPackage) {
10948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10949 mApp, subId, "clearSignalStrengthUpdateRequest");
10950
10951 final int callingUid = Binder.getCallingUid();
10952 // Verify that tha callingPackage belongs to the calling UID
10953 mApp.getSystemService(AppOpsManager.class)
10954 .checkPackage(callingUid, callingPackage);
10955
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
10958 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10959 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10960
10961 if (result instanceof IllegalStateException) {
10962 throw (IllegalStateException) result;
10963 }
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
Rambo Wang3607f502021-02-01 21:51:40 -080010969 private static void validateSignalStrengthUpdateRequest(Context context,
10970 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010971 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10972 // phone/system process do not have further restriction on request
10973 return;
10974 }
10975
10976 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010977 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010978 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010979 context.enforceCallingOrSelfPermission(
10980 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10981 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010982 }
10983
10984 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10985 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10986 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10987 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10988 || info.isEnabled()) {
10989 throw new IllegalArgumentException(
10990 "Only system can set hide fields in SignalThresholdInfo");
10991 }
10992
10993 // Thresholds length for each RAN need in range. This has been validated in
10994 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10995 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10996 final int[] thresholds = info.getThresholds();
10997 Objects.requireNonNull(thresholds);
10998 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10999 || thresholds.length
11000 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11001 throw new IllegalArgumentException(
11002 "thresholds length is out of range: " + thresholds.length);
11003 }
11004 }
11005 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011006
11007 /**
11008 * Gets the current phone capability.
11009 *
11010 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11011 * @return the PhoneCapability which describes the data connection capability of modem.
11012 * It's used to evaluate possible phone config change, for example from single
11013 * SIM device to multi-SIM device.
11014 */
11015 @Override
11016 public PhoneCapability getPhoneCapability() {
11017 enforceReadPrivilegedPermission("getPhoneCapability");
11018 final long identity = Binder.clearCallingIdentity();
11019 try {
11020 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
Michele Berionne5e411512020-11-13 02:36:59 +000011025
11026 /**
11027 * Prepare TelephonyManager for an unattended reboot. The reboot is
11028 * required to be done shortly after the API is invoked.
11029 */
11030 @Override
11031 @TelephonyManager.PrepareUnattendedRebootResult
11032 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011034 enforceRebootPermission();
11035
11036 final long identity = Binder.clearCallingIdentity();
11037 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011038 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011039 } finally {
11040 Binder.restoreCallingIdentity(identity);
11041 }
11042 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011043
11044 /**
11045 * Request to get the current slicing configuration including URSP rules and
11046 * NSSAIs (configured, allowed and rejected).
11047 *
11048 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11049 */
11050 @Override
11051 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011052 TelephonyPermissions
11053 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11054 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011055
11056 final long identity = Binder.clearCallingIdentity();
11057 try {
11058 Phone phone = getDefaultPhone();
11059 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011064
11065 /**
11066 * Register an IMS connection state callback
11067 */
11068 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011069 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11070 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011071 if (feature == ImsFeature.FEATURE_MMTEL) {
11072 // ImsMmTelManager
11073 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11074 TelephonyPermissions
11075 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11076 mApp, subId, "registerImsStateCallback");
11077 } else if (feature == ImsFeature.FEATURE_RCS) {
11078 // ImsRcsManager or SipDelegateManager
11079 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11080 Binder.getCallingUid(), "registerImsStateCallback",
11081 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11082 Manifest.permission.READ_PRECISE_PHONE_STATE,
11083 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11084 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11085 }
11086
11087 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11088 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11089 "IMS not available on device.");
11090 }
11091
11092 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11093 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11094 }
11095
11096 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11097 if (controller == null) {
11098 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11099 "IMS not available on device.");
11100 }
11101
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011102 if (callingPackage == null) {
11103 callingPackage = getCurrentPackageName();
11104 }
11105
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011106 final long token = Binder.clearCallingIdentity();
11107 try {
11108 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011109 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011110 } catch (ImsException e) {
11111 throw new ServiceSpecificException(e.getCode());
11112 } finally {
11113 Binder.restoreCallingIdentity(token);
11114 }
11115 }
11116
11117 /**
11118 * Unregister an IMS connection state callback
11119 */
11120 @Override
11121 public void unregisterImsStateCallback(IImsStateCallback cb) {
11122 final long token = Binder.clearCallingIdentity();
11123 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11124 if (controller == null) {
11125 return;
11126 }
11127 try {
11128 controller.unregisterImsStateCallback(cb);
11129 } finally {
11130 Binder.restoreCallingIdentity(token);
11131 }
11132 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011133
11134 /**
11135 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11136 *
11137 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11138 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11139 * SecurityException.
11140 * If there is current registered network this value will be same as the registered cell
11141 * identity. If the device goes out of service the previous cell identity is cached and
11142 * will be returned. If the cache age of the Cell identity is more than 24 hours
11143 * it will be cleared and null will be returned.
11144 *
11145 */
11146 @Override
11147 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11148 String callingFeatureId) {
11149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11150 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11151 LocationAccessPolicy.checkLocationPermission(mApp,
11152 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11153 .setCallingPackage(callingPackage)
11154 .setCallingFeatureId(callingFeatureId)
11155 .setCallingPid(Binder.getCallingPid())
11156 .setCallingUid(Binder.getCallingUid())
11157 .setMethod("getLastKnownCellIdentity")
11158 .setLogAsInfo(true)
11159 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11160 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11161 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11162 .build());
11163
11164 boolean hasFinePermission =
11165 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11166 if (!hasFinePermission
11167 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11168 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11169 + "and BIND_CONNECTION_SERVICE permission.");
11170 }
11171
11172 final long identity = Binder.clearCallingIdentity();
11173 try {
11174 Phone phone = getPhone(subId);
11175 if (phone == null) return null;
11176 ServiceStateTracker sst = phone.getServiceStateTracker();
11177 if (sst == null) return null;
11178 return sst.getLastKnownCellIdentity();
11179 } finally {
11180 Binder.restoreCallingIdentity(identity);
11181 }
11182 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011183
11184 @Override
11185 public boolean isUsingNewDataStack() {
11186 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11187 return getDefaultPhone().isUsingNewDataStack();
11188 }
jimsun3b9ccac2021-10-26 15:01:23 +080011189
11190 /**
11191 * Sets the modem service class Name that Telephony will bind to.
11192 *
11193 * @param serviceName The class name of the modem service.
11194 * @return true if the operation is succeed, otherwise false.
11195 */
11196 public boolean setModemService(String serviceName) {
11197 Log.d(LOG_TAG, "setModemService - " + serviceName);
11198 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11200 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11201 "setModemService");
11202 return mPhoneConfigurationManager.setModemService(serviceName);
11203 }
11204
11205 /**
11206 * Return the class name of the currently bounded modem service.
11207 *
11208 * @return the class name of the modem service.
11209 */
11210 public String getModemService() {
11211 String result;
11212 Log.d(LOG_TAG, "getModemService");
11213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11214 TelephonyPermissions
11215 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11216 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11217 "getModemService");
11218 result = mPhoneConfigurationManager.getModemService();
11219 Log.d(LOG_TAG, "result = " + result);
11220 return result;
11221 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011222
11223 @Override
11224 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11225 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11226 mApp.enforceCallingOrSelfPermission(
11227 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11228 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11229
11230 final long identity = Binder.clearCallingIdentity();
11231 try {
11232 Phone phone = getPhone(subId);
11233 if (phone == null) return;
11234 phone.setVoiceServiceStateOverride(hasService);
11235 } finally {
11236 Binder.restoreCallingIdentity(identity);
11237 }
11238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011239}