blob: b501892572b38727d6496c25a9c599ac6d729aac [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;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
Chen Xu540470b2021-12-14 17:15:47 -080036import android.compat.Compatibility;
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 Nudelmanb0b87642020-11-12 15:04:39 -080078import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080079import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070080import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080081import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070082import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080083import android.telephony.CellIdentityCdma;
84import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070086import android.telephony.CellInfoGsm;
87import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070088import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080089import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070090import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070091import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070092import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080093import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070094import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080095import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070096import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080097import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080098import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070099import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800100import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800102import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800103import android.telephony.SignalStrengthUpdateRequest;
104import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800105import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800106import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800107import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700108import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800111import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800112import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000113import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000114import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000115import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700116import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700117import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800118import android.telephony.data.ApnSetting;
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.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800137import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800138import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800139import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700142import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800144import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145
Andrew Lee312e8172014-10-23 17:01:36 -0700146import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800147import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800148import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800149import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800150import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700152import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700153import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800154import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800155import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700156import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800158import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700160import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800161import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800162import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800163import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700164import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000165import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700166import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800167import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800170import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700172import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700175import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800176import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700177import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700178import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700179import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700180import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800181import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800182import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700183import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700184import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700185import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800186import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800187import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800188import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700189import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700191import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800192import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700193import com.android.internal.telephony.imsphone.ImsPhone;
194import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000195import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800196import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700197import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800199import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700202import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800203import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000205import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800206import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000207import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800208import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700209import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700210import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800211import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800212import com.android.phone.callcomposer.CallComposerPictureManager;
213import com.android.phone.callcomposer.CallComposerPictureTransfer;
214import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700215import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800217import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700218import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700219import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800220import com.android.services.telephony.TelecomAccountRegistry;
221import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800222import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800223
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700225import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.io.IOException;
227import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700228import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800230import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000231import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800232import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800233import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800234import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800235import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100236import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700238import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800239import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800240import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800241import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800242import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800243import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
245/**
246 * Implementation of the ITelephony interface.
247 */
Santos Cordon117fee72014-05-16 17:56:12 -0700248public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 private static final String LOG_TAG = "PhoneInterfaceManager";
250 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
251 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
254 // Message codes used with mMainThreadHandler
255 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700256 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
257 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700258 private static final int CMD_OPEN_CHANNEL = 9;
259 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
260 private static final int CMD_CLOSE_CHANNEL = 11;
261 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800262 private static final int CMD_NV_READ_ITEM = 13;
263 private static final int EVENT_NV_READ_ITEM_DONE = 14;
264 private static final int CMD_NV_WRITE_ITEM = 15;
265 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
266 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
267 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700268 private static final int CMD_RESET_MODEM_CONFIG = 19;
269 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800270 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
271 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800272 private static final int CMD_SEND_ENVELOPE = 25;
273 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000274 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
275 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700276 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
277 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
278 private static final int CMD_EXCHANGE_SIM_IO = 31;
279 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
281 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700282 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700284 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
285 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700286 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
287 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
288 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
289 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700290 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
291 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
292 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
293 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700294 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800295 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
296 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000297 private static final int CMD_SWITCH_SLOTS = 50;
298 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700299 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
300 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
301 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
302 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
303 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
304 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
305 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
306 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700307 private static final int CMD_GET_ALL_CELL_INFO = 60;
308 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
309 private static final int CMD_GET_CELL_LOCATION = 62;
310 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_MODEM_REBOOT = 64;
312 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700313 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
314 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800315 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
316 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700317 private static final int CMD_GET_MODEM_STATUS = 70;
318 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700319 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
320 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700321 private static final int CMD_ERASE_MODEM_CONFIG = 74;
322 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800323 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
324 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
325 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
326 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800327 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
328 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800329 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800330 private static final int CMD_GET_CALL_FORWARDING = 83;
331 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
332 private static final int CMD_SET_CALL_FORWARDING = 85;
333 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
334 private static final int CMD_GET_CALL_WAITING = 87;
335 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
336 private static final int CMD_SET_CALL_WAITING = 89;
337 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700338 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
339 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
340 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
341 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700342 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
343 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800344 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
345 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800346 private static final int CMD_SET_DATA_THROTTLING = 99;
347 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800348 private static final int CMD_SET_SIM_POWER = 101;
349 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800350 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
351 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
352 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
353 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800354 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
355 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000356 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800357 private static final int CMD_GET_SLICING_CONFIG = 110;
358 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800359 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700360 private static final int CMD_ENABLE_VONR = 113;
361 private static final int EVENT_ENABLE_VONR_DONE = 114;
362 private static final int CMD_IS_VONR_ENABLED = 115;
363 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800365 // Parameters of select command.
366 private static final int SELECT_COMMAND = 0xA4;
367 private static final int SELECT_P1 = 0x04;
368 private static final int SELECT_P2 = 0;
369 private static final int SELECT_P3 = 0x10;
370
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 /** The singleton instance. */
372 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800373 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800377 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700378 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700380 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800382 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800383 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700384 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800385 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 /** User Activity */
388 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
390
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700391 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
392
Derek Tan97ebb422014-09-05 16:55:38 -0700393 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
394 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800395 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800396 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700397
Michelecea4cf22018-12-21 15:00:11 -0800398 // String to store multi SIM allowed
399 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
400
Derek Tan740e1672017-06-27 14:56:27 -0700401 // The AID of ISD-R.
402 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
403
yinxub1bed742017-04-17 11:45:04 -0700404 private NetworkScanRequestTracker mNetworkScanRequestTracker;
405
David Kelly5e06a7f2018-03-12 14:10:59 +0000406 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
407 private static final int MANUFACTURER_CODE_LENGTH = 8;
408
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800410 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411
Derek Tan89e89d42014-07-08 17:00:10 -0700412 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700413 * Experiment flag to enable erase modem config on reset network, default value is false
414 */
415 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
416 "reset_network_erase_modem_config_enabled";
417
Rambo Wang0f050d82021-02-12 11:43:36 -0800418 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800419
sandeepjsb6c87872021-09-27 15:34:44 +0000420 /**
421 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
422 * one ICCID active at the same time.
423 * Apps should use below API signatures if targeting SDK is T and beyond.
424 *
425 * @hide
426 */
427 @ChangeId
428 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
429 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800430
Naina Nallurid63128d2019-09-17 14:10:30 -0700431 /**
Chen Xu540470b2021-12-14 17:15:47 -0800432 * Apps targeting on Android T and beyond will get exception whenever icc close channel
433 * operation fails.
434 */
435 @ChangeId
436 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
437 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
438
439 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 * A request object to use for transmitting data to an ICC.
441 */
442 private static final class IccAPDUArgument {
443 public int channel, cla, command, p1, p2, p3;
444 public String data;
445
446 public IccAPDUArgument(int channel, int cla, int command,
447 int p1, int p2, int p3, String data) {
448 this.channel = channel;
449 this.cla = cla;
450 this.command = command;
451 this.p1 = p1;
452 this.p2 = p2;
453 this.p3 = p3;
454 this.data = data;
455 }
456 }
457
458 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700459 * A request object to use for transmitting data to an ICC.
460 */
461 private static final class ManualNetworkSelectionArgument {
462 public OperatorInfo operatorInfo;
463 public boolean persistSelection;
464
465 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
466 this.operatorInfo = operatorInfo;
467 this.persistSelection = persistSelection;
468 }
469 }
470
471 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
473 * request after sending. The main thread will notify the request when it is complete.
474 */
475 private static final class MainThreadRequest {
476 /** The argument to use for the request */
477 public Object argument;
478 /** The result of the request that is run on the main thread */
479 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800480 // The subscriber id that this request applies to. Defaults to
481 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
482 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483
Nathan Harold92bed182018-10-12 18:16:49 -0700484 // In cases where subId is unavailable, the caller needs to specify the phone.
485 public Phone phone;
486
vagdeviaf9a5b92018-08-15 16:01:53 -0700487 public WorkSource workSource;
488
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 public MainThreadRequest(Object argument) {
490 this.argument = argument;
491 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800492
Nathan Harold92bed182018-10-12 18:16:49 -0700493 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
494 this.argument = argument;
495 if (phone != null) {
496 this.phone = phone;
497 }
498 this.workSource = workSource;
499 }
500
vagdeviaf9a5b92018-08-15 16:01:53 -0700501 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800502 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800503 if (subId != null) {
504 this.subId = subId;
505 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700506 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 }
509
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800510 private static final class IncomingThirdPartyCallArgs {
511 public final ComponentName component;
512 public final String callId;
513 public final String callerDisplayName;
514
515 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
516 String callerDisplayName) {
517 this.component = component;
518 this.callId = callId;
519 this.callerDisplayName = callerDisplayName;
520 }
521 }
522
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 /**
524 * A handler that processes messages on the main thread in the phone process. Since many
525 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
526 * inbound binder threads to the main thread in the phone process. The Binder thread
527 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
528 * on, which will be notified when the operation completes and will contain the result of the
529 * request.
530 *
531 * <p>If a MainThreadRequest object is provided in the msg.obj field,
532 * note that request.result must be set to something non-null for the calling thread to
533 * unblock.
534 */
535 private final class MainThreadHandler extends Handler {
536 @Override
537 public void handleMessage(Message msg) {
538 MainThreadRequest request;
539 Message onCompleted;
540 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000541 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800543 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544
545 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 case CMD_HANDLE_USSD_REQUEST: {
547 request = (MainThreadRequest) msg.obj;
548 final Phone phone = getPhoneFromRequest(request);
549 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800550 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700552
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 if (!isUssdApiAllowed(request.subId)) {
554 // Carrier does not support use of this API, return failure.
555 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
556 UssdResponse response = new UssdResponse(ussdRequest, null);
557 Bundle returnData = new Bundle();
558 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
559 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700560
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 request.result = true;
562 notifyRequester(request);
563 return;
564 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700565
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 try {
567 request.result = phone != null
568 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
569 } catch (CallStateException cse) {
570 request.result = false;
571 }
572 // Wake up the requesting thread
573 notifyRequester(request);
574 break;
pkanwar32d516d2016-10-14 19:37:38 -0700575 }
576
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700579 final Phone phone = getPhoneFromRequest(request);
580 request.result = phone != null ?
581 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
582 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700587
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000591 uiccPort = getUiccPortFromRequest(request);
592 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800594 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800598 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000599 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800600 iccArgument.channel, iccArgument.cla, iccArgument.command,
601 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
602 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 break;
605
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 ar = (AsyncResult) msg.obj;
608 request = (MainThreadRequest) ar.userObj;
609 if (ar.exception == null && ar.result != null) {
610 request.result = ar.result;
611 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800612 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.result == null) {
614 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800615 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800617 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 } else {
619 loge("iccTransmitApduLogicalChannel: Unknown exception");
620 }
621 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
626 request = (MainThreadRequest) msg.obj;
627 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000628 uiccPort = getUiccPortFromRequest(request);
629 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800631 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 } else {
634 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800635 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000636 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800637 iccArgument.cla, iccArgument.command, iccArgument.p1,
638 iccArgument.p2,
639 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 }
641 break;
642
643 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
648 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 if (ar.result == null) {
651 loge("iccTransmitApduBasicChannel: Empty response");
652 } else if (ar.exception instanceof CommandException) {
653 loge("iccTransmitApduBasicChannel: CommandException: " +
654 ar.exception);
655 } else {
656 loge("iccTransmitApduBasicChannel: Unknown exception");
657 }
658 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 break;
661
662 case CMD_EXCHANGE_SIM_IO:
663 request = (MainThreadRequest) msg.obj;
664 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort = getUiccPortFromRequest(request);
666 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 } else {
671 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
672 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000673 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
675 iccArgument.data, onCompleted);
676 }
677 break;
678
679 case EVENT_EXCHANGE_SIM_IO_DONE:
680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result;
684 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800685 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 break;
689
Derek Tan4d5e5c12014-02-04 11:54:58 -0800690 case CMD_SEND_ENVELOPE:
691 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 uiccPort = getUiccPortFromRequest(request);
693 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800695 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 } else {
698 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800699 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700700 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800701 break;
702
703 case EVENT_SEND_ENVELOPE_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800708 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700710 if (ar.result == null) {
711 loge("sendEnvelopeWithStatus: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("sendEnvelopeWithStatus: CommandException: " +
714 ar.exception);
715 } else {
716 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
717 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800720 break;
721
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 case CMD_OPEN_CHANNEL:
723 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800725 IccLogicalChannelRequest openChannelRequest =
726 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000727 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800729 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800730 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 } else {
733 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800734 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
735 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700736 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case EVENT_OPEN_CHANNEL_DONE:
740 ar = (AsyncResult) msg.obj;
741 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 int[] result = (int[]) ar.result;
745 int channelId = result[0];
746 byte[] selectResponse = null;
747 if (result.length > 1) {
748 selectResponse = new byte[result.length - 1];
749 for (int i = 1; i < result.length; ++i) {
750 selectResponse[i - 1] = (byte) result[i];
751 }
752 }
753 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800754 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800755
756 uiccPort = getUiccPortFromRequest(request);
757 IccLogicalChannelRequest channelRequest =
758 (IccLogicalChannelRequest) request.argument;
759 channelRequest.channel = channelId;
760 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 if (ar.result == null) {
763 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700765 if (ar.exception != null) {
766 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
767 }
768
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700769 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700770 if (ar.exception instanceof CommandException) {
771 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800772 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700773 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700774 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700775 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700776 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700777 }
778 }
779 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800780 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700782 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
786 case CMD_CLOSE_CHANNEL:
787 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000788 uiccPort = getUiccPortFromRequest(request);
789 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700790 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800791 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800792 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800793 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 } else {
795 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000796 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700797 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 break;
799
800 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 if (ar.exception == null) {
804 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800805 uiccPort = getUiccPortFromRequest(request);
806 final int channelId = (Integer) request.argument;
807 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800808 } else {
809 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800810 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800811 if (ar.exception instanceof CommandException) {
812 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
813 CommandException.Error error =
814 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800815 if (error == CommandException.Error.INVALID_ARGUMENTS) {
816 // should only throw exceptions from the binder threads.
817 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800818 "iccCloseLogicalChannel: invalid argument ");
819 }
820 } else {
821 loge("iccCloseLogicalChannel: Unknown exception");
822 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800823 request.result = (exception != null) ? exception :
824 new IllegalStateException(
825 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800826 }
827 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800828 break;
829
830 case CMD_NV_READ_ITEM:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800833 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
834 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800835 break;
836
837 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800843 request.result = "";
844 if (ar.result == null) {
845 loge("nvReadItem: Empty response");
846 } else if (ar.exception instanceof CommandException) {
847 loge("nvReadItem: CommandException: " +
848 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800850 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 }
852 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700853 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 break;
855
Jake Hambye994d462014-02-03 13:10:13 -0800856 case CMD_NV_WRITE_ITEM:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
859 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800860 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700861 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800862 break;
863
864 case EVENT_NV_WRITE_ITEM_DONE:
865 handleNullReturnEvent(msg, "nvWriteItem");
866 break;
867
868 case CMD_NV_WRITE_CDMA_PRL:
869 request = (MainThreadRequest) msg.obj;
870 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800871 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800872 break;
873
874 case EVENT_NV_WRITE_CDMA_PRL_DONE:
875 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
876 break;
877
chen xu6dac5ab2018-10-26 17:39:23 -0700878 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800879 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700880 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800881 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800882 break;
883
chen xu6dac5ab2018-10-26 17:39:23 -0700884 case EVENT_RESET_MODEM_CONFIG_DONE:
885 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800886 break;
887
Sooraj Sasindran37444802020-08-11 10:40:43 -0700888 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
891 request);
892 Phone phone = getPhoneFromRequest(request);
893 if (phone != null) {
894 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
895 } else {
896 loge("isNRDualConnectivityEnabled: No phone object");
897 request.result = false;
898 notifyRequester(request);
899 }
900 break;
901 }
902
903 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
904 ar = (AsyncResult) msg.obj;
905 request = (MainThreadRequest) ar.userObj;
906 if (ar.exception == null && ar.result != null) {
907 request.result = ar.result;
908 } else {
909 // request.result must be set to something non-null
910 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700911 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700912 request.result = ar.result;
913 } else {
914 request.result = false;
915 }
916 if (ar.result == null) {
917 loge("isNRDualConnectivityEnabled: Empty response");
918 } else if (ar.exception instanceof CommandException) {
919 loge("isNRDualConnectivityEnabled: CommandException: "
920 + ar.exception);
921 } else {
922 loge("isNRDualConnectivityEnabled: Unknown exception");
923 }
924 }
925 notifyRequester(request);
926 break;
927
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700928 case CMD_IS_VONR_ENABLED: {
929 request = (MainThreadRequest) msg.obj;
930 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
931 request);
932 Phone phone = getPhoneFromRequest(request);
933 if (phone != null) {
934 phone.isVoNrEnabled(onCompleted, request.workSource);
935 } else {
936 loge("isVoNrEnabled: No phone object");
937 request.result = false;
938 notifyRequester(request);
939 }
940 break;
941 }
942
943 case EVENT_IS_VONR_ENABLED_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 if (ar.exception == null && ar.result != null) {
947 request.result = ar.result;
948 } else {
949 // request.result must be set to something non-null
950 // for the calling thread to unblock
951 if (ar.result != null) {
952 request.result = ar.result;
953 } else {
954 request.result = false;
955 }
956 if (ar.result == null) {
957 loge("isVoNrEnabled: Empty response");
958 } else if (ar.exception instanceof CommandException) {
959 loge("isVoNrEnabled: CommandException: "
960 + ar.exception);
961 } else {
962 loge("isVoNrEnabled: Unknown exception");
963 }
964 }
965 notifyRequester(request);
966 break;
967
Sooraj Sasindran37444802020-08-11 10:40:43 -0700968 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
971 Phone phone = getPhoneFromRequest(request);
972 if (phone != null) {
973 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
974 request.workSource);
975 } else {
976 loge("enableNrDualConnectivity: No phone object");
977 request.result =
978 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null) {
988 request.result =
989 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
990 } else {
991 request.result =
992 TelephonyManager
993 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
994 if (ar.exception instanceof CommandException) {
995 CommandException.Error error =
996 ((CommandException) (ar.exception)).getCommandError();
997 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
998 request.result =
999 TelephonyManager
1000 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001001 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1002 request.result =
1003 TelephonyManager
1004 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001005 }
1006 loge("enableNrDualConnectivity" + ": CommandException: "
1007 + ar.exception);
1008 } else {
1009 loge("enableNrDualConnectivity" + ": Unknown exception");
1010 }
1011 }
1012 notifyRequester(request);
1013 break;
1014 }
1015
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001016 case CMD_ENABLE_VONR: {
1017 request = (MainThreadRequest) msg.obj;
1018 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1019 Phone phone = getPhoneFromRequest(request);
1020 if (phone != null) {
1021 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1022 request.workSource);
1023 } else {
1024 loge("setVoNrEnabled: No phone object");
1025 request.result =
1026 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1027 notifyRequester(request);
1028 }
1029 break;
1030 }
1031
1032 case EVENT_ENABLE_VONR_DONE: {
1033 ar = (AsyncResult) msg.obj;
1034 request = (MainThreadRequest) ar.userObj;
1035 if (ar.exception == null) {
1036 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1037 } else {
1038 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1039 if (ar.exception instanceof CommandException) {
1040 CommandException.Error error =
1041 ((CommandException) (ar.exception)).getCommandError();
1042 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1043 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1044 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1045 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1046 } else {
1047 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1048 }
1049 loge("setVoNrEnabled" + ": CommandException: "
1050 + ar.exception);
1051 } else {
1052 loge("setVoNrEnabled" + ": Unknown exception");
1053 }
1054 }
1055 notifyRequester(request);
1056 break;
1057 }
1058
SongFerngWang3ef3e072020-12-21 16:41:52 +08001059 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001060 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001061 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1062 request);
1063 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001064 break;
1065
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 if (ar.exception == null && ar.result != null) {
1070 request.result = ar.result; // Integer
1071 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301072 // request.result must be set to something non-null
1073 // for the calling thread to unblock
1074 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001075 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001076 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001078 loge("getAllowedNetworkTypesBitmask: CommandException: "
1079 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001080 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001081 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 }
1083 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001084 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 break;
1086
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1090 request);
1091 Pair<Integer, Long> reasonWithNetworkTypes =
1092 (Pair<Integer, Long>) request.argument;
1093 getPhoneFromRequest(request).setAllowedNetworkTypes(
1094 reasonWithNetworkTypes.first,
1095 reasonWithNetworkTypes.second,
1096 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001097 break;
1098
SongFerngWang3ef3e072020-12-21 16:41:52 +08001099 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1100 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 break;
1102
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001103 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1104 request = (MainThreadRequest)msg.obj;
1105 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001106 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001107 break;
1108
1109 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1110 ar = (AsyncResult)msg.obj;
1111 request = (MainThreadRequest)ar.userObj;
1112 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001113 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001114 break;
1115
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001116 case CMD_SET_VOICEMAIL_NUMBER:
1117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1119 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001120 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1121 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001122 break;
1123
1124 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1125 handleNullReturnEvent(msg, "setVoicemailNumber");
1126 break;
1127
Stuart Scott54788802015-03-30 13:18:01 -07001128 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1129 request = (MainThreadRequest) msg.obj;
1130 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1131 request);
1132 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1133 break;
1134
1135 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1136 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1137 break;
1138
Shishir Agrawal302c8692015-06-19 13:49:39 -07001139 case CMD_PERFORM_NETWORK_SCAN:
1140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1142 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1143 break;
1144
Hall Liu27d24262020-09-18 19:04:59 -07001145 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001148 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1149 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1150 request.argument;
1151 int callForwardingReason = args.first;
1152 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001153 break;
Hall Liu27d24262020-09-18 19:04:59 -07001154 }
1155 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001156 ar = (AsyncResult) msg.obj;
1157 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001158 TelephonyManager.CallForwardingInfoCallback callback =
1159 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1160 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001161 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001162 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001163 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1164 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1165 // Service Class is a bit mask per 3gpp 27.007. Search for
1166 // any service for voice call.
1167 if ((callForwardInfo.serviceClass
1168 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001169 callForwardingInfo = new CallForwardingInfo(
1170 callForwardInfo.status
1171 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001172 callForwardInfo.reason,
1173 callForwardInfo.number,
1174 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001175 break;
1176 }
1177 }
1178 // Didn't find a call forward info for voice call.
1179 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001180 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1181 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001182 }
Hall Liu27d24262020-09-18 19:04:59 -07001183 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001184 } else {
1185 if (ar.result == null) {
1186 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1187 }
1188 if (ar.exception != null) {
1189 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1190 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001191 int errorCode = TelephonyManager
1192 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 if (ar.exception instanceof CommandException) {
1194 CommandException.Error error =
1195 ((CommandException) (ar.exception)).getCommandError();
1196 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001200 errorCode = TelephonyManager
1201 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 }
1203 }
Hall Liu27d24262020-09-18 19:04:59 -07001204 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001205 }
Shuo Qian4a594052020-01-23 11:59:30 -08001206 break;
Hall Liu27d24262020-09-18 19:04:59 -07001207 }
Shuo Qian4a594052020-01-23 11:59:30 -08001208
Hall Liu27d24262020-09-18 19:04:59 -07001209 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001210 request = (MainThreadRequest) msg.obj;
1211 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001212 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001213 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001214 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1215 request.argument).first;
1216 request.phone.setCallForwardingOption(
1217 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001218 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001219 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001220 callForwardingInfoToSet.getReason(),
1221 callForwardingInfoToSet.getNumber(),
1222 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1223 break;
Hall Liu27d24262020-09-18 19:04:59 -07001224 }
Shuo Qian4a594052020-01-23 11:59:30 -08001225
Hall Liu27d24262020-09-18 19:04:59 -07001226 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001227 ar = (AsyncResult) msg.obj;
1228 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001229 Consumer<Integer> callback =
1230 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1231 request.argument).second;
1232 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001233 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001234 int errorCode = TelephonyManager.CallForwardingInfoCallback
1235 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001236 if (ar.exception instanceof CommandException) {
1237 CommandException.Error error =
1238 ((CommandException) (ar.exception)).getCommandError();
1239 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001242 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001243 errorCode = TelephonyManager.CallForwardingInfoCallback
1244 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001245 }
1246 }
1247 callback.accept(errorCode);
1248 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001249 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 }
Shuo Qian4a594052020-01-23 11:59:30 -08001251 break;
Hall Liu27d24262020-09-18 19:04:59 -07001252 }
Shuo Qian4a594052020-01-23 11:59:30 -08001253
Hall Liu27d24262020-09-18 19:04:59 -07001254 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001255 request = (MainThreadRequest) msg.obj;
1256 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1257 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260
Hall Liu27d24262020-09-18 19:04:59 -07001261 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001264 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001265 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001267 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 // Service Class is a bit mask per 3gpp 27.007.
1269 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001270 if (callForwardResults.length > 1
1271 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001272 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001273 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001274 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1275 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001277 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
1279 } else {
1280 if (ar.result == null) {
1281 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1282 }
1283 if (ar.exception != null) {
1284 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1285 }
1286 if (ar.exception instanceof CommandException) {
1287 CommandException.Error error =
1288 ((CommandException) (ar.exception)).getCommandError();
1289 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001290 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001291 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001292 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1293 callWaitingStatus =
1294 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001295 }
1296 }
1297 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001298 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001299 break;
Hall Liu27d24262020-09-18 19:04:59 -07001300 }
Shuo Qian4a594052020-01-23 11:59:30 -08001301
Hall Liu27d24262020-09-18 19:04:59 -07001302 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001303 request = (MainThreadRequest) msg.obj;
1304 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001305 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1306 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001307 break;
Hall Liu27d24262020-09-18 19:04:59 -07001308 }
Shuo Qian4a594052020-01-23 11:59:30 -08001309
Hall Liu27d24262020-09-18 19:04:59 -07001310 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001311 ar = (AsyncResult) msg.obj;
1312 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001313 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1314 Consumer<Integer> callback =
1315 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1316 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001318 if (ar.exception instanceof CommandException) {
1319 CommandException.Error error =
1320 ((CommandException) (ar.exception)).getCommandError();
1321 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1322 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001323 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1324 callback.accept(
1325 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001326 } else {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1328 }
1329 } else {
1330 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1331 }
1332 } else {
1333 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1334 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001335 }
Shuo Qian4a594052020-01-23 11:59:30 -08001336 break;
Hall Liu27d24262020-09-18 19:04:59 -07001337 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001338 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1339 ar = (AsyncResult) msg.obj;
1340 request = (MainThreadRequest) ar.userObj;
1341 CellNetworkScanResult cellScanResult;
1342 if (ar.exception == null && ar.result != null) {
1343 cellScanResult = new CellNetworkScanResult(
1344 CellNetworkScanResult.STATUS_SUCCESS,
1345 (List<OperatorInfo>) ar.result);
1346 } else {
1347 if (ar.result == null) {
1348 loge("getCellNetworkScanResults: Empty response");
1349 }
1350 if (ar.exception != null) {
1351 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1352 }
1353 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1354 if (ar.exception instanceof CommandException) {
1355 CommandException.Error error =
1356 ((CommandException) (ar.exception)).getCommandError();
1357 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1358 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1359 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1360 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1361 }
1362 }
1363 cellScanResult = new CellNetworkScanResult(errorCode, null);
1364 }
1365 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001366 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001367 break;
1368
1369 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1370 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001371 ManualNetworkSelectionArgument selArg =
1372 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001373 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1374 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001375 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1376 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001377 break;
1378
1379 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 if (ar.exception == null) {
1383 request.result = true;
1384 } else {
1385 request.result = false;
1386 loge("setNetworkSelectionModeManual " + ar.exception);
1387 }
1388 notifyRequester(request);
1389 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001390 break;
1391
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001392 case CMD_GET_MODEM_ACTIVITY_INFO:
1393 request = (MainThreadRequest) msg.obj;
1394 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001395 if (defaultPhone != null) {
1396 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001397 } else {
1398 ResultReceiver result = (ResultReceiver) request.argument;
1399 Bundle bundle = new Bundle();
1400 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001401 new ModemActivityInfo(0, 0, 0,
1402 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001403 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001404 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001405 break;
1406
Hall Liud0f208c2020-10-14 16:54:44 -07001407 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001411 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001412 if (mLastModemActivityInfo == null) {
1413 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1414 mLastModemActivitySpecificInfo[0] =
1415 new ActivityStatsTechSpecificInfo(
1416 0,
1417 0,
1418 new int[ModemActivityInfo.getNumTxPowerLevels()],
1419 0);
1420 mLastModemActivityInfo =
1421 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1422 }
1423
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001424 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001425 // Update the last modem activity info and the result of the request.
1426 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1427 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001428 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001429 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001430 mLastModemActivityInfo =
1431 new ModemActivityInfo(
1432 mLastModemActivityInfo.getTimestampMillis(),
1433 mLastModemActivityInfo.getSleepTimeMillis(),
1434 mLastModemActivityInfo.getIdleTimeMillis(),
1435 mLastModemActivitySpecificInfo);
1436
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001437 } else {
1438 if (ar.result == null) {
1439 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001440 error = TelephonyManager.ModemActivityInfoException
1441 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001443 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001444 error = TelephonyManager.ModemActivityInfoException
1445 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 } else {
1447 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001448 error = TelephonyManager.ModemActivityInfoException
1449 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 }
1451 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001453 if (mLastModemActivityInfo != null) {
1454 bundle.putParcelable(
1455 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1456 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001457 } else {
1458 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1459 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001461 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001462 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001463 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001464
Meng Wang1a7c35a2016-05-05 20:56:15 -07001465 case CMD_SET_ALLOWED_CARRIERS:
1466 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001467 CarrierRestrictionRules argument =
1468 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001469 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001470 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001471 break;
1472
1473 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1474 ar = (AsyncResult) msg.obj;
1475 request = (MainThreadRequest) ar.userObj;
1476 if (ar.exception == null && ar.result != null) {
1477 request.result = ar.result;
1478 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001479 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1480 if (ar.exception instanceof CommandException) {
1481 loge("setAllowedCarriers: CommandException: " + ar.exception);
1482 CommandException.Error error =
1483 ((CommandException) (ar.exception)).getCommandError();
1484 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1485 request.result =
1486 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1487 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001488 } else {
1489 loge("setAllowedCarriers: Unknown exception");
1490 }
1491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001492 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 break;
1494
1495 case CMD_GET_ALLOWED_CARRIERS:
1496 request = (MainThreadRequest) msg.obj;
1497 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001498 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 break;
1500
1501 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1502 ar = (AsyncResult) msg.obj;
1503 request = (MainThreadRequest) ar.userObj;
1504 if (ar.exception == null && ar.result != null) {
1505 request.result = ar.result;
1506 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001507 request.result = new IllegalStateException(
1508 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001509 if (ar.result == null) {
1510 loge("getAllowedCarriers: Empty response");
1511 } else if (ar.exception instanceof CommandException) {
1512 loge("getAllowedCarriers: CommandException: " +
1513 ar.exception);
1514 } else {
1515 loge("getAllowedCarriers: Unknown exception");
1516 }
1517 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001518 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 break;
1520
Nathan Haroldb3014052017-01-25 15:57:32 -08001521 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1522 ar = (AsyncResult) msg.obj;
1523 request = (MainThreadRequest) ar.userObj;
1524 if (ar.exception == null && ar.result != null) {
1525 request.result = ar.result;
1526 } else {
1527 request.result = new IllegalArgumentException(
1528 "Failed to retrieve Forbidden Plmns");
1529 if (ar.result == null) {
1530 loge("getForbiddenPlmns: Empty response");
1531 } else {
1532 loge("getForbiddenPlmns: Unknown exception");
1533 }
1534 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001535 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001536 break;
1537
1538 case CMD_GET_FORBIDDEN_PLMNS:
1539 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001540 uiccPort = getUiccPortFromRequest(request);
1541 if (uiccPort == null) {
1542 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001543 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001544 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001545 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001546 break;
1547 }
1548 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001549 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001550 if (uiccApp == null) {
1551 loge("getForbiddenPlmns() no app with specified type -- "
1552 + appType);
1553 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001554 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001555 break;
1556 } else {
1557 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1558 + " specified type -- " + appType);
1559 }
1560 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1561 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1562 onCompleted);
1563 break;
1564
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001565 case CMD_SWITCH_SLOTS:
1566 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001567 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001568 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001569 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001570 break;
1571
1572 case EVENT_SWITCH_SLOTS_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001576 notifyRequester(request);
1577 break;
1578 case CMD_GET_NETWORK_SELECTION_MODE:
1579 request = (MainThreadRequest) msg.obj;
1580 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1581 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1582 break;
1583
1584 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
1587 if (ar.exception != null) {
1588 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1589 } else {
1590 int mode = ((int[]) ar.result)[0];
1591 if (mode == 0) {
1592 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1593 } else {
1594 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1595 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001596 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001597 notifyRequester(request);
1598 break;
1599 case CMD_GET_CDMA_ROAMING_MODE:
1600 request = (MainThreadRequest) msg.obj;
1601 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1602 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1603 break;
1604 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
1607 if (ar.exception != null) {
1608 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1609 } else {
1610 request.result = ((int[]) ar.result)[0];
1611 }
1612 notifyRequester(request);
1613 break;
1614 case CMD_SET_CDMA_ROAMING_MODE:
1615 request = (MainThreadRequest) msg.obj;
1616 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1617 int mode = (int) request.argument;
1618 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1619 break;
1620 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 request.result = ar.exception == null;
1624 notifyRequester(request);
1625 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001626 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1627 request = (MainThreadRequest) msg.obj;
1628 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1629 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1630 break;
1631 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception != null) {
1635 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1636 } else {
1637 request.result = ((int[]) ar.result)[0];
1638 }
1639 notifyRequester(request);
1640 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001641 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1642 request = (MainThreadRequest) msg.obj;
1643 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1644 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001645 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1646 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001647 break;
1648 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 request.result = ar.exception == null;
1652 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001653 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001654 case CMD_GET_ALL_CELL_INFO:
1655 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001656 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001657 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 case EVENT_GET_ALL_CELL_INFO_DONE:
1660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001662 // If a timeout occurs, the response will be null
1663 request.result = (ar.exception == null && ar.result != null)
1664 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001665 synchronized (request) {
1666 request.notifyAll();
1667 }
1668 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001669 case CMD_REQUEST_CELL_INFO_UPDATE:
1670 request = (MainThreadRequest) msg.obj;
1671 request.phone.requestCellInfoUpdate(request.workSource,
1672 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1673 break;
1674 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1678 try {
1679 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001680 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001681 cb.onError(
1682 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1683 ar.exception.getClass().getName(),
1684 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001686 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001687 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001688 } else {
1689 // use the result as returned
1690 cb.onCellInfo((List<CellInfo>) ar.result);
1691 }
1692 } catch (RemoteException re) {
1693 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1694 }
1695 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001696 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001697 request = (MainThreadRequest) msg.obj;
1698 WorkSource ws = (WorkSource) request.argument;
1699 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001700 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001701 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 }
1703 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 if (ar.exception == null) {
1707 request.result = ar.result;
1708 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001709 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001710 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001711 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001712 }
1713
1714 synchronized (request) {
1715 request.notifyAll();
1716 }
1717 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001718 }
chen xu6dac5ab2018-10-26 17:39:23 -07001719 case CMD_MODEM_REBOOT:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001722 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001723 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001724 case EVENT_CMD_MODEM_REBOOT_DONE:
1725 handleNullReturnEvent(msg, "rebootModem");
1726 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001727 case CMD_REQUEST_ENABLE_MODEM:
1728 request = (MainThreadRequest) msg.obj;
1729 boolean enable = (boolean) request.argument;
1730 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001731 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001732 PhoneConfigurationManager.getInstance()
1733 .enablePhone(request.phone, enable, onCompleted);
1734 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001735 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001739 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001740 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001741 if ((boolean) request.result) {
1742 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1743 updateModemStateMetrics();
1744 } else {
1745 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1746 + ar.exception);
1747 }
1748 notifyRequester(request);
1749 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001750 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001751 case CMD_GET_MODEM_STATUS:
1752 request = (MainThreadRequest) msg.obj;
1753 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1754 PhoneConfigurationManager.getInstance()
1755 .getPhoneStatusFromModem(request.phone, onCompleted);
1756 break;
1757 case EVENT_GET_MODEM_STATUS_DONE:
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760 int id = request.phone.getPhoneId();
1761 if (ar.exception == null && ar.result != null) {
1762 request.result = ar.result;
1763 //update the cache as modem status has changed
1764 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1765 (boolean) request.result);
1766 } else {
1767 // Return true if modem status cannot be retrieved. For most cases,
1768 // modem status is on. And for older version modems, GET_MODEM_STATUS
1769 // and disable modem are not supported. Modem is always on.
1770 // TODO: this should be fixed in R to support a third
1771 // status UNKNOWN b/131631629
1772 request.result = true;
1773 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1774 + ar.exception);
1775 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001776 notifyRequester(request);
1777 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001778 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1779 request = (MainThreadRequest) msg.obj;
1780 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1781 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1782 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1783 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1784 break;
1785 }
1786 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1787 ar = (AsyncResult) msg.obj;
1788 request = (MainThreadRequest) ar.userObj;
1789 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1790 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1791 args.second.accept(ar.exception == null);
1792 notifyRequester(request);
1793 break;
1794 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001795 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1796 request = (MainThreadRequest) msg.obj;
1797 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1798 Phone phone = getPhoneFromRequest(request);
1799 if (phone != null) {
1800 phone.getSystemSelectionChannels(onCompleted);
1801 } else {
1802 loge("getSystemSelectionChannels: No phone object");
1803 request.result = new ArrayList<RadioAccessSpecifier>();
1804 notifyRequester(request);
1805 }
1806 break;
1807 }
1808 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1809 ar = (AsyncResult) msg.obj;
1810 request = (MainThreadRequest) ar.userObj;
1811 if (ar.exception == null && ar.result != null) {
1812 request.result = ar.result;
1813 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001814 request.result = new IllegalStateException(
1815 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001816 if (ar.result == null) {
1817 loge("getSystemSelectionChannels: Empty response");
1818 } else {
1819 loge("getSystemSelectionChannels: Unknown exception");
1820 }
1821 }
1822 notifyRequester(request);
1823 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001824 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1825 ar = (AsyncResult) msg.obj;
1826 request = (MainThreadRequest) ar.userObj;
1827 if (ar.exception == null && ar.result != null) {
1828 request.result = ar.result;
1829 } else {
1830 request.result = -1;
1831 loge("Failed to set Forbidden Plmns");
1832 if (ar.result == null) {
1833 loge("setForbidenPlmns: Empty response");
1834 } else if (ar.exception != null) {
1835 loge("setForbiddenPlmns: Exception: " + ar.exception);
1836 request.result = -1;
1837 } else {
1838 loge("setForbiddenPlmns: Unknown exception");
1839 }
1840 }
1841 notifyRequester(request);
1842 break;
1843 case CMD_SET_FORBIDDEN_PLMNS:
1844 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001845 uiccPort = getUiccPortFromRequest(request);
1846 if (uiccPort == null) {
1847 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001848 request.result = -1;
1849 notifyRequester(request);
1850 break;
1851 }
1852 Pair<Integer, List<String>> setFplmnsArgs =
1853 (Pair<Integer, List<String>>) request.argument;
1854 appType = setFplmnsArgs.first;
1855 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001856 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001857 if (uiccApp == null) {
1858 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1859 request.result = -1;
1860 loge("Failed to get UICC App");
1861 notifyRequester(request);
1862 } else {
1863 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1864 ((SIMRecords) uiccApp.getIccRecords())
1865 .setForbiddenPlmns(onCompleted, fplmns);
1866 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001867 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001868 case CMD_ERASE_MODEM_CONFIG:
1869 request = (MainThreadRequest) msg.obj;
1870 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1871 defaultPhone.eraseModemConfig(onCompleted);
1872 break;
1873 case EVENT_ERASE_MODEM_CONFIG_DONE:
1874 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001875 break;
zoey chene02881a2019-12-30 16:11:23 +08001876
Kai Shif70f46f2021-03-03 13:59:46 -08001877 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1878 request = (MainThreadRequest) msg.obj;
1879 request.result = defaultPhone.eraseDataInSharedPreferences();
1880 notifyRequester(request);
1881 break;
1882
zoey chene02881a2019-12-30 16:11:23 +08001883 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1884 request = (MainThreadRequest) msg.obj;
1885 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1886 Pair<String, String> changed = (Pair<String, String>) request.argument;
1887 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1888 changed.first, changed.second, onCompleted);
1889 break;
1890 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1891 ar = (AsyncResult) msg.obj;
1892 request = (MainThreadRequest) ar.userObj;
1893 if (ar.exception == null) {
1894 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001895 // If the operation is successful, update the PIN storage
1896 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1897 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001898 UiccController.getInstance().getPinStorage()
1899 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001900 } else {
1901 request.result = msg.arg1;
1902 }
1903 notifyRequester(request);
1904 break;
1905
Michele Berionne5e411512020-11-13 02:36:59 +00001906 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001907 request = (MainThreadRequest) msg.obj;
1908 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1909 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1910 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1911 enabled.first, enabled.second, onCompleted);
1912 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001913 }
zoey chene02881a2019-12-30 16:11:23 +08001914 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1915 ar = (AsyncResult) msg.obj;
1916 request = (MainThreadRequest) ar.userObj;
1917 if (ar.exception == null) {
1918 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001919 // If the operation is successful, update the PIN storage
1920 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1921 int phoneId = getPhoneFromRequest(request).getPhoneId();
1922 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001923 UiccController.getInstance().getPinStorage()
1924 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001925 } else {
1926 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1927 }
zoey chene02881a2019-12-30 16:11:23 +08001928 } else {
1929 request.result = msg.arg1;
1930 }
Michele Berionne5e411512020-11-13 02:36:59 +00001931
1932
zoey chene02881a2019-12-30 16:11:23 +08001933 notifyRequester(request);
1934 break;
1935
Peter Wangdafb9ac2020-01-15 14:13:38 -08001936 case MSG_NOTIFY_USER_ACTIVITY:
1937 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001938 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001939 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1940 getDefaultPhone().getContext().sendBroadcastAsUser(
1941 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1942 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001943
1944 case CMD_SET_DATA_THROTTLING: {
1945 request = (MainThreadRequest) msg.obj;
1946 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1947 DataThrottlingRequest dataThrottlingRequest =
1948 (DataThrottlingRequest) request.argument;
1949 Phone phone = getPhoneFromRequest(request);
1950 if (phone != null) {
1951 phone.setDataThrottling(onCompleted,
1952 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1953 dataThrottlingRequest.getCompletionDurationMillis());
1954 } else {
1955 loge("setDataThrottling: No phone object");
1956 request.result =
1957 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1958 notifyRequester(request);
1959 }
1960
1961 break;
1962 }
1963 case EVENT_SET_DATA_THROTTLING_DONE:
1964 ar = (AsyncResult) msg.obj;
1965 request = (MainThreadRequest) ar.userObj;
1966
1967 if (ar.exception == null) {
1968 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1969 } else if (ar.exception instanceof CommandException) {
1970 loge("setDataThrottling: CommandException: " + ar.exception);
1971 CommandException.Error error =
1972 ((CommandException) (ar.exception)).getCommandError();
1973
1974 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1975 request.result = TelephonyManager
1976 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1977 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1978 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001979 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1980 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001981 } else {
1982 request.result =
1983 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1984 }
1985 } else {
1986 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1987 }
1988 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1989 notifyRequester(request);
1990 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001991
1992 case CMD_SET_SIM_POWER: {
1993 request = (MainThreadRequest) msg.obj;
1994 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1995 request = (MainThreadRequest) msg.obj;
1996 int stateToSet =
1997 ((Pair<Integer, IIntegerConsumer>)
1998 request.argument).first;
1999 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2000 break;
2001 }
2002 case EVENT_SET_SIM_POWER_DONE: {
2003 ar = (AsyncResult) msg.obj;
2004 request = (MainThreadRequest) ar.userObj;
2005 IIntegerConsumer callback =
2006 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2007 if (ar.exception != null) {
2008 loge("setSimPower exception: " + ar.exception);
2009 int errorCode = TelephonyManager.CallForwardingInfoCallback
2010 .RESULT_ERROR_UNKNOWN;
2011 if (ar.exception instanceof CommandException) {
2012 CommandException.Error error =
2013 ((CommandException) (ar.exception)).getCommandError();
2014 if (error == CommandException.Error.SIM_ERR) {
2015 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2016 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2017 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2018 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2019 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2020 } else {
2021 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2022 }
2023 }
2024 try {
2025 callback.accept(errorCode);
2026 } catch (RemoteException e) {
2027 // Ignore if the remote process is no longer available to call back.
2028 Log.w(LOG_TAG, "setSimPower: callback not available.");
2029 }
2030 } else {
2031 try {
2032 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2033 } catch (RemoteException e) {
2034 // Ignore if the remote process is no longer available to call back.
2035 Log.w(LOG_TAG, "setSimPower: callback not available.");
2036 }
2037 }
2038 break;
2039 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002040 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2041 request = (MainThreadRequest) msg.obj;
2042
2043 final Phone phone = getPhoneFromRequest(request);
2044 if (phone == null || phone.getServiceStateTracker() == null) {
2045 request.result = new IllegalStateException("Phone or SST is null");
2046 notifyRequester(request);
2047 break;
2048 }
2049
2050 Pair<Integer, SignalStrengthUpdateRequest> pair =
2051 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2052 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2053 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002054 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002055 request.subId, pair.first /*callingUid*/,
2056 pair.second /*request*/, onCompleted);
2057 break;
2058 }
2059 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2060 ar = (AsyncResult) msg.obj;
2061 request = (MainThreadRequest) ar.userObj;
2062 // request.result will be the exception of ar if present, true otherwise.
2063 // Be cautious not to leave result null which will wait() forever
2064 request.result = ar.exception != null ? ar.exception : true;
2065 notifyRequester(request);
2066 break;
2067 }
2068 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2069 request = (MainThreadRequest) msg.obj;
2070
2071 Phone phone = getPhoneFromRequest(request);
2072 if (phone == null || phone.getServiceStateTracker() == null) {
2073 request.result = new IllegalStateException("Phone or SST is null");
2074 notifyRequester(request);
2075 break;
2076 }
2077
2078 Pair<Integer, SignalStrengthUpdateRequest> pair =
2079 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2080 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2081 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002082 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002083 request.subId, pair.first /*callingUid*/,
2084 pair.second /*request*/, onCompleted);
2085 break;
2086 }
2087 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2088 ar = (AsyncResult) msg.obj;
2089 request = (MainThreadRequest) ar.userObj;
2090 request.result = ar.exception != null ? ar.exception : true;
2091 notifyRequester(request);
2092 break;
2093 }
Jordan Liu109698e2020-11-24 14:50:34 -08002094
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002095 case CMD_GET_SLICING_CONFIG: {
2096 request = (MainThreadRequest) msg.obj;
2097 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2098 request.phone.getSlicingConfig(onCompleted);
2099 break;
2100 }
2101 case EVENT_GET_SLICING_CONFIG_DONE: {
2102 ar = (AsyncResult) msg.obj;
2103 request = (MainThreadRequest) ar.userObj;
2104 ResultReceiver result = (ResultReceiver) request.argument;
2105
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002106 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002107 Bundle bundle = new Bundle();
2108 int resultCode = 0;
2109 if (ar.exception != null) {
2110 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2111 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002112 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 } else if (ar.result == null) {
2114 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002115 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002116 } else {
2117 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002118 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2119 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002120 }
2121
2122 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002124 }
2125 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2126 result.send(resultCode, bundle);
2127 notifyRequester(request);
2128 break;
2129 }
2130
Michele Berionne5e411512020-11-13 02:36:59 +00002131 case CMD_PREPARE_UNATTENDED_REBOOT:
2132 request = (MainThreadRequest) msg.obj;
2133 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002134 UiccController.getInstance().getPinStorage()
2135 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002136 notifyRequester(request);
2137 break;
2138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 default:
2140 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2141 break;
2142 }
2143 }
Jake Hambye994d462014-02-03 13:10:13 -08002144
Pengquan Menga1bb6272018-09-06 09:59:22 -07002145 private void notifyRequester(MainThreadRequest request) {
2146 synchronized (request) {
2147 request.notifyAll();
2148 }
2149 }
2150
Jake Hambye994d462014-02-03 13:10:13 -08002151 private void handleNullReturnEvent(Message msg, String command) {
2152 AsyncResult ar = (AsyncResult) msg.obj;
2153 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2154 if (ar.exception == null) {
2155 request.result = true;
2156 } else {
2157 request.result = false;
2158 if (ar.exception instanceof CommandException) {
2159 loge(command + ": CommandException: " + ar.exception);
2160 } else {
2161 loge(command + ": Unknown exception");
2162 }
2163 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002164 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
2168 /**
2169 * Posts the specified command to be executed on the main thread,
2170 * waits for the request to complete, and returns the result.
2171 * @see #sendRequestAsync
2172 */
2173 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002174 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2175 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002176 }
2177
2178 /**
2179 * Posts the specified command to be executed on the main thread,
2180 * waits for the request to complete, and returns the result.
2181 * @see #sendRequestAsync
2182 */
2183 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2184 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002185 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
2188 /**
2189 * Posts the specified command to be executed on the main thread,
2190 * waits for the request to complete, and returns the result.
2191 * @see #sendRequestAsync
2192 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002193 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002194 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2195 }
2196
2197 /**
2198 * Posts the specified command to be executed on the main thread,
2199 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2200 * if not timeout or null otherwise.
2201 * @see #sendRequestAsync
2202 */
2203 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2204 long timeoutInMs) {
2205 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002206 }
2207
2208 /**
2209 * Posts the specified command to be executed on the main thread,
2210 * waits for the request to complete, and returns the result.
2211 * @see #sendRequestAsync
2212 */
Nathan Harold92bed182018-10-12 18:16:49 -07002213 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002214 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002215 }
2216
2217 /**
2218 * Posts the specified command to be executed on the main thread,
2219 * waits for the request to complete, and returns the result.
2220 * @see #sendRequestAsync
2221 */
2222 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002223 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2224 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002225 }
2226
2227 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002228 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2229 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2230 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002231 * @see #sendRequestAsync
2232 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2234 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2236 throw new RuntimeException("This method will deadlock if called from the main thread.");
2237 }
2238
Nathan Harold92bed182018-10-12 18:16:49 -07002239 MainThreadRequest request = null;
2240 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2241 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2242 } else if (phone != null) {
2243 request = new MainThreadRequest(argument, phone, workSource);
2244 } else {
2245 request = new MainThreadRequest(argument, subId, workSource);
2246 }
2247
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 Message msg = mMainThreadHandler.obtainMessage(command, request);
2249 msg.sendToTarget();
2250
Rambo Wang0f050d82021-02-12 11:43:36 -08002251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002253 if (timeoutInMs >= 0) {
2254 // Wait for at least timeoutInMs before returning null request result
2255 long now = SystemClock.elapsedRealtime();
2256 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002257 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002258 try {
2259 request.wait(deadline - now);
2260 } catch (InterruptedException e) {
2261 // Do nothing, go back and check if request is completed or timeout
2262 } finally {
2263 now = SystemClock.elapsedRealtime();
2264 }
2265 }
2266 } else {
2267 // Wait for the request to complete
2268 while (request.result == null) {
2269 try {
2270 request.wait();
2271 } catch (InterruptedException e) {
2272 // Do nothing, go back and wait until the request is complete
2273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 }
2275 }
2276 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002277 if (request.result == null) {
2278 Log.wtf(LOG_TAG,
2279 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 return request.result;
2282 }
2283
2284 /**
2285 * Asynchronous ("fire and forget") version of sendRequest():
2286 * Posts the specified command to be executed on the main thread, and
2287 * returns immediately.
2288 * @see #sendRequest
2289 */
2290 private void sendRequestAsync(int command) {
2291 mMainThreadHandler.sendEmptyMessage(command);
2292 }
2293
2294 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002295 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002296 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002297 */
2298 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002299 sendRequestAsync(command, argument, null, null);
2300 }
2301
2302 /**
2303 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2304 * @see {@link #sendRequest(int,Object)}
2305 */
2306 private void sendRequestAsync(
2307 int command, Object argument, Phone phone, WorkSource workSource) {
2308 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002309 Message msg = mMainThreadHandler.obtainMessage(command, request);
2310 msg.sendToTarget();
2311 }
2312
2313 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 * Initialize the singleton PhoneInterfaceManager instance.
2315 * This is only done once, at startup, from PhoneApp.onCreate().
2316 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002317 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 synchronized (PhoneInterfaceManager.class) {
2319 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002320 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 } else {
2322 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2323 }
2324 return sInstance;
2325 }
2326 }
2327
2328 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002329 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002332 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002333 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002335 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002337 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002338 mTelephonySharedPreferences =
2339 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002340 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002341 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002342 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002343 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002344
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 publish();
2346 }
2347
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002348 private Phone getDefaultPhone() {
2349 Phone thePhone = getPhone(getDefaultSubscription());
2350 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2351 }
2352
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 private void publish() {
2354 if (DBG) log("publish: " + this);
2355
Peter Wangc035ce42020-01-08 21:00:22 -08002356 TelephonyFrameworkInitializer
2357 .getTelephonyServiceManager()
2358 .getTelephonyServiceRegisterer()
2359 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
Stuart Scott584921c2015-01-15 17:10:34 -08002362 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002363 if (request.phone != null) {
2364 return request.phone;
2365 } else {
2366 return getPhoneFromSubId(request.subId);
2367 }
2368 }
2369
2370 private Phone getPhoneFromSubId(int subId) {
2371 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2372 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002373 }
2374
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002375 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002376 Phone phone = getPhoneFromRequest(request);
2377 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002378 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002379 }
2380
Wink Saville36469e72014-06-11 15:17:00 -07002381 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002382 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002383 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385
Kai Shif70f46f2021-03-03 13:59:46 -08002386 private void sendEraseModemConfig(@NonNull Phone phone) {
2387 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2388 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2389 }
2390
2391 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2392 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2393 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002394 }
2395
Peter Wang44b186e2020-01-13 23:33:09 -08002396 private boolean isImsAvailableOnDevice() {
2397 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2398 if (pm == null) {
2399 // For some reason package manger is not available.. This will fail internally anyway,
2400 // so do not throw error and allow.
2401 return true;
2402 }
2403 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2404 }
2405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002407 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002408 }
2409
Wink Savilleb564aae2014-10-23 10:18:09 -07002410 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 if (DBG) log("dial: " + number);
2412 // No permission check needed here: This is just a wrapper around the
2413 // ACTION_DIAL intent, which is available to any app since it puts up
2414 // the UI before it does anything.
2415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 String url = createTelUrl(number);
2419 if (url == null) {
2420 return;
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423 // PENDING: should we just silently fail if phone is offhook or ringing?
2424 PhoneConstants.State state = mCM.getState(subId);
2425 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2426 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2427 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2428 mApp.startActivity(intent);
2429 }
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433 }
2434
2435 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002436 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002437 }
2438
Wink Savilleb564aae2014-10-23 10:18:09 -07002439 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 if (DBG) log("call: " + number);
2441
2442 // This is just a wrapper around the ACTION_CALL intent, but we still
2443 // need to do a permission check since we're calling startActivity()
2444 // from the context of the phone app.
2445 enforceCallPermission();
2446
Jordan Liu1617b712019-07-10 15:06:26 -07002447 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 != AppOpsManager.MODE_ALLOWED) {
2449 return;
2450 }
2451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 final long identity = Binder.clearCallingIdentity();
2453 try {
2454 String url = createTelUrl(number);
2455 if (url == null) {
2456 return;
2457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 boolean isValid = false;
2460 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2461 if (slist != null) {
2462 for (SubscriptionInfo subInfoRecord : slist) {
2463 if (subInfoRecord.getSubscriptionId() == subId) {
2464 isValid = true;
2465 break;
2466 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002467 }
Wink Saville08874612014-08-31 19:19:58 -07002468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 if (!isValid) {
2470 return;
2471 }
Wink Saville08874612014-08-31 19:19:58 -07002472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2474 intent.putExtra(SUBSCRIPTION_KEY, subId);
2475 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2476 mApp.startActivity(intent);
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
2479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 }
2481
Wink Savilleb564aae2014-10-23 10:18:09 -07002482 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002483 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002484 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2485 }
2486
Wink Savilleb564aae2014-10-23 10:18:09 -07002487 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002488 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002489 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2490 }
2491
Wink Savilleb564aae2014-10-23 10:18:09 -07002492 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494
2495 final long identity = Binder.clearCallingIdentity();
2496 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002497 Phone phone = getPhone(subId);
2498 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 checkSimPin.start();
2500 return checkSimPin.unlockSim(null, pin);
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
2503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
Wink Savilleb564aae2014-10-23 10:18:09 -07002506 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002511 Phone phone = getPhone(subId);
2512 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 checkSimPuk.start();
2514 return checkSimPuk.unlockSim(puk, pin);
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
2519
2520 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002521 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 * a synchronous one.
2523 */
2524 private static class UnlockSim extends Thread {
2525
2526 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002527 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528
2529 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002530 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2531 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532
2533 // For replies from SimCard interface
2534 private Handler mHandler;
2535
2536 // For async handler to identify request type
2537 private static final int SUPPLY_PIN_COMPLETE = 100;
2538
Michele Berionne5e411512020-11-13 02:36:59 +00002539 UnlockSim(int phoneId, IccCard simCard) {
2540 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 mSimCard = simCard;
2542 }
2543
2544 @Override
2545 public void run() {
2546 Looper.prepare();
2547 synchronized (UnlockSim.this) {
2548 mHandler = new Handler() {
2549 @Override
2550 public void handleMessage(Message msg) {
2551 AsyncResult ar = (AsyncResult) msg.obj;
2552 switch (msg.what) {
2553 case SUPPLY_PIN_COMPLETE:
2554 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2555 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002556 mRetryCount = msg.arg1;
2557 if (ar.exception != null) {
2558 if (ar.exception instanceof CommandException &&
2559 ((CommandException)(ar.exception)).getCommandError()
2560 == CommandException.Error.PASSWORD_INCORRECT) {
2561 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002562 } //When UiccCardApp dispose,handle message and return exception
2563 else if (ar.exception instanceof CommandException &&
2564 ((CommandException) (ar.exception)).getCommandError()
2565 == CommandException.Error.ABORTED) {
2566 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002567 } else {
2568 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2569 }
2570 } else {
2571 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 mDone = true;
2574 UnlockSim.this.notifyAll();
2575 }
2576 break;
2577 }
2578 }
2579 };
2580 UnlockSim.this.notifyAll();
2581 }
2582 Looper.loop();
2583 }
2584
2585 /*
2586 * Use PIN or PUK to unlock SIM card
2587 *
2588 * If PUK is null, unlock SIM card with PIN
2589 *
2590 * If PUK is not null, unlock SIM card with PUK and set PIN code
2591 */
Wink Saville9de0f752013-10-22 19:04:03 -07002592 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593
2594 while (mHandler == null) {
2595 try {
2596 wait();
2597 } catch (InterruptedException e) {
2598 Thread.currentThread().interrupt();
2599 }
2600 }
2601 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2602
2603 if (puk == null) {
2604 mSimCard.supplyPin(pin, callback);
2605 } else {
2606 mSimCard.supplyPuk(puk, pin, callback);
2607 }
2608
2609 while (!mDone) {
2610 try {
2611 Log.d(LOG_TAG, "wait for done");
2612 wait();
2613 } catch (InterruptedException e) {
2614 // Restore the interrupted status
2615 Thread.currentThread().interrupt();
2616 }
2617 }
2618 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002619 int[] resultArray = new int[2];
2620 resultArray[0] = mResult;
2621 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002622
2623 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002624 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002625 }
2626
Wink Saville9de0f752013-10-22 19:04:03 -07002627 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629 }
2630
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002631 /**
2632 * This method has been removed due to privacy and stability concerns.
2633 */
2634 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002636 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2637 return;
Wink Saville36469e72014-06-11 15:17:00 -07002638 }
2639
Nathan Harold1f889d82020-06-04 17:05:26 -07002640 @Override
2641 public void updateServiceLocationWithPackageName(String callingPackage) {
2642 mApp.getSystemService(AppOpsManager.class)
2643 .checkPackage(Binder.getCallingUid(), callingPackage);
2644
Nathan Haroldf096d982020-11-18 17:18:06 -08002645 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002646 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2647 // Callers targeting S have no business invoking this method.
2648 return;
2649 }
2650
2651 LocationAccessPolicy.LocationPermissionResult locationResult =
2652 LocationAccessPolicy.checkLocationPermission(mApp,
2653 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2654 .setCallingPackage(callingPackage)
2655 .setCallingFeatureId(null)
2656 .setCallingPid(Binder.getCallingPid())
2657 .setCallingUid(Binder.getCallingUid())
2658 .setMethod("updateServiceLocation")
2659 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2660 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2661 .build());
2662 // Apps that lack location permission have no business calling this method;
2663 // however, because no permission was declared in the public API, denials must
2664 // all be "soft".
2665 switch (locationResult) {
2666 case DENIED_HARD: /* fall through */
2667 case DENIED_SOFT:
2668 return;
2669 }
2670
2671 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 final long identity = Binder.clearCallingIdentity();
2673 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002674 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002676 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677 }
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
2682
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002683 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002684 @Override
2685 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002686 return isRadioOnWithFeature(callingPackage, null);
2687 }
2688
2689
2690 @Override
2691 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2692 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2693 callingFeatureId);
2694 }
2695
2696 @Deprecated
2697 @Override
2698 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2699 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002700 }
2701
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002703 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2704 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002706 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002707 return false;
2708 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
2710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 return isRadioOnForSubscriber(subId);
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
2715 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002716 }
2717
2718 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 final Phone phone = getPhone(subId);
2722 if (phone != null) {
2723 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2724 } else {
2725 return false;
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
2732 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002733 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 }
Wink Saville36469e72014-06-11 15:17:00 -07002735
Wink Savilleb564aae2014-10-23 10:18:09 -07002736 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone phone = getPhone(subId);
2742 if (phone != null) {
2743 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002747 }
Wink Saville36469e72014-06-11 15:17:00 -07002748 }
2749
2750 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002751 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002752 }
2753
Wink Savilleb564aae2014-10-23 10:18:09 -07002754 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756
2757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 final Phone phone = getPhone(subId);
2760 if (phone == null) {
2761 return false;
2762 }
2763 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2764 toggleRadioOnOffForSubscriber(subId);
2765 }
2766 return true;
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
Wink Saville36469e72014-06-11 15:17:00 -07002771
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002772 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002773 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002774 /*
2775 * If any of the Radios are available, it will need to be
2776 * shutdown. So return true if any Radio is available.
2777 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2781 Phone phone = PhoneFactory.getPhone(i);
2782 if (phone != null && phone.isRadioAvailable()) return true;
2783 }
2784 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2785 return false;
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002788 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002789 }
2790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002792 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 enforceModifyPermission();
2794
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2798 logv("Shutting down Phone " + i);
2799 shutdownRadioUsingPhoneId(i);
2800 }
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002803 }
2804 }
2805
2806 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002807 Phone phone = PhoneFactory.getPhone(phoneId);
2808 if (phone != null && phone.isRadioAvailable()) {
2809 phone.shutdownRadio();
2810 }
2811 }
2812
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002814 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2819 if (defaultPhone != null) {
2820 defaultPhone.setRadioPower(turnOn);
2821 return true;
2822 } else {
2823 loge("There's no default phone.");
2824 return false;
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002828 }
Wink Saville36469e72014-06-11 15:17:00 -07002829 }
2830
Wink Savilleb564aae2014-10-23 10:18:09 -07002831 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833
2834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 final Phone phone = getPhone(subId);
2837 if (phone != null) {
2838 phone.setRadioPower(turnOn);
2839 return true;
2840 } else {
2841 return false;
2842 }
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847
Wink Saville36469e72014-06-11 15:17:00 -07002848 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 public boolean enableDataConnectivity() {
2851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 int subId = mSubscriptionController.getDefaultDataSubId();
2856 final Phone phone = getPhone(subId);
2857 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002858 if (phone.isUsingNewDataStack()) {
2859 phone.getDataSettingsManager().setDataEnabled(
2860 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2861 } else {
2862 phone.getDataEnabledSettings().setDataEnabled(
2863 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 return true;
2866 } else {
2867 return false;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
2873
Wink Saville36469e72014-06-11 15:17:00 -07002874 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 public boolean disableDataConnectivity() {
2877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 int subId = mSubscriptionController.getDefaultDataSubId();
2882 final Phone phone = getPhone(subId);
2883 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002884 if (phone.isUsingNewDataStack()) {
2885 phone.getDataSettingsManager().setDataEnabled(
2886 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2887 } else {
2888 phone.getDataEnabledSettings().setDataEnabled(
2889 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 return true;
2892 } else {
2893 return false;
2894 }
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 }
2899
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002901 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 final Phone phone = getPhone(subId);
2905 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002906 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 } else {
2908 return false;
2909 }
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 }
2914
2915 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002916 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002917 }
2918
pkanwarae03a6b2016-11-06 20:37:09 -08002919 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 enforceCallPermission();
2921
2922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2925 return;
2926 }
2927 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2928 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
2931 }
pkanwar32d516d2016-10-14 19:37:38 -07002932 };
2933
Wink Savilleb564aae2014-10-23 10:18:09 -07002934 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936
2937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2940 return false;
2941 }
2942 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 }
2947
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002948 /**
2949 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2950 * tag on getCallState Binder call.
2951 */
2952 @Deprecated
2953 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002955 if (CompatChanges.isChangeEnabled(
2956 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2957 Binder.getCallingUid())) {
2958 // Do not allow this API to be called on API version 31+, it should only be
2959 // called on old apps using this Binder call directly.
2960 throw new SecurityException("This method can only be used for applications "
2961 + "targeting API version 30 or less.");
2962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963 final long identity = Binder.clearCallingIdentity();
2964 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002965 Phone phone = getPhone(getDefaultSubscription());
2966 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2967 PhoneConstantConversions.convertCallState(phone.getState());
2968 } finally {
2969 Binder.restoreCallingIdentity(identity);
2970 }
2971 }
2972
2973 @Override
2974 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2975 if (CompatChanges.isChangeEnabled(
2976 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2977 Binder.getCallingUid())) {
2978 // Check READ_PHONE_STATE for API version 31+
2979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2980 featureId, "getCallStateForSubscription")) {
2981 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2982 + "targeting API level 31+.");
2983 }
2984 }
2985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2989 PhoneConstantConversions.convertCallState(phone.getState());
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 }
2994
Sanket Padawe356d7632015-06-22 14:03:32 -07002995 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002996 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002997 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2998 }
2999
3000 @Override
3001 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003004 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003006 if (phone.isUsingNewDataStack()) {
3007 return phone.getDataNetworkController().getInternetDataNetworkState();
3008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3010 } else {
3011 return PhoneConstantConversions.convertDataState(
3012 PhoneConstants.DataState.DISCONNECTED);
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003017 }
3018
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003020 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003021 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3022 }
3023
3024 @Override
3025 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003028 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 if (phone != null) {
3030 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3031 } else {
3032 return TelephonyManager.DATA_ACTIVITY_NONE;
3033 }
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
3039 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003040 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003042 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003043
3044 LocationAccessPolicy.LocationPermissionResult locationResult =
3045 LocationAccessPolicy.checkLocationPermission(mApp,
3046 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3047 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003048 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003049 .setCallingPid(Binder.getCallingPid())
3050 .setCallingUid(Binder.getCallingUid())
3051 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003052 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003053 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3054 .build());
3055 switch (locationResult) {
3056 case DENIED_HARD:
3057 throw new SecurityException("Not allowed to access cell location");
3058 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003059 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3060 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003063 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003067 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003068 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Svetoslav64fad262015-04-14 14:35:21 -07003072 }
3073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003075 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003076 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3077 // registered cell info, so return a NULL country instead.
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003080 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3081 // Get default phone in this case.
3082 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3083 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003084 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003086 if (phone == null) return "";
3087 ServiceStateTracker sst = phone.getServiceStateTracker();
3088 if (sst == null) return "";
3089 LocaleTracker lt = sst.getLocaleTracker();
3090 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003091 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003095 }
3096
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003097 /**
3098 * This method was removed due to potential issues caused by performing partial
3099 * updates of service state, and lack of a credible use case.
3100 *
3101 * This has the ability to break the telephony implementation by disabling notification of
3102 * changes in device connectivity. DO NOT USE THIS!
3103 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003104 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 public void enableLocationUpdates() {
3106 mApp.enforceCallingOrSelfPermission(
3107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003110 /**
3111 * This method was removed due to potential issues caused by performing partial
3112 * updates of service state, and lack of a credible use case.
3113 *
3114 * This has the ability to break the telephony implementation by disabling notification of
3115 * changes in device connectivity. DO NOT USE THIS!
3116 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 @Override
3118 public void disableLocationUpdates() {
3119 mApp.enforceCallingOrSelfPermission(
3120 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 }
3122
3123 @Override
3124 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003125 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3126 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003127 try {
3128 mApp.getSystemService(AppOpsManager.class)
3129 .checkPackage(Binder.getCallingUid(), callingPackage);
3130 } catch (SecurityException e) {
3131 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3132 throw e;
3133 }
3134
Nathan Haroldf096d982020-11-18 17:18:06 -08003135 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003136 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3137 throw new SecurityException(
3138 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3139 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003140
Jordan Liu1617b712019-07-10 15:06:26 -07003141 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3143 return null;
3144 }
Svetoslav64fad262015-04-14 14:35:21 -07003145
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003146 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003148 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003149 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150
Nathan Haroldf180aac2018-06-01 18:43:55 -07003151 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3152 for (CellInfo ci : info) {
3153 if (ci instanceof CellInfoGsm) {
3154 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3155 } else if (ci instanceof CellInfoWcdma) {
3156 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003159 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003162 private List<CellInfo> getCachedCellInfo() {
3163 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3164 for (Phone phone : PhoneFactory.getPhones()) {
3165 List<CellInfo> info = phone.getAllCellInfo();
3166 if (info != null) cellInfos.addAll(info);
3167 }
3168 return cellInfos;
3169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170
3171 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003174 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003175
3176 LocationAccessPolicy.LocationPermissionResult locationResult =
3177 LocationAccessPolicy.checkLocationPermission(mApp,
3178 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3179 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003180 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 .setCallingPid(Binder.getCallingPid())
3182 .setCallingUid(Binder.getCallingUid())
3183 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003184 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3186 .build());
3187 switch (locationResult) {
3188 case DENIED_HARD:
3189 throw new SecurityException("Not allowed to access cell info");
3190 case DENIED_SOFT:
3191 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 }
3193
Nathan Haroldf096d982020-11-18 17:18:06 -08003194 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003195 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3196 return getCachedCellInfo();
3197 }
3198
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003199 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3204 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003205 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003206 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 if (info != null) cellInfos.addAll(info);
3208 }
3209 return cellInfos;
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213 }
3214
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003215 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003216 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3217 String callingFeatureId) {
3218 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3219 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003220 }
3221
3222 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3224 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003225 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003227 }
3228
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003229 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3230 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003231 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003232 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003233
3234 LocationAccessPolicy.LocationPermissionResult locationResult =
3235 LocationAccessPolicy.checkLocationPermission(mApp,
3236 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3237 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003238 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003239 .setCallingPid(Binder.getCallingPid())
3240 .setCallingUid(Binder.getCallingUid())
3241 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003242 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3243 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003244 .build());
3245 switch (locationResult) {
3246 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003247 if (TelephonyPermissions
3248 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003249 // Safetynet logging for b/154934934
3250 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3251 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003252 throw new SecurityException("Not allowed to access cell info");
3253 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003254 if (TelephonyPermissions
3255 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003256 // Safetynet logging for b/154934934
3257 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3258 }
Nathan Harold5320c422019-05-09 10:26:08 -07003259 try {
3260 cb.onCellInfo(new ArrayList<CellInfo>());
3261 } catch (RemoteException re) {
3262 // Drop without consequences
3263 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003264 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003265 }
3266
Nathan Harolda939a962019-05-09 10:13:47 -07003267
3268 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003269 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3270
3271 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3272 }
3273
3274 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003276 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278
3279 final long identity = Binder.clearCallingIdentity();
3280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285 }
3286
Shishir Agrawala9f32182016-04-12 12:00:16 -07003287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003288 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003289 Phone phone = PhoneFactory.getPhone(slotIndex);
3290 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 return null;
3292 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003294 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003295 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003296 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003297 return null;
3298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 return phone.getImei();
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003306 }
3307
3308 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003309 public String getTypeAllocationCodeForSlot(int slotIndex) {
3310 Phone phone = PhoneFactory.getPhone(slotIndex);
3311 String tac = null;
3312 if (phone != null) {
3313 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003314 try {
3315 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3316 } catch (IndexOutOfBoundsException e) {
3317 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3318 return null;
3319 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003320 }
3321 return tac;
3322 }
3323
3324 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003325 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003326 try {
3327 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3328 } catch (SecurityException se) {
3329 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3330 throw new SecurityException("Package " + callingPackage + " does not belong to "
3331 + Binder.getCallingUid());
3332 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003333 Phone phone = PhoneFactory.getPhone(slotIndex);
3334 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003335 return null;
3336 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337
Jeff Davidson913390f2018-02-23 17:11:49 -08003338 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003339 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003340 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003341 return null;
3342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 return phone.getMeid();
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
Jack Yu2af8d712017-03-15 17:14:14 -07003350 }
3351
3352 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003353 public String getManufacturerCodeForSlot(int slotIndex) {
3354 Phone phone = PhoneFactory.getPhone(slotIndex);
3355 String manufacturerCode = null;
3356 if (phone != null) {
3357 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003358 try {
3359 manufacturerCode =
3360 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3361 } catch (IndexOutOfBoundsException e) {
3362 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3363 return null;
3364 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003365 }
3366 return manufacturerCode;
3367 }
3368
3369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003370 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3371 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003372 Phone phone = PhoneFactory.getPhone(slotIndex);
3373 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003374 return null;
3375 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003376 int subId = phone.getSubId();
3377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003378 mApp, subId, callingPackage, callingFeatureId,
3379 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003380 return null;
3381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 return phone.getDeviceSvn();
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003389 }
3390
fionaxu43304da2017-11-27 22:51:16 -08003391 @Override
3392 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 final Phone phone = getPhone(subId);
3396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
fionaxu43304da2017-11-27 22:51:16 -08003400 }
3401
3402 @Override
3403 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 final Phone phone = getPhone(subId);
3407 return phone == null ? null : phone.getCarrierName();
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
fionaxu43304da2017-11-27 22:51:16 -08003411 }
3412
calvinpanffe225e2018-11-01 19:43:06 +08003413 @Override
chen xu0026ca62019-03-06 15:28:50 -08003414 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 final Phone phone = getPhone(subId);
3418 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003419 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
3423 }
3424
3425 @Override
chen xu0026ca62019-03-06 15:28:50 -08003426 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003430 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
chen xu651eec72018-11-11 19:03:44 -08003436 @Override
chen xu864e11c2018-12-06 22:10:03 -08003437 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3438 if (!isSubscriptionMccMnc) {
3439 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3440 }
chen xu651eec72018-11-11 19:03:44 -08003441 final Phone phone = PhoneFactory.getPhone(slotIndex);
3442 if (phone == null) {
3443 return TelephonyManager.UNKNOWN_CARRIER_ID;
3444 }
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
3451 }
3452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 //
3454 // Internal helper methods.
3455 //
3456
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003457 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003458 * Make sure the caller is the calling package itself
3459 *
3460 * @throws SecurityException if the caller is not the calling package
3461 */
3462 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3463 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003464 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3465 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003466 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003467 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003468 } catch (PackageManager.NameNotFoundException e) {
3469 // packageUid is -1
3470 }
3471 if (packageUid != callingUid) {
3472 throw new SecurityException(message + ": Package " + callingPackage
3473 + " does not belong to " + callingUid);
3474 }
3475 }
3476
3477 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3479 *
3480 * @throws SecurityException if the caller does not have the required permission
3481 */
3482 private void enforceModifyPermission() {
3483 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3484 }
3485
Shuo Qian3b6ee772019-11-13 17:43:31 -08003486 private void enforceActiveEmergencySessionPermission() {
3487 mApp.enforceCallingOrSelfPermission(
3488 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3489 }
3490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 /**
3492 * Make sure the caller has the CALL_PHONE permission.
3493 *
3494 * @throws SecurityException if the caller does not have the required permission
3495 */
3496 private void enforceCallPermission() {
3497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3498 }
3499
paulhu5a773602019-08-23 19:17:33 +08003500 private void enforceSettingsPermission() {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003502 }
3503
Michele Berionne5e411512020-11-13 02:36:59 +00003504 private void enforceRebootPermission() {
3505 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3506 }
3507
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 private String createTelUrl(String number) {
3509 if (TextUtils.isEmpty(number)) {
3510 return null;
3511 }
3512
Jake Hambye994d462014-02-03 13:10:13 -08003513 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 }
3515
Ihab Awadf9e92732013-12-05 18:02:52 -08003516 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3518 }
3519
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003520 private static void logv(String msg) {
3521 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3522 }
3523
Ihab Awadf9e92732013-12-05 18:02:52 -08003524 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3526 }
3527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003530 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003531 }
3532
Sanket Padawe356d7632015-06-22 14:03:32 -07003533 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003534 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
3539 return PhoneConstants.PHONE_TYPE_NONE;
3540 } else {
3541 return phone.getPhoneType();
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547
3548 /**
3549 * Returns the CDMA ERI icon index to display
3550 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3553 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3554 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003555 }
3556
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3559 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003561 mApp, subId, callingPackage, callingFeatureId,
3562 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 return -1;
3564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 return phone.getCdmaEriIconIndex();
3571 } else {
3572 return -1;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003577 }
3578
3579 /**
3580 * Returns the CDMA ERI icon mode,
3581 * 0 - ON
3582 * 1 - FLASHING
3583 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003585 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3586 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3587 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003588 }
3589
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3592 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003594 mApp, subId, callingPackage, callingFeatureId,
3595 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003596 return -1;
3597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 final Phone phone = getPhone(subId);
3602 if (phone != null) {
3603 return phone.getCdmaEriIconMode();
3604 } else {
3605 return -1;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 }
3611
3612 /**
3613 * Returns the CDMA ERI text,
3614 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003616 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3617 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3618 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003619 }
3620
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003622 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3623 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003625 mApp, subId, callingPackage, callingFeatureId,
3626 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003627 return null;
3628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629
3630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 final Phone phone = getPhone(subId);
3633 if (phone != null) {
3634 return phone.getCdmaEriText();
3635 } else {
3636 return null;
3637 }
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003641 }
3642
3643 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003644 * Returns the CDMA MDN.
3645 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003646 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003647 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3649 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 return phone.getLine1Number();
3656 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 return null;
3659 }
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003662 }
3663 }
3664
3665 /**
3666 * Returns the CDMA MIN.
3667 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003668 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003669 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3671 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 final Phone phone = getPhone(subId);
3676 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3677 return phone.getCdmaMin();
3678 } else {
3679 return null;
3680 }
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003683 }
3684 }
3685
Hall Liud892bec2018-11-30 14:51:45 -08003686 @Override
3687 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3688 INumberVerificationCallback callback, String callingPackage) {
3689 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3690 != PERMISSION_GRANTED) {
3691 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3692 }
3693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3694
3695 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3696 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003697 throw new SecurityException("Calling package must be configured in the device config: "
3698 + "calling package: " + callingPackage
3699 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003700 }
3701
3702 if (range == null) {
3703 throw new NullPointerException("Range must be non-null");
3704 }
3705
3706 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003707 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003708
3709 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3710 }
3711
Junda Liuca05d5d2014-08-14 22:36:34 -07003712 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003713 * Returns true if CDMA provisioning needs to run.
3714 */
3715 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 final long identity = Binder.clearCallingIdentity();
3717 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 }
3723
3724 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003725 * Sets the voice mail number of a given subId.
3726 */
3727 @Override
3728 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003729 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3730 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3735 new Pair<String, String>(alphaTag, number), new Integer(subId));
3736 return success;
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003740 }
3741
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003743 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3744 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003745 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3746 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003747 if (!TextUtils.equals(callingPackage, systemDialer)) {
3748 throw new SecurityException("caller must be system dialer");
3749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3754 if (phoneAccountHandle == null) {
3755 return null;
3756 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003760 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003761 }
3762
3763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3765 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003768 mApp, subId, callingPackage, callingFeatureId,
3769 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003770 return null;
3771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003773 final long identity = Binder.clearCallingIdentity();
3774 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003775 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003779 }
3780
3781 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003782 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3783 VisualVoicemailSmsFilterSettings settings) {
3784 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003793 }
3794
3795 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003796 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003806 }
3807
3808 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003809 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3810 String callingPackage, int subId) {
3811 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003816 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003820 }
3821
3822 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003823 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825
3826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003833 }
3834
3835 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003836 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3837 String callingAttributionTag, int subId, String number, int port, String text,
3838 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003840 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003841 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003842 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003843 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3844 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003845 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003846
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003847 /**
fionaxu0152e512016-11-14 13:36:14 -08003848 * Sets the voice activation state of a given subId.
3849 */
3850 @Override
3851 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3853 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854
3855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 final Phone phone = getPhone(subId);
3858 if (phone != null) {
3859 phone.setVoiceActivationState(activationState);
3860 } else {
3861 loge("setVoiceActivationState fails with invalid subId: " + subId);
3862 }
3863 } finally {
3864 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003865 }
3866 }
3867
3868 /**
3869 * Sets the data activation state of a given subId.
3870 */
3871 @Override
3872 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3874 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875
3876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 if (phone != null) {
3880 phone.setDataActivationState(activationState);
3881 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003882 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003886 }
3887 }
3888
3889 /**
3890 * Returns the voice activation state of a given subId.
3891 */
3892 @Override
3893 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895
fionaxu0152e512016-11-14 13:36:14 -08003896 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 if (phone != null) {
3900 return phone.getVoiceActivationState();
3901 } else {
3902 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3903 }
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003906 }
3907 }
3908
3909 /**
3910 * Returns the data activation state of a given subId.
3911 */
3912 @Override
3913 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915
fionaxu0152e512016-11-14 13:36:14 -08003916 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 if (phone != null) {
3920 return phone.getDataActivationState();
3921 } else {
3922 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3923 }
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003926 }
3927 }
3928
3929 /**
Wink Saville36469e72014-06-11 15:17:00 -07003930 * Returns the unread count of voicemails for a subId
3931 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003933 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3934 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003936 mApp, subId, callingPackage, callingFeatureId,
3937 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003938 return 0;
3939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 final Phone phone = getPhone(subId);
3943 if (phone != null) {
3944 return phone.getVoiceMessageCount();
3945 } else {
3946 return 0;
3947 }
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 }
3952
3953 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003954 * returns true, if the device is in a state where both voice and data
3955 * are supported simultaneously. This can change based on location or network condition.
3956 */
3957 @Override
3958 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 final Phone phone = getPhone(subId);
3962 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003966 }
3967
3968 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003969 * Send the dialer code if called from the current default dialer or the caller has
3970 * carrier privilege.
3971 * @param inputCode The dialer code to send
3972 */
3973 @Override
3974 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003977 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3978 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003979 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003980 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003981 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983
3984 final long identity = Binder.clearCallingIdentity();
3985 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
fionaxu235cc5e2017-03-06 22:25:57 -08003990 }
3991
Pengquan Menga1bb6272018-09-06 09:59:22 -07003992 @Override
3993 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003994 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003995 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003996 mApp, subId, "getNetworkSelectionMode");
3997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 if (!isActiveSubscription(subId)) {
4000 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4001 }
4002 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004005 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004006 }
4007
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004009 public boolean isInEmergencySmsMode() {
4010 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 for (Phone phone : PhoneFactory.getPhones()) {
4014 if (phone.isInEmergencySmsMode()) {
4015 return true;
4016 }
4017 }
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
4020 }
4021 return false;
4022 }
4023
shilu366312e2019-12-17 09:28:10 -08004024 /**
4025 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4026 * @param subId The subscription to use to check the configuration.
4027 * @param c The callback that will be used to send the result.
4028 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004029 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004030 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4031 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 mApp, subId, "registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 final long token = Binder.clearCallingIdentity();
4035 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004036 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
4037 manager.addRegistrationCallbackForSubscription(c, subId);
4038 return null;
4039 });
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 } finally {
4043 Binder.restoreCallingIdentity(token);
4044 }
4045 }
4046
shilu366312e2019-12-17 09:28:10 -08004047 /**
4048 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4049 * @param subId The subscription to use to check the configuration.
4050 * @param c The callback that will be used to send the result.
4051 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004053 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004054 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004055 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004056 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4057 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4058 }
Meng Wangafbc5852019-09-19 17:37:13 -07004059 final long token = Binder.clearCallingIdentity();
4060 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004061 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4062 .removeRegistrationCallbackForSubscription(c, subId);
4063 } catch (ImsException e) {
4064 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4065 + "is inactive, ignoring unregister.");
4066 // If the subscription is no longer active, just return, since the callback
4067 // will already have been removed internally.
4068 } finally {
4069 Binder.restoreCallingIdentity(token);
4070 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 }
4072
Brad Ebingera34a6c22019-10-22 17:36:18 -07004073 /**
4074 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4075 */
4076 @Override
4077 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4078 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4079 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4081 "IMS not available on device.");
4082 }
4083 final long token = Binder.clearCallingIdentity();
4084 try {
4085 Phone phone = getPhone(subId);
4086 if (phone == null) {
4087 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4088 + subId + "'");
4089 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4090 }
4091 phone.getImsRegistrationState(regState -> {
4092 try {
4093 consumer.accept((regState == null)
4094 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4095 } catch (RemoteException e) {
4096 // Ignore if the remote process is no longer available to call back.
4097 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4098 }
4099 });
4100 } finally {
4101 Binder.restoreCallingIdentity(token);
4102 }
4103 }
4104
4105 /**
4106 * Get the transport type for the IMS service registration state.
4107 */
4108 @Override
4109 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004110 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004111 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004112 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4113 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4114 "IMS not available on device.");
4115 }
4116 final long token = Binder.clearCallingIdentity();
4117 try {
4118 Phone phone = getPhone(subId);
4119 if (phone == null) {
4120 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4121 + subId + "'");
4122 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4123 }
4124 phone.getImsRegistrationTech(regTech -> {
4125 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4126 int regTechConverted = (regTech == null)
4127 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4128 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4129 regTechConverted);
4130 try {
4131 consumer.accept(regTechConverted);
4132 } catch (RemoteException e) {
4133 // Ignore if the remote process is no longer available to call back.
4134 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4135 }
4136 });
4137 } finally {
4138 Binder.restoreCallingIdentity(token);
4139 }
4140 }
4141
shilu366312e2019-12-17 09:28:10 -08004142 /**
4143 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4144 * @param subId The subscription to use to check the configuration.
4145 * @param c The callback that will be used to send the result.
4146 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004148 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4149 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004150 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004151 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 final long token = Binder.clearCallingIdentity();
4153 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004154 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
4155 manager.addCapabilitiesCallbackForSubscription(c, subId);
4156 return null;
4157 });
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (ImsException e) {
4159 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(token);
4162 }
4163 }
4164
shilu366312e2019-12-17 09:28:10 -08004165 /**
4166 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4167 * @param subId The subscription to use to check the configuration.
4168 * @param c The callback that will be used to send the result.
4169 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004171 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004172 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004173 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4175 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4176 }
Meng Wangafbc5852019-09-19 17:37:13 -07004177
4178 final long token = Binder.clearCallingIdentity();
4179 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004180 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004181 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004182 } catch (ImsException e) {
4183 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4184 + "is inactive, ignoring unregister.");
4185 // If the subscription is no longer active, just return, since the callback
4186 // will already have been removed internally.
4187 } finally {
4188 Binder.restoreCallingIdentity(token);
4189 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 }
4191
4192 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004193 public boolean isCapable(int subId, int capability, int regTech) {
4194 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 final long token = Binder.clearCallingIdentity();
4196 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004197 return runUsingImsManagerOrThrow(subId,
4198 manager -> manager.queryMmTelCapability(capability, regTech));
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004199 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004200 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4201 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 } finally {
4203 Binder.restoreCallingIdentity(token);
4204 }
4205 }
4206
4207 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004208 public boolean isAvailable(int subId, int capability, int regTech) {
4209 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 final long token = Binder.clearCallingIdentity();
4211 try {
4212 Phone phone = getPhone(subId);
4213 if (phone == null) return false;
4214 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004215 } catch (com.android.ims.ImsException e) {
4216 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4217 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 } finally {
4219 Binder.restoreCallingIdentity(token);
4220 }
4221 }
4222
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004223 /**
4224 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4225 * subscription.
4226 * @param subId The subscription to use to check the configuration.
4227 * @param callback The callback that will be used to send the result.
4228 * @param capability The MmTelFeature capability that will be used to send the result.
4229 * @param transportType The transport type of the MmTelFeature capability.
4230 */
4231 @Override
4232 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4233 int transportType) {
4234 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004235 final long token = Binder.clearCallingIdentity();
4236 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004237 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
4238 manager.isSupported(capability, transportType, aBoolean -> {
4239 try {
4240 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4241 } catch (RemoteException e) {
4242 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4243 + "running. Ignore");
4244 }
4245 });
4246 return null;
4247 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004248 } catch (ImsException e) {
4249 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004250 } finally {
4251 Binder.restoreCallingIdentity(token);
4252 }
4253 }
4254
shilu366312e2019-12-17 09:28:10 -08004255 /**
4256 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4257 * @param subId The subscription to use to check the configuration.
4258 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 @Override
4260 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004261 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004262 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004263
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 final long token = Binder.clearCallingIdentity();
4265 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004266 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004267 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004268 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004269 } catch (ImsException e) {
4270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 } finally {
4272 Binder.restoreCallingIdentity(token);
4273 }
4274 }
4275
4276 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004277 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004279 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 final long identity = Binder.clearCallingIdentity();
4281 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004282 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004283 // This setting doesn't require an active ImsService connection, so do not verify. The
4284 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
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(identity);
4290 }
4291 }
4292
shilu366312e2019-12-17 09:28:10 -08004293 /**
4294 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4295 * @param subId The subscription to use to check the configuration.
4296 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004298 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004299 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004300 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 final long identity = Binder.clearCallingIdentity();
4302 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004303 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004304 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004305 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004306 } catch (ImsException e) {
4307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
4311 }
4312
4313 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004314 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004316 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 final long identity = Binder.clearCallingIdentity();
4318 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004320 // This setting doesn't require an active ImsService connection, so do not verify. The
4321 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004330 /**
4331 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4332 * @param subId The subscription to use to check the configuration.
4333 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 @Override
4335 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004336 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004337 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 final long identity = Binder.clearCallingIdentity();
4339 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004340 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004341 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004343 } catch (ImsException e) {
4344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
4350 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004351 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004353 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 final long identity = Binder.clearCallingIdentity();
4355 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004356 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004357 // This setting doesn't require an active ImsService connection, so do not verify. The
4358 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004367 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004368 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4369 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4370 * @param subId The subscription to use to check the configuration.
4371 */
4372 @Override
4373 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004374 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004375 mApp, subId, "isCrossSimCallingEnabledByUser");
4376 final long identity = Binder.clearCallingIdentity();
4377 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004378 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004379 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004380 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004381 } catch (ImsException e) {
4382 throw new ServiceSpecificException(e.getCode());
4383 } finally {
4384 Binder.restoreCallingIdentity(identity);
4385 }
4386 }
4387
4388 /**
4389 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4390 * Requires MODIFY_PHONE_STATE permission.
4391 * @param subId The subscription to use to check the configuration.
4392 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4393 * false otherwise
4394 */
4395 @Override
4396 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4398 "setCrossSimCallingEnabled");
4399 final long identity = Binder.clearCallingIdentity();
4400 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004401 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004402 // This setting doesn't require an active ImsService connection, so do not verify. The
4403 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004404 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004405 } catch (ImsException e) {
4406 throw new ServiceSpecificException(e.getCode());
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
4410 }
4411
4412 /**
shilu366312e2019-12-17 09:28:10 -08004413 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4414 * @param subId The subscription to use to check the configuration.
4415 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004417
Brad Ebinger35c841c2018-10-01 10:40:55 -07004418 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004419 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004420 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 final long identity = Binder.clearCallingIdentity();
4422 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004423 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004424 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004426 } catch (ImsException e) {
4427 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
4431 }
4432
4433 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004434 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004436 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 final long identity = Binder.clearCallingIdentity();
4438 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004439 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004440 // This setting doesn't require an active ImsService connection, so do not verify. The
4441 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
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
4451 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4453 "setVoWiFiNonPersistent");
4454 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 will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004459 } catch (ImsException e) {
4460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
4464 }
4465
shilu366312e2019-12-17 09:28:10 -08004466 /**
4467 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4468 * @param subId The subscription to use to check the configuration.
4469 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 @Override
4471 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004472 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004473 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004474 final long identity = Binder.clearCallingIdentity();
4475 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004476 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004477 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004479 } catch (ImsException e) {
4480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484 }
4485
4486 @Override
4487 public void setVoWiFiModeSetting(int subId, int mode) {
4488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4489 "setVoWiFiModeSetting");
4490 final long identity = Binder.clearCallingIdentity();
4491 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004492 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004493 // This setting doesn't require an active ImsService connection, so do not verify. The
4494 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, 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 int getVoWiFiRoamingModeSetting(int subId) {
4505 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4506 final long identity = Binder.clearCallingIdentity();
4507 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004509 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004511 } catch (ImsException e) {
4512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
4518 @Override
4519 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4521 "setVoWiFiRoamingModeSetting");
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004525 // This setting doesn't require an active ImsService connection, so do not verify. The
4526 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, 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 setRttCapabilitySetting(int subId, boolean isEnabled) {
4537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4538 "setRttCapabilityEnabled");
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).setRttEnabled(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004552 /**
4553 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4554 * @param subId The subscription to use to check the configuration.
4555 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004556 @Override
4557 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004558 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004559 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004560 final long identity = Binder.clearCallingIdentity();
4561 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004562 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004563 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004564 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004565 } catch (ImsException e) {
4566 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
4570 }
4571
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004572 @Override
4573 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4574 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004575
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004576 final long identity = Binder.clearCallingIdentity();
4577 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004578 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
4579 manager.addProvisioningCallbackForSubscription(callback, subId);
4580 return null;
4581 });
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004582 } catch (ImsException e) {
4583 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
4587 }
4588
4589 @Override
4590 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4591 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004592
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4595 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4596 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004597 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004598 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004599 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004600 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004601 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4602 + "is inactive, ignoring unregister.");
4603 // If the subscription is no longer active, just return, since the callback will already
4604 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
4608 }
4609
joonhunshincffb7fc2021-11-28 07:32:01 +00004610 @Override
4611 public void registerFeatureProvisioningChangedCallback(int subId,
4612 IFeatureProvisioningCallback callback) {
4613 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4614 mApp, subId, "registerFeatureProvisioningChangedCallback");
4615
4616 final long identity = Binder.clearCallingIdentity();
4617 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4618 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4619 }
4620
4621 ImsProvisioningController.getInstance()
4622 .addFeatureProvisioningChangedCallback(subId, callback);
4623
4624 Binder.restoreCallingIdentity(identity);
4625 }
4626
4627 @Override
4628 public void unregisterFeatureProvisioningChangedCallback(int subId,
4629 IFeatureProvisioningCallback callback) {
4630 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4631 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4632
4633 final long identity = Binder.clearCallingIdentity();
4634 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4635 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4636 }
4637
4638 ImsProvisioningController.getInstance()
4639 .removeFeatureProvisioningChangedCallback(subId, callback);
4640
4641 Binder.restoreCallingIdentity(identity);
4642 }
allenwtsu99c623b2020-01-03 18:24:23 +08004643
4644 private void checkModifyPhoneStatePermission(int subId, String message) {
4645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4646 message);
4647 }
4648
4649 private boolean isImsProvisioningRequired(int subId, int capability,
4650 boolean isMmtelCapability) {
4651 Phone phone = getPhone(subId);
4652 if (phone == null) {
4653 loge("phone instance null for subid " + subId);
4654 return false;
4655 }
4656 if (isMmtelCapability) {
4657 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4658 return false;
4659 }
4660 } else {
4661 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4662 return false;
4663 }
4664 }
4665 return true;
4666 }
4667
4668 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004669 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004670 boolean isProvisioned) {
4671 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4672
4673 final long identity = Binder.clearCallingIdentity();
4674 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004675 ImsProvisioningController.getInstance()
4676 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4677 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004678 } finally {
4679 Binder.restoreCallingIdentity(identity);
4680 }
allenwtsu99c623b2020-01-03 18:24:23 +08004681 }
4682
4683
4684 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004685 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4686 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4687 mApp, subId, "getRcsProvisioningStatusForCapability");
4688
allenwtsu99c623b2020-01-03 18:24:23 +08004689 final long identity = Binder.clearCallingIdentity();
4690 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004691 return ImsProvisioningController.getInstance()
4692 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
4696 }
4697
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004698 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004699 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4700 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004701 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004702
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004703 final long identity = Binder.clearCallingIdentity();
4704 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004705 ImsProvisioningController.getInstance()
4706 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 } finally {
4708 Binder.restoreCallingIdentity(identity);
4709 }
4710 }
4711
4712 @Override
4713 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004714 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4715 mApp, subId, "getProvisioningStatusForCapability");
4716
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004719 return ImsProvisioningController.getInstance()
4720 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
4725 }
4726
4727 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004728 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4729 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4730 mApp, subId, "isProvisioningRequiredForCapability");
4731
4732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 return ImsProvisioningController.getInstance()
4735 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004739 }
4740
4741 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004742 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4743 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4744 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745
joonhunshincffb7fc2021-11-28 07:32:01 +00004746 final long identity = Binder.clearCallingIdentity();
4747 try {
4748 return ImsProvisioningController.getInstance()
4749 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004753 }
4754
4755 private static String getMmTelProvisioningKey(int subId, int tech) {
4756 // resulting key is provision_ims_mmtel_{subId}_{tech}
4757 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4758 }
4759
4760 /**
4761 * Query CarrierConfig to see if the specified capability requires provisioning for the
4762 * carrier associated with the subscription id.
4763 */
4764 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4765 int capability) {
4766 CarrierConfigManager configManager = new CarrierConfigManager(context);
4767 PersistableBundle c = configManager.getConfigForSubId(subId);
4768 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004769 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004770 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4771 false);
4772 boolean requireVoiceVtProvisioning = c.getBoolean(
4773 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4774
4775 // First check to make sure that the capability requires provisioning.
4776 switch (capability) {
4777 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4778 // intentional fallthrough
4779 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4780 if (requireVoiceVtProvisioning) {
4781 // Voice and Video requires provisioning
4782 return true;
4783 }
4784 break;
4785 }
4786 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4787 if (requireUtProvisioning) {
4788 // UT requires provisioning
4789 return true;
4790 }
4791 break;
4792 }
4793 }
4794 return false;
4795 }
4796
allenwtsu99c623b2020-01-03 18:24:23 +08004797 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4798 int capability) {
4799 CarrierConfigManager configManager = new CarrierConfigManager(context);
4800 PersistableBundle c = configManager.getConfigForSubId(subId);
4801
4802 boolean requireRcsProvisioning = c.getBoolean(
4803 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4804
4805 // First check to make sure that the capability requires provisioning.
4806 switch (capability) {
4807 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4808 // intentional fallthrough
4809 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4810 if (requireRcsProvisioning) {
4811 // OPTION or PRESENCE requires provisioning
4812 return true;
4813 }
4814 break;
4815 }
4816 }
4817 return false;
4818 }
4819
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004820 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004821 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004822 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4823 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4824 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004825 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4826 mApp, subId, "getImsProvisioningInt");
4827
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004828 final long identity = Binder.clearCallingIdentity();
4829 try {
4830 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 int slotId = getSlotIndex(subId);
4832 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4833 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4834 + subId + "' for key:" + key);
4835 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4836 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004837
4838 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4839 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4840 return retVal;
4841 }
4842
calvinpanb5a34062021-02-08 19:59:36 +08004843 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004844 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004845 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4846 + subId + "' for key:" + key);
4847 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
4851 }
4852
4853 @Override
4854 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4856 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4857 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004858 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4859 mApp, subId, "getImsProvisioningString");
4860
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004864 int slotId = getSlotIndex(subId);
4865 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4866 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4867 + subId + "' for key:" + key);
4868 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4869 }
calvinpanb5a34062021-02-08 19:59:36 +08004870 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004871 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004872 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4873 + subId + "' for key:" + key);
4874 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004875 } finally {
4876 Binder.restoreCallingIdentity(identity);
4877 }
4878 }
4879
4880 @Override
4881 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004882 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4883 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4884 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4886 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004887
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004891 int slotId = getSlotIndex(subId);
4892 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4893 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4894 + subId + "' for key:" + key);
4895 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4896 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004897
4898 int retVal = ImsProvisioningController.getInstance()
4899 .setProvisioningValue(subId, key, value);
4900 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4901 return retVal;
4902 }
4903
calvinpanb5a34062021-02-08 19:59:36 +08004904 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4905 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004906 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004907 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004908 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
4912 }
4913
4914 @Override
4915 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4917 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4918 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4920 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 int slotId = getSlotIndex(subId);
4925 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4926 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4927 + subId + "' for key:" + key);
4928 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4929 }
calvinpanb5a34062021-02-08 19:59:36 +08004930 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4931 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004933 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004934 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
4938 }
4939
Brad Ebinger919631e2021-06-02 17:46:35 -07004940 /**
4941 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4942 * for the given slot ID or no ImsResolver instance has been created.
4943 * @param slotId The slot ID that the IMS service is created for.
4944 * @throws ImsException If there is no ImsService configured for this slot.
4945 */
4946 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4947 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4948 ImsFeature.FEATURE_MMTEL)) {
4949 throw new ImsException("This subscription does not support MMTEL over IMS",
4950 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4951 }
4952 }
4953
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004954 //
4955
4956 /**
4957 * Functional interface for encapsulating IMS related commands that should be sent to
4958 * ImsManager for processing.
4959 * @param <V> The return type
4960 */
4961 private interface ImsFunction<V> {
4962 V call(ImsManager manager) throws Exception;
4963 }
4964
4965 /**
4966 * Run the specified command on the ImsManager for the subscription specified or throw an
4967 * {@link ImsException} if the IMS is not available for any reason.
4968 * @param subId The subscription to use
4969 * @param func The function to run on the given ImsManager instance.
4970 * @param <V> The return type of the function
4971 * @return The result of the evaluated command
4972 * @throws ImsException if the IMS service is not available for any reason.
4973 */
4974 private <V> V runUsingImsManagerOrThrow(int subId, ImsFunction<V> func) throws ImsException {
4975 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4976 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4977 "IMS not available on device.");
4978 }
4979 int slotId = getSlotIndexOrException(subId);
4980 verifyImsMmTelConfiguredOrThrow(slotId);
4981 ImsManager manager = ImsManager.getInstance(mApp, slotId);
4982 if (manager.getSubId() != subId || !manager.isServiceReady()) {
4983 Log.w(LOG_TAG, "getImsManagerForSubIdOrThrow: couldn't resolve ImsManager, ready= "
4984 + manager.isServiceReady() + ", manager subId= " + manager.getSubId()
4985 + ", request subId= " + subId);
4986 // if we have hit this point, getSlotIndexOrException has already checked that the subId
4987 // is active for a phone, but ImsManager currently doesn't have the correct subId set or
4988 // the ImsService has crashed/is not ready. The caller will have to wait for the service
4989 // to be available before calling again.
4990 throw new ImsException("The ImsService is not available for the subId specified.",
4991 ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4992 }
4993 try {
4994 return func.call(manager);
4995 } catch (Exception e) {
4996 // Some methods internally report RuntimeExceptions. Repackage those exceptions as well
4997 // defined ImsExceptions.
4998 throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4999 }
5000 }
5001
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005002 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005003 int slotId = SubscriptionManager.getSlotIndex(subId);
5004 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005005 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5006 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005007 }
5008 return slotId;
5009 }
5010
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005011 private int getSlotIndex(int subId) {
5012 int slotId = SubscriptionManager.getSlotIndex(subId);
5013 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5014 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5015 }
5016 return slotId;
5017 }
5018
Wink Saville36469e72014-06-11 15:17:00 -07005019 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005020 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005021 */
5022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005023 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5024 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005025 try {
5026 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5027 } catch (SecurityException se) {
5028 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5029 throw new SecurityException("Package " + callingPackage + " does not belong to "
5030 + Binder.getCallingUid());
5031 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005032 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005033 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005034 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005035 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005036 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005037 mApp, subId, callingPackage, callingFeatureId,
5038 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005039 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5040 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 final Phone phone = getPhone(subId);
5045 if (phone != null) {
5046 return phone.getServiceState().getDataNetworkType();
5047 } else {
5048 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5049 }
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005053 }
5054
5055 /**
5056 * Returns the data network type
5057 */
5058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005059 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005060 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5061 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005062 }
5063
5064 /**
5065 * Returns the data network type for a subId
5066 */
5067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005068 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5069 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005070 String functionName = "getDataNetworkTypeForSubscriber";
5071 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5072 mApp, functionName)) {
5073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5074 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5075 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5076 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005077 }
5078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
5081 final Phone phone = getPhone(subId);
5082 if (phone != null) {
5083 return phone.getServiceState().getDataNetworkType();
5084 } else {
5085 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5086 }
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005090 }
5091
5092 /**
Wink Saville36469e72014-06-11 15:17:00 -07005093 * Returns the Voice network type for a subId
5094 */
5095 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005096 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5097 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005098 String functionName = "getVoiceNetworkTypeForSubscriber";
5099 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5100 mApp, functionName)) {
5101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5102 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5103 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5104 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005105 }
5106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 final Phone phone = getPhone(subId);
5110 if (phone != null) {
5111 return phone.getServiceState().getVoiceNetworkType();
5112 } else {
5113 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5114 }
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005118 }
5119
5120 /**
5121 * @return true if a ICC card is present
5122 */
5123 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005124 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005125 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5126 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005127 }
5128
5129 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005130 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005131 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005132 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005133 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 final Phone phone = PhoneFactory.getPhone(slotIndex);
5137 if (phone != null) {
5138 return phone.getIccCard().hasIccCard();
5139 } else {
5140 return false;
5141 }
5142 } finally {
5143 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005145 }
5146
5147 /**
5148 * Return if the current radio is LTE on CDMA. This
5149 * is a tri-state return value as for a period of time
5150 * the mode may be unknown.
5151 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005152 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005153 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005154 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005155 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005157 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5158 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5159 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005160 }
5161
Sanket Padawe356d7632015-06-22 14:03:32 -07005162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005163 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5164 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005165 try {
5166 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5167 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005168 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5169 }
5170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
5173 final Phone phone = getPhone(subId);
5174 if (phone == null) {
5175 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5176 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005177 return TelephonyProperties.lte_on_cdma_device()
5178 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 }
5180 } finally {
5181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005182 }
Wink Saville36469e72014-06-11 15:17:00 -07005183 }
5184
Wink Saville36469e72014-06-11 15:17:00 -07005185 /**
5186 * {@hide}
5187 * Returns Default subId, 0 in the case of single standby.
5188 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005189 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005190 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005191 }
5192
Shishir Agrawala9f32182016-04-12 12:00:16 -07005193 private int getSlotForDefaultSubscription() {
5194 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5195 }
5196
Wink Savilleb564aae2014-10-23 10:18:09 -07005197 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005198 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005199 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005200
Pengquan Menge92a50d2018-09-21 15:54:48 -07005201 private boolean isActiveSubscription(int subId) {
5202 return mSubscriptionController.isActiveSubId(subId);
5203 }
5204
Ihab Awadf2177b72013-11-25 13:33:23 -08005205 /**
5206 * @see android.telephony.TelephonyManager.WifiCallingChoices
5207 */
5208 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 final long identity = Binder.clearCallingIdentity();
5210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005211 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5213 getWhenToMakeWifiCallsDefaultPreference());
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005217 }
5218
5219 /**
5220 * @see android.telephony.TelephonyManager.WifiCallingChoices
5221 */
5222 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005226 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005231 }
5232
Sailesh Nepald1e68152013-12-12 19:08:02 -08005233 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005234 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005235 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005236 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005237
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005238 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5239 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5240 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005241 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005242 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5243 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005244 }
5245 return PhoneFactory.getPhone(phoneId);
5246 }
5247
Shishir Agrawal566b7612013-10-28 14:41:00 -07005248 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005249 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005250 @NonNull IccLogicalChannelRequest request) {
5251 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5252 /*message=*/ "iccOpenLogicalChannel");
5253
5254 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5255 // Verify that the callingPackage in the request belongs to the calling UID
5256 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5257
5258 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005259 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005260
Rambo Wanga1782702021-11-10 20:15:19 -08005261 private Phone getPhoneFromValidIccLogicalChannelRequest(
5262 @NonNull IccLogicalChannelRequest request, String message) {
5263 Phone phone;
5264 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5266 mApp, request.subId, message);
5267 phone = getPhoneFromSubId(request.subId);
5268 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5269 enforceModifyPermission();
5270 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5271 } else {
5272 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005273 }
Rambo Wanga1782702021-11-10 20:15:19 -08005274 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005275 }
5276
5277 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005278 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005281 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005283 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5284 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005285 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5286 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 loge("The calling package is not allowed to access ISD-R.");
5288 throw new SecurityException(
5289 "The calling package is not allowed to access ISD-R.");
5290 }
Derek Tan740e1672017-06-27 14:56:27 -07005291 }
Derek Tan740e1672017-06-27 14:56:27 -07005292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005294 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5295 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 return response;
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
5299 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005300 }
5301
5302 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005303 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5304 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5305 /*message=*/"iccCloseLogicalChannel");
5306
5307 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5308
5309 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005310 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005311
Rambo Wanga1782702021-11-10 20:15:19 -08005312 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5313 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005314 // before this feature is enabled, this API should only return false if
5315 // the operation fails instead of throwing runtime exception for
5316 // backward-compatibility.
5317 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5318 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 final long identity = Binder.clearCallingIdentity();
5320 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005321 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005322 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 }
Chen Xue9d737e2022-01-01 23:41:31 -08005324 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005325 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005326 Boolean success = false;
5327 if (result instanceof RuntimeException) {
5328 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005329 if (shouldThrowExceptionOnFailure) {
5330 throw (RuntimeException) result;
5331 } else {
5332 return false;
5333 }
Chen Xue9d737e2022-01-01 23:41:31 -08005334 } else if (result instanceof Boolean) {
5335 success = (Boolean) result;
5336 } else {
5337 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5338 }
Rambo Wanga1782702021-11-10 20:15:19 -08005339 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 return success;
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005343 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005344 }
5345
5346 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005347 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005348 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5350 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005351 if (DBG) {
5352 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5353 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5354 + p3 + " data=" + data);
5355 }
5356 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5357 command, p1, p2, p3, data);
5358 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005359
Jordan Liu4c733742019-02-28 12:03:40 -08005360 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005361 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5362 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005363 enforceModifyPermission();
5364 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005365 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5366 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5367 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005368 }
5369 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005370 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5371 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005372 }
5373
5374 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5375 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005378 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 return "";
5380 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005383 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5384 null /* workSource */);
5385 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387 // Append the returned status code to the end of the response payload.
5388 String s = Integer.toHexString(
5389 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5390 if (response.payload != null) {
5391 s = IccUtils.bytesToHexString(response.payload) + s;
5392 }
5393 return s;
5394 } finally {
5395 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005396 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005397 }
Jake Hambye994d462014-02-03 13:10:13 -08005398
Evan Charltonc66da362014-05-16 14:06:40 -07005399 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005400 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5401 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5403 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005405 if (DBG) {
5406 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5407 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5408 }
5409 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5410 cla, command, p1, p2, p3, data);
5411 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005412
Jordan Liu4c733742019-02-28 12:03:40 -08005413 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005414 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5415 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005416 enforceModifyPermission();
5417 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5418 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005419 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5420 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5421 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005422 }
5423
5424 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005425 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5426 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005427 }
5428
5429 // open APDU basic channel assuming the caller has sufficient permissions
5430 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5431 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
5434 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5435 && TextUtils.equals(ISDR_AID, data)) {
5436 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005437 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5438 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 if (bestComponent == null
5440 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5441 loge("The calling package is not allowed to select ISD-R.");
5442 throw new SecurityException(
5443 "The calling package is not allowed to select ISD-R.");
5444 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005445 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005448 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5449 null /* workSource */);
5450 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 // Append the returned status code to the end of the response payload.
5453 String s = Integer.toHexString(
5454 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5455 if (response.payload != null) {
5456 s = IccUtils.bytesToHexString(response.payload) + s;
5457 }
5458 return s;
5459 } finally {
5460 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005461 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005462 }
5463
5464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005465 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005466 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5468 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 final long identity = Binder.clearCallingIdentity();
5471 try {
5472 if (DBG) {
5473 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5474 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5475 }
5476
5477 IccIoResult response =
5478 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5479 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5480 subId);
5481
5482 if (DBG) {
5483 log("Exchange SIM_IO [R]" + response);
5484 }
5485
5486 byte[] result = null;
5487 int length = 2;
5488 if (response.payload != null) {
5489 length = 2 + response.payload.length;
5490 result = new byte[length];
5491 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5492 } else {
5493 result = new byte[length];
5494 }
5495
5496 result[length - 1] = (byte) response.sw2;
5497 result[length - 2] = (byte) response.sw1;
5498 return result;
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005501 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005502 }
5503
Nathan Haroldb3014052017-01-25 15:57:32 -08005504 /**
5505 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5506 * on a particular subscription
5507 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005508 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5509 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005511 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005512 return null;
5513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 if (appType != TelephonyManager.APPTYPE_USIM
5518 && appType != TelephonyManager.APPTYPE_SIM) {
5519 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5520 return null;
5521 }
5522 Object response = sendRequest(
5523 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5524 if (response instanceof String[]) {
5525 return (String[]) response;
5526 }
yincheng zhao2737e882019-09-06 17:06:54 -07005527 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005529 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005532 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005533 }
5534
yincheng zhao2737e882019-09-06 17:06:54 -07005535 /**
5536 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5537 * subscription.
5538 *
5539 * @param subId the id of the subscription.
5540 * @param appType the uicc app type, must be USIM or SIM.
5541 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5542 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005543 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005544 * @return number of fplmns that is successfully written to the SIM.
5545 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005546 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5547 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5549 mApp, subId, "setForbiddenPlmns");
5550
yincheng zhao2737e882019-09-06 17:06:54 -07005551 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5552 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5553 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5554 }
5555 if (fplmns == null) {
5556 throw new IllegalArgumentException("Fplmn List provided is null");
5557 }
5558 for (String fplmn : fplmns) {
5559 if (!CellIdentity.isValidPlmn(fplmn)) {
5560 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5561 }
5562 }
5563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 Object response = sendRequest(
5566 CMD_SET_FORBIDDEN_PLMNS,
5567 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5568 subId);
5569 return (int) response;
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
5573 }
5574
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005575 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005576 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5578 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5583 if (response.payload == null) {
5584 return "";
5585 }
Evan Charltonc66da362014-05-16 14:06:40 -07005586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 // Append the returned status code to the end of the response payload.
5588 String s = Integer.toHexString(
5589 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5590 s = IccUtils.bytesToHexString(response.payload) + s;
5591 return s;
5592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
Evan Charltonc66da362014-05-16 14:06:40 -07005595 }
5596
Jake Hambye994d462014-02-03 13:10:13 -08005597 /**
5598 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5599 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5600 *
5601 * @param itemID the ID of the item to read
5602 * @return the NV item as a String, or null on error.
5603 */
5604 @Override
5605 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005606 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5608 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609
5610 final long identity = Binder.clearCallingIdentity();
5611 try {
5612 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005613 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5615 return value;
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
5618 }
Jake Hambye994d462014-02-03 13:10:13 -08005619 }
5620
5621 /**
5622 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5623 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5624 *
5625 * @param itemID the ID of the item to read
5626 * @param itemValue the value to write, as a String
5627 * @return true on success; false on any failure
5628 */
5629 @Override
5630 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005631 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5633 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634
5635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5638 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005639 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5641 return success;
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Jake Hambye994d462014-02-03 13:10:13 -08005645 }
5646
5647 /**
5648 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5649 * Used for device configuration by some CDMA operators.
5650 *
5651 * @param preferredRoamingList byte array containing the new PRL
5652 * @return true on success; false on any failure
5653 */
5654 @Override
5655 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5657 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5662 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5663 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5664 return success;
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
Jake Hambye994d462014-02-03 13:10:13 -08005668 }
5669
5670 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005671 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005672 * Used for device configuration by some CDMA operators.
5673 *
chen xu6dac5ab2018-10-26 17:39:23 -07005674 * @param slotIndex - device slot.
5675 *
Jake Hambye994d462014-02-03 13:10:13 -08005676 * @return true on success; false on any failure
5677 */
5678 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005679 public boolean resetModemConfig(int slotIndex) {
5680 Phone phone = PhoneFactory.getPhone(slotIndex);
5681 if (phone != null) {
5682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5683 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684
chen xu6dac5ab2018-10-26 17:39:23 -07005685 final long identity = Binder.clearCallingIdentity();
5686 try {
5687 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5688 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5689 return success;
5690 } finally {
5691 Binder.restoreCallingIdentity(identity);
5692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 }
chen xu6dac5ab2018-10-26 17:39:23 -07005694 return false;
5695 }
5696
5697 /**
5698 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5699 *
5700 * @param slotIndex - device slot.
5701 *
5702 * @return true on success; false on any failure
5703 */
5704 @Override
5705 public boolean rebootModem(int slotIndex) {
5706 Phone phone = PhoneFactory.getPhone(slotIndex);
5707 if (phone != null) {
5708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5709 mApp, phone.getSubId(), "rebootModem");
5710
5711 final long identity = Binder.clearCallingIdentity();
5712 try {
5713 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5714 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5715 return success;
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
5719 }
5720 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005721 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005722
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005723 public String[] getPcscfAddress(String apnType, String callingPackage,
5724 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5727 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005728 return new String[0];
5729 }
5730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005733 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
Wink Saville36469e72014-06-11 15:17:00 -07005737 }
5738
Brad Ebinger51f743a2017-01-23 13:50:20 -08005739 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005740 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5741 * {@link #disableIms(int)}.
5742 * @param slotIndex device slot.
5743 */
5744 public void resetIms(int slotIndex) {
5745 enforceModifyPermission();
5746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 if (mImsResolver == null) {
5750 // may happen if the does not support IMS.
5751 return;
5752 }
5753 mImsResolver.disableIms(slotIndex);
5754 mImsResolver.enableIms(slotIndex);
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
5758 }
5759
5760 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5762 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005763 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005764 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005765 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005769 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005770 // may happen if the device does not support IMS.
5771 return;
5772 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005773 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005777 }
5778
5779 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005780 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5781 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005782 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005783 public void disableIms(int slotId) {
5784 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785
5786 final long identity = Binder.clearCallingIdentity();
5787 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005788 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005789 // may happen if the device does not support IMS.
5790 return;
5791 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005792 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005796 }
5797
5798 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005799 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5800 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005801 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005802 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005803 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005808 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005809 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5810 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005811 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005812 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005816 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005817 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005818 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5819 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005820 @Override
5821 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005822 enforceModifyPermission();
5823
5824 final long identity = Binder.clearCallingIdentity();
5825 try {
5826 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005827 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
5831 }
5832
5833 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005834 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005835 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005836 */
5837 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839
5840 final long identity = Binder.clearCallingIdentity();
5841 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005843 // may happen if the device does not support IMS.
5844 return null;
5845 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005846 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005850 }
5851
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005852 /**
5853 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005854 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005855 */
5856 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005862 // may happen if the device does not support IMS.
5863 return null;
5864 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005865 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 } finally {
5867 Binder.restoreCallingIdentity(identity);
5868 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005869 }
5870
Brad Ebinger884c07b2018-02-15 16:17:40 -08005871 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005872 * Sets the ImsService Package Name that Telephony will bind to.
5873 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 * @param slotIndex the slot ID that the ImsService should bind for.
5875 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005876 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 * @param featureTypes An integer array of feature types associated with a packageName.
5878 * @param packageName The name of the package that the current configuration will be replaced
5879 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005880 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005881 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5883 int[] featureTypes, String packageName) {
5884 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5885 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5887 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005888 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 final long identity = Binder.clearCallingIdentity();
5891 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005892 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005893 // may happen if the device does not support IMS.
5894 return false;
5895 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005896 Map<Integer, String> featureConfig = new HashMap<>();
5897 for (int featureType : featureTypes) {
5898 featureConfig.put(featureType, packageName);
5899 }
5900 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5901 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005905 }
5906
5907 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005908 * Clears any carrier ImsService overrides for the slot index specified that were previously
5909 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5910 *
5911 * This should only be used for testing.
5912 *
5913 * @param slotIndex the slot ID that the ImsService should bind for.
5914 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5915 */
5916 @Override
5917 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5918 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5920 "clearCarrierImsServiceOverride");
5921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5922 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5923 "clearCarrierImsServiceOverride");
5924
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
5927 if (mImsResolver == null) {
5928 // may happen if the device does not support IMS.
5929 return false;
5930 }
5931 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
5935 }
5936
5937 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005939 *
5940 * @param slotId The slot that the ImsService is associated with.
5941 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5942 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005943 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005944 * @return the package name of the ImsService configuration.
5945 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005946 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5947 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005948 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005949 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005950 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5952 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 final long identity = Binder.clearCallingIdentity();
5955 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005956 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005957 // may happen if the device does not support IMS.
5958 return "";
5959 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005960 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005961 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5962 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005966 }
5967
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005968 /**
5969 * Get the MmTelFeature state associated with the requested subscription id.
5970 * @param subId The subscription that the MmTelFeature is associated with.
5971 * @param callback A callback with an integer containing the
5972 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5973 */
5974 @Override
5975 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5976 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005977 final long token = Binder.clearCallingIdentity();
5978 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08005979 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
5980 manager.getImsServiceState(anInteger -> {
5981 try {
5982 callback.accept(anInteger == null
5983 ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5984 } catch (RemoteException e) {
5985 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer "
5986 + "running. Ignore");
5987 }
5988 });
5989 return null;
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005990 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005991 } catch (ImsException e) {
5992 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005993 } finally {
5994 Binder.restoreCallingIdentity(token);
5995 }
5996 }
5997
Daniel Brightbb5840b2021-01-12 15:48:18 -08005998 /**
5999 * Sets the ims registration state on all valid {@link Phone}s.
6000 */
6001 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 final long identity = Binder.clearCallingIdentity();
6005 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006006 // NOTE: Before S, this method only set the default phone.
6007 for (final Phone phone : PhoneFactory.getPhones()) {
6008 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6009 phone.setImsRegistrationState(registered);
6010 }
6011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
Wink Saville36469e72014-06-11 15:17:00 -07006015 }
6016
6017 /**
Stuart Scott54788802015-03-30 13:18:01 -07006018 * Set the network selection mode to automatic.
6019 *
6020 */
6021 @Override
6022 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6024 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
shilufc958392020-01-20 11:36:01 -08006028 if (!isActiveSubscription(subId)) {
6029 return;
6030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006032 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6033 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
Stuart Scott54788802015-03-30 13:18:01 -07006037 }
6038
Jack Yud10cdd42020-09-28 20:28:01 -07006039 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006040 * Ask the radio to connect to the input network and change selection mode to manual.
6041 *
6042 * @param subId the id of the subscription.
6043 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6044 * the operator to attach to.
6045 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6046 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6047 * normal network selection next time.
6048 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006049 */
6050 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006051 public boolean setNetworkSelectionModeManual(
6052 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6054 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006055
6056 if (!isActiveSubscription(subId)) {
6057 return false;
6058 }
6059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 final long identity = Binder.clearCallingIdentity();
6061 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006062 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006064 if (DBG) {
6065 log("setNetworkSelectionModeManual: subId: " + subId
6066 + " operator: " + operatorInfo);
6067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6069 } finally {
6070 Binder.restoreCallingIdentity(identity);
6071 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006072 }
shilu84f6e8b2019-12-19 13:58:01 -08006073 /**
6074 * Get the manual network selection
6075 *
6076 * @param subId the id of the subscription.
6077 *
6078 * @return the previously saved user selected PLMN
6079 */
6080 @Override
6081 public String getManualNetworkSelectionPlmn(int subId) {
6082 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006083 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006084 mApp, subId, "getManualNetworkSelectionPlmn");
6085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006089 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006090 }
6091
6092 final Phone phone = getPhone(subId);
6093 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006094 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006095 }
6096 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6097 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6098 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
6102 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006103
6104 /**
6105 * Scans for available networks.
6106 */
6107 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006108 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6111 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006112 LocationAccessPolicy.LocationPermissionResult locationResult =
6113 LocationAccessPolicy.checkLocationPermission(mApp,
6114 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6115 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006116 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006117 .setCallingPid(Binder.getCallingPid())
6118 .setCallingUid(Binder.getCallingUid())
6119 .setMethod("getCellNetworkScanResults")
6120 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006121 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6122 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006123 .build());
6124 switch (locationResult) {
6125 case DENIED_HARD:
6126 throw new SecurityException("Not allowed to access scan results -- location");
6127 case DENIED_SOFT:
6128 return null;
6129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130
Pengquan Menga1bb6272018-09-06 09:59:22 -07006131 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 try {
6133 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006134 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006139 }
6140
6141 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006142 * Get the call forwarding info, given the call forwarding reason.
6143 */
6144 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006145 public void getCallForwarding(int subId, int callForwardingReason,
6146 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006147 enforceReadPrivilegedPermission("getCallForwarding");
6148 long identity = Binder.clearCallingIdentity();
6149 try {
6150 if (DBG) {
6151 log("getCallForwarding: subId " + subId
6152 + " callForwardingReason" + callForwardingReason);
6153 }
Hall Liu27d24262020-09-18 19:04:59 -07006154
6155 Phone phone = getPhone(subId);
6156 if (phone == null) {
6157 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006158 callback.onError(
6159 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006160 } catch (RemoteException e) {
6161 // ignore
6162 }
6163 return;
6164 }
6165
6166 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6167 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6168 @Override
6169 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6170 try {
6171 callback.onCallForwardingInfoAvailable(info);
6172 } catch (RemoteException e) {
6173 // ignore
6174 }
6175 }
6176
6177 @Override
6178 public void onError(int error) {
6179 try {
6180 callback.onError(error);
6181 } catch (RemoteException e) {
6182 // ignore
6183 }
6184 }
6185 });
6186 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
6193 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6194 * reason, the number to forward, and the timeout before the forwarding is attempted.
6195 */
6196 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006197 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6198 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006199 enforceModifyPermission();
6200 long identity = Binder.clearCallingIdentity();
6201 try {
6202 if (DBG) {
6203 log("setCallForwarding: subId " + subId
6204 + " callForwardingInfo" + callForwardingInfo);
6205 }
Hall Liu27d24262020-09-18 19:04:59 -07006206
6207 Phone phone = getPhone(subId);
6208 if (phone == null) {
6209 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006210 callback.accept(
6211 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006212 } catch (RemoteException e) {
6213 // ignore
6214 }
6215 return;
6216 }
6217
6218 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6219 FunctionalUtils.ignoreRemoteException(callback::accept));
6220
6221 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224 }
6225 }
6226
6227 /**
Hall Liu27d24262020-09-18 19:04:59 -07006228 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006229 */
6230 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006231 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006232 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006233 long identity = Binder.clearCallingIdentity();
6234 try {
Hall Liu27d24262020-09-18 19:04:59 -07006235 Phone phone = getPhone(subId);
6236 if (phone == null) {
6237 try {
6238 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6239 } catch (RemoteException e) {
6240 // ignore
6241 }
6242 return;
6243 }
SongFerngWang0e767992021-03-31 22:08:45 +08006244 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6245 PersistableBundle c = configManager.getConfigForSubId(subId);
6246 boolean requireUssd = c.getBoolean(
6247 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006248
Shuo Qian4a594052020-01-23 11:59:30 -08006249 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006250 if (requireUssd) {
6251 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6252 getSubscriptionCarrierId(subId));
6253 String newUssdCommand = "";
6254 try {
6255 newUssdCommand = carrierXmlParser.getFeature(
6256 CarrierXmlParser.FEATURE_CALL_WAITING)
6257 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6258 } catch (NullPointerException e) {
6259 loge("Failed to generate USSD number" + e);
6260 }
6261 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6262 mMainThreadHandler, callback, carrierXmlParser,
6263 CarrierXmlParser.SsEntry.SSAction.QUERY);
6264 final String ussdCommand = newUssdCommand;
6265 Executors.newSingleThreadExecutor().execute(() -> {
6266 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6267 });
6268 } else {
6269 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6270 callback::accept);
6271 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6272 }
Shuo Qian4a594052020-01-23 11:59:30 -08006273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
6276 }
6277
6278 /**
Hall Liu27d24262020-09-18 19:04:59 -07006279 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006280 */
6281 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006282 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006283 enforceModifyPermission();
6284 long identity = Binder.clearCallingIdentity();
6285 try {
Hall Liu27d24262020-09-18 19:04:59 -07006286 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6287
6288 Phone phone = getPhone(subId);
6289 if (phone == null) {
6290 try {
6291 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6292 } catch (RemoteException e) {
6293 // ignore
6294 }
6295 return;
6296 }
6297
SongFerngWang0e767992021-03-31 22:08:45 +08006298 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6299 PersistableBundle c = configManager.getConfigForSubId(subId);
6300 boolean requireUssd = c.getBoolean(
6301 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006302
SongFerngWang0e767992021-03-31 22:08:45 +08006303 if (DBG) log("getCallWaitingStatus: subId " + subId);
6304 if (requireUssd) {
6305 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6306 getSubscriptionCarrierId(subId));
6307 CarrierXmlParser.SsEntry.SSAction ssAction =
6308 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6309 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6310 String newUssdCommand = "";
6311 try {
6312 newUssdCommand = carrierXmlParser.getFeature(
6313 CarrierXmlParser.FEATURE_CALL_WAITING)
6314 .makeCommand(ssAction, null);
6315 } catch (NullPointerException e) {
6316 loge("Failed to generate USSD number" + e);
6317 }
6318 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6319 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6320 final String ussdCommand = newUssdCommand;
6321 Executors.newSingleThreadExecutor().execute(() -> {
6322 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6323 });
6324 } else {
6325 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6326 FunctionalUtils.ignoreRemoteException(callback::accept));
6327
6328 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6329 }
Shuo Qian4a594052020-01-23 11:59:30 -08006330 } finally {
6331 Binder.restoreCallingIdentity(identity);
6332 }
6333 }
6334
6335 /**
yinxub1bed742017-04-17 11:45:04 -07006336 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006337 *
yinxub1bed742017-04-17 11:45:04 -07006338 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006339 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6340 * location related information which will be sent if the caller already possess
6341 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006342 * @param request contains the radio access networks with bands/channels to scan
6343 * @param messenger callback messenger for scan results or errors
6344 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006345 * @return the id of the requested scan which can be used to stop the scan.
6346 */
6347 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006348 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6349 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006350 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6352 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006353 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006354 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6355 if (!renounceFineLocationAccess) {
6356 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6357 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6358 .setCallingPackage(callingPackage)
6359 .setCallingFeatureId(callingFeatureId)
6360 .setCallingPid(Binder.getCallingPid())
6361 .setCallingUid(Binder.getCallingUid())
6362 .setMethod("requestNetworkScan")
6363 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6364 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6365 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6366 .build());
6367 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006368 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006369 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6370 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006371 if (e != null) {
6372 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6373 throw e;
6374 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006375 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006376 return TelephonyScanManager.INVALID_SCAN_ID;
6377 }
6378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 }
Hall Liu912dfd32019-04-25 14:02:26 -07006380 int callingUid = Binder.getCallingUid();
6381 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006382 final long identity = Binder.clearCallingIdentity();
6383 try {
6384 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006385 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006386 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
yinxu504e1392017-04-12 16:03:22 -07006390 }
6391
Hall Liub2ac8ef2019-02-28 15:56:23 -08006392 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006393 NetworkScanRequest request, int subId, String callingPackage) {
6394 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006395 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6396 boolean hasNetworkScanPermission =
6397 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6398 == PERMISSION_GRANTED;
6399
6400 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6401 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6402 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006403 }
6404
6405 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6406 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006407 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6408 return new SecurityException("Specific channels must not be"
6409 + " scanned without location access.");
6410 }
6411 }
6412 }
6413
Hall Liub2ac8ef2019-02-28 15:56:23 -08006414 return null;
6415 }
6416
yinxu504e1392017-04-12 16:03:22 -07006417 /**
6418 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006419 *
6420 * @param subId id of the subscription
6421 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006422 */
6423 @Override
6424 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6426 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427
Hall Liu912dfd32019-04-25 14:02:26 -07006428 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 final long identity = Binder.clearCallingIdentity();
6430 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006431 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
yinxu504e1392017-04-12 16:03:22 -07006435 }
6436
6437 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006438 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006439 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006440 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006441 */
6442 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006443 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006444 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006445 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006446 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006450 if (DBG) log("getAllowedNetworkTypesBitmask");
6451 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6452 int networkTypesBitmask = (result != null ? result[0] : -1);
6453 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6454 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006458 }
6459
6460 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006461 * Get the allowed network types for certain reason.
6462 *
6463 * @param subId the id of the subscription.
6464 * @param reason the reason the allowed network type change is taking place
6465 * @return the allowed network types.
6466 */
6467 @Override
6468 public long getAllowedNetworkTypesForReason(int subId,
6469 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006470 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006471 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6475 } finally {
6476 Binder.restoreCallingIdentity(identity);
6477 }
6478 }
6479
6480 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006481 * Enable/Disable E-UTRA-NR Dual Connectivity
6482 * @param subId subscription id of the sim card
6483 * @param nrDualConnectivityState expected NR dual connectivity state
6484 * This can be passed following states
6485 * <ol>
6486 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6487 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6488 * <li>Disable NR dual connectivity and force secondary cell to be released
6489 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6490 * </ol>
6491 * @return operation result.
6492 */
6493 @Override
6494 public int setNrDualConnectivityState(int subId,
6495 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6497 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006498 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006499 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6500 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6501 }
6502
Sooraj Sasindran37444802020-08-11 10:40:43 -07006503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6504 final long identity = Binder.clearCallingIdentity();
6505 try {
6506 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6507 nrDualConnectivityState, subId,
6508 workSource);
6509 if (DBG) log("enableNRDualConnectivity result: " + result);
6510 return result;
6511 } finally {
6512 Binder.restoreCallingIdentity(identity);
6513 }
6514 }
6515
6516 /**
6517 * Is E-UTRA-NR Dual Connectivity enabled
6518 * @return true if dual connectivity is enabled else false
6519 */
6520 @Override
6521 public boolean isNrDualConnectivityEnabled(int subId) {
6522 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006523 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006524 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006525 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006526 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6527 return false;
6528 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6530 final long identity = Binder.clearCallingIdentity();
6531 try {
6532 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6533 null, subId, workSource);
6534 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6535 return isEnabled;
6536 } finally {
6537 Binder.restoreCallingIdentity(identity);
6538 }
6539 }
6540
6541 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006542 * Set the allowed network types of the device and
6543 * provide the reason triggering the allowed network change.
6544 *
6545 * @param subId the id of the subscription.
6546 * @param reason the reason the allowed network type change is taking place
6547 * @param allowedNetworkTypes the allowed network types.
6548 * @return true on success; false on any failure.
6549 */
6550 @Override
6551 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006552 @TelephonyManager.AllowedNetworkTypesReason int reason,
6553 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6555 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006556 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006557 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6558 return false;
6559 }
6560 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6561 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006562 return false;
6563 }
6564
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006565 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6566 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6567
6568
6569 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6570 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6571 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006572 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006573
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006574 final long identity = Binder.clearCallingIdentity();
6575 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006576 Boolean success = (Boolean) sendRequest(
6577 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6578 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6579
6580 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6581 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
6585 }
6586
6587 /**
Miaoa84611c2019-03-15 09:21:10 +08006588 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006589 *
Miaoa84611c2019-03-15 09:21:10 +08006590 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006591 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006592 * @hide
6593 */
6594 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006595 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006596 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006598 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 try {
Miaoa84611c2019-03-15 09:21:10 +08006600 if (phone != null) {
6601 return phone.hasMatchedTetherApnSetting();
6602 } else {
6603 return false;
6604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 } finally {
6606 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006607 }
Junda Liu475951f2014-11-07 16:45:03 -08006608 }
6609
6610 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006611 * Get the user enabled state of Mobile Data.
6612 *
6613 * TODO: remove and use isUserDataEnabled.
6614 * This can't be removed now because some vendor codes
6615 * calls through ITelephony directly while they should
6616 * use TelephonyManager.
6617 *
6618 * @return true on enabled
6619 */
6620 @Override
6621 public boolean getDataEnabled(int subId) {
6622 return isUserDataEnabled(subId);
6623 }
6624
6625 /**
6626 * Get whether mobile data is enabled per user setting.
6627 *
6628 * There are other factors deciding whether mobile data is actually enabled, but they are
6629 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006630 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006631 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6632 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006633 *
6634 * @return {@code true} if data is enabled else {@code false}
6635 */
6636 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006637 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006638 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006639 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006640 try {
6641 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6642 functionName);
6643 } catch (Exception e) {
6644 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6645 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006646 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006648 mApp, subId, functionName);
6649
Robert Greenwalt646120a2014-05-23 11:54:03 -07006650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651
6652 final long identity = Binder.clearCallingIdentity();
6653 try {
6654 int phoneId = mSubscriptionController.getPhoneId(subId);
6655 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6656 Phone phone = PhoneFactory.getPhone(phoneId);
6657 if (phone != null) {
6658 boolean retVal = phone.isUserDataEnabled();
6659 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6660 return retVal;
6661 } else {
6662 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6663 return false;
6664 }
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006667 }
6668 }
6669
6670 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006671 * Checks if the device is capable of mobile data by considering whether whether the
6672 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6673 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006674 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006675 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006676 */
6677 @Override
6678 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006679 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006680 try {
6681 try {
6682 mApp.enforceCallingOrSelfPermission(
6683 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006684 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006685 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006686 try {
6687 mApp.enforceCallingOrSelfPermission(
6688 android.Manifest.permission.READ_PHONE_STATE,
6689 functionName);
6690 } catch (Exception e2) {
6691 mApp.enforceCallingOrSelfPermission(
6692 permission.READ_BASIC_PHONE_STATE, functionName);
6693 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006694 }
6695 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006696 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698
6699 final long identity = Binder.clearCallingIdentity();
6700 try {
6701 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 Phone phone = PhoneFactory.getPhone(phoneId);
6703 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006704 boolean retVal;
6705 if (phone.isUsingNewDataStack()) {
6706 retVal = phone.getDataNetworkController().getDataSettingsManager()
6707 .isDataEnabled();
6708 } else {
6709 retVal = phone.getDataEnabledSettings().isDataEnabled();
6710 }
6711 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 return retVal;
6713 } else {
6714 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6715 return false;
6716 }
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006719 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006720 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006721
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006722 /**
6723 * Check if data is enabled for a specific reason
6724 * @param subId Subscription index
6725 * @param reason the reason the data enable change is taking place
6726 * @return {@code true} if the overall data is enabled; {@code false} if not.
6727 */
6728 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006729 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006731 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006732 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006733 try {
6734 mApp.enforceCallingOrSelfPermission(
6735 android.Manifest.permission.ACCESS_NETWORK_STATE,
6736 functionName);
6737 } catch (Exception e) {
6738 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6739 functionName);
6740 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006741 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006742 try {
6743 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006744 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006745 } catch (Exception e2) {
6746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006747 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006748 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006749 }
6750
6751
6752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 int phoneId = mSubscriptionController.getPhoneId(subId);
6755 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006756 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006757 + " reason=" + reason);
6758 }
6759 Phone phone = PhoneFactory.getPhone(phoneId);
6760 if (phone != null) {
6761 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006762 if (phone.isUsingNewDataStack()) {
6763 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006764 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006765 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6766 retVal = phone.isUserDataEnabled();
6767 } else {
6768 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6769 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006770 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006771 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006772 return retVal;
6773 } else {
6774 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006775 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006776 + subId + " retVal=false");
6777 }
6778 return false;
6779 }
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
6783 }
6784
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006785 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006786 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006787 if (uid == Process.PHONE_UID) {
6788 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6789 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6791 }
6792
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006793 //load access rules from carrier configs, and check those as well: b/139133814
6794 SubscriptionController subController = SubscriptionController.getInstance();
6795 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6796 || subController == null) return privilegeFromSim;
6797
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006798 PackageManager pkgMgr = phone.getContext().getPackageManager();
6799 String[] packages = pkgMgr.getPackagesForUid(uid);
6800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006803 int subId = phone.getSubId();
6804 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6805 // A test override is in place for the privileges for this subId, so don't try to
6806 // read the subscription privileges.
6807 return privilegeFromSim;
6808 }
6809 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006810 SubscriptionManager subManager = (SubscriptionManager)
6811 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6812 for (String pkg : packages) {
6813 if (subManager.canManageSubscription(subInfo, pkg)) {
6814 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6815 }
6816 }
6817 return privilegeFromSim;
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
6821 }
6822
6823 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6824 String pkgName) {
6825 //load access rules from carrier configs, and check those as well: b/139133814
6826 SubscriptionController subController = SubscriptionController.getInstance();
6827 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6828 || subController == null) return privilegeFromSim;
6829
6830 final long identity = Binder.clearCallingIdentity();
6831 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006832 int subId = phone.getSubId();
6833 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6834 // A test override is in place for the privileges for this subId, so don't try to
6835 // read the subscription privileges.
6836 return privilegeFromSim;
6837 }
6838 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006839 SubscriptionManager subManager = (SubscriptionManager)
6840 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6841 return subManager.canManageSubscription(subInfo, pkgName)
6842 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
6846 }
6847
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006848 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006849 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006850 // No permission needed; this only lets the caller inspect their own status.
6851 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006852 }
Junda Liu29340342014-07-10 15:23:27 -07006853
6854 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006855 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006856 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006857 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6858 }
6859
6860 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6861 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006862 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006863 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6865 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006866 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6867 if (cpt == null) {
6868 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6870 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006871 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006872 }
6873
6874 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006875 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006876 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006877 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006878 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006879 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006880 Phone phone = getPhone(subId);
6881 if (phone == null) {
6882 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6883 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6884 }
6885 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6886 if (cpt == null) {
6887 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006888 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6889 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006890 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006891 }
6892
6893 @Override
6894 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006895 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
6896 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006897 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006898 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006899 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006900 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6901 Phone phone = PhoneFactory.getPhone(phoneId);
6902 if (phone == null) {
6903 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006904 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006905 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6906 if (cpt == null) {
6907 continue;
6908 }
6909 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006910 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6911 break;
6912 }
6913 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006914 return result;
Junda Liu29340342014-07-10 15:23:27 -07006915 }
Derek Tan89e89d42014-07-08 17:00:10 -07006916
6917 @Override
Junda Liue64de782015-04-16 17:19:16 -07006918 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006919 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006920 Phone phone = PhoneFactory.getPhone(phoneId);
6921 if (phone == null) {
6922 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006923 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006924 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6925 if (cpt == null) {
6926 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006927 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006928 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006929 }
6930
Amith Yamasani6e118872016-02-19 12:53:51 -08006931 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006932 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006933 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006934 Phone phone = PhoneFactory.getPhone(phoneId);
6935 if (phone == null) {
6936 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006937 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006938 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6939 if (cpt == null) {
6940 return Collections.emptyList();
6941 }
6942 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006943 }
6944
chen xuf7e9fe82019-05-09 19:31:02 -07006945 @Override
6946 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006947 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006948 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006949 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006950 try {
6951 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6952 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6953 }
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006956 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006957 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006958 }
6959
Wink Savilleb564aae2014-10-23 10:18:09 -07006960 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006961 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006962 UiccPort port = phone == null ? null : phone.getUiccPort();
6963 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006964 return null;
6965 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006966 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006967 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006968 return null;
6969 }
6970 return iccId;
6971 }
6972
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006973 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006974 public void setCallComposerStatus(int subId, int status) {
6975 enforceModifyPermission();
6976
6977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 Phone phone = getPhone(subId);
6980 if (phone != null) {
6981 Phone defaultPhone = phone.getImsPhone();
6982 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6983 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6984 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006985 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6986 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006987 }
6988 }
Shuo Qian284ae752020-12-22 19:10:14 -08006989 } catch (ImsException e) {
6990 throw new ServiceSpecificException(e.getCode());
6991 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006992 Binder.restoreCallingIdentity(identity);
6993 }
6994 }
6995
6996 @Override
6997 public int getCallComposerStatus(int subId) {
6998 enforceReadPrivilegedPermission("getCallComposerStatus");
6999
7000 final long identity = Binder.clearCallingIdentity();
7001 try {
7002 Phone phone = getPhone(subId);
7003 if (phone != null) {
7004 Phone defaultPhone = phone.getImsPhone();
7005 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7006 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7007 return imsPhone.getCallComposerStatus();
7008 }
7009 }
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
7012 }
7013 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7014 }
7015
7016 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007017 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7018 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007019 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007020 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 final long identity = Binder.clearCallingIdentity();
7023 try {
7024 final String iccId = getIccId(subId);
7025 final Phone phone = getPhone(subId);
7026 if (phone == null) {
7027 return false;
7028 }
7029 final String subscriberId = phone.getSubscriberId();
7030
7031 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007032 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 + subscriberId + " to " + number);
7034 }
7035
7036 if (TextUtils.isEmpty(iccId)) {
7037 return false;
7038 }
7039
7040 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7041
7042 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7043 if (alphaTag == null) {
7044 editor.remove(alphaTagPrefKey);
7045 } else {
7046 editor.putString(alphaTagPrefKey, alphaTag);
7047 }
7048
7049 // Record both the line number and IMSI for this ICCID, since we need to
7050 // track all merged IMSIs based on line number
7051 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7052 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7053 if (number == null) {
7054 editor.remove(numberPrefKey);
7055 editor.remove(subscriberPrefKey);
7056 } else {
7057 editor.putString(numberPrefKey, number);
7058 editor.putString(subscriberPrefKey, subscriberId);
7059 }
7060
7061 editor.commit();
7062 return true;
7063 } finally {
7064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007065 }
Derek Tan7226c842014-07-02 17:42:23 -07007066 }
7067
7068 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007069 public String getLine1NumberForDisplay(int subId, String callingPackage,
7070 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007071 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007073 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007074 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007075 return null;
7076 }
Derek Tan97ebb422014-09-05 16:55:38 -07007077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 String iccId = getIccId(subId);
7081 if (iccId != null) {
7082 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7083 if (DBG_MERGE) {
7084 log("getLine1NumberForDisplay returning "
7085 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7086 }
7087 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007088 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7090 return null;
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007093 }
Derek Tan7226c842014-07-02 17:42:23 -07007094 }
7095
7096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007097 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7098 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007100 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007101 return null;
7102 }
Derek Tan97ebb422014-09-05 16:55:38 -07007103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 String iccId = getIccId(subId);
7107 if (iccId != null) {
7108 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7109 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7110 }
7111 return null;
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007114 }
Derek Tan7226c842014-07-02 17:42:23 -07007115 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007116
7117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7119 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007120 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7121 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007123 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007124 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007125 return null;
7126 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007127
Jordan Liub49b04b2019-05-06 14:45:15 -07007128 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7129 // the process, where TelephonyManager was instantiated.
7130 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007131 final long identity = Binder.clearCallingIdentity();
7132 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007133 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 final TelephonyManager tele = TelephonyManager.from(context);
7135 final SubscriptionManager sub = SubscriptionManager.from(context);
7136
7137 // Figure out what subscribers are currently active
7138 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
Jordan Liub49b04b2019-05-06 14:45:15 -07007140 // Only consider subs which match the current subId
7141 // This logic can be simplified. See b/131189269 for progress.
7142 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007143 activeSubscriberIds.add(tele.getSubscriberId(subId));
7144 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145
7146 // First pass, find a number override for an active subscriber
7147 String mergeNumber = null;
7148 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7149 for (String key : prefs.keySet()) {
7150 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7151 final String subscriberId = (String) prefs.get(key);
7152 if (activeSubscriberIds.contains(subscriberId)) {
7153 final String iccId = key.substring(
7154 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7155 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7156 mergeNumber = (String) prefs.get(numberKey);
7157 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007158 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 + " for active subscriber " + subscriberId);
7160 }
7161 if (!TextUtils.isEmpty(mergeNumber)) {
7162 break;
7163 }
7164 }
7165 }
7166 }
7167
7168 // Shortcut when no active merged subscribers
7169 if (TextUtils.isEmpty(mergeNumber)) {
7170 return null;
7171 }
7172
7173 // Second pass, find all subscribers under that line override
7174 final ArraySet<String> result = new ArraySet<>();
7175 for (String key : prefs.keySet()) {
7176 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7177 final String number = (String) prefs.get(key);
7178 if (mergeNumber.equals(number)) {
7179 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7180 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7181 final String subscriberId = (String) prefs.get(subscriberKey);
7182 if (!TextUtils.isEmpty(subscriberId)) {
7183 result.add(subscriberId);
7184 }
7185 }
7186 }
7187 }
7188
7189 final String[] resultArray = result.toArray(new String[result.size()]);
7190 Arrays.sort(resultArray);
7191 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007192 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7194 }
7195 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007196 } finally {
7197 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007198 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007199 }
7200
7201 @Override
zoey chen38003472019-12-13 17:16:31 +08007202 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7203 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007204
7205 final long identity = Binder.clearCallingIdentity();
7206 try {
7207 final TelephonyManager telephonyManager = mApp.getSystemService(
7208 TelephonyManager.class);
7209 String subscriberId = telephonyManager.getSubscriberId(subId);
7210 if (subscriberId == null) {
7211 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007212 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007213 + subId);
7214 }
7215 return null;
7216 }
7217
7218 final SubscriptionInfo info = SubscriptionController.getInstance()
7219 .getSubscriptionInfo(subId);
7220 final ParcelUuid groupUuid = info.getGroupUuid();
7221 // If it doesn't belong to any group, return just subscriberId of itself.
7222 if (groupUuid == null) {
7223 return new String[]{subscriberId};
7224 }
7225
7226 // Get all subscriberIds from the group.
7227 final List<String> mergedSubscriberIds = new ArrayList<>();
7228 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007229 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007230 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007231 for (SubscriptionInfo subInfo : groupInfos) {
7232 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7233 if (subscriberId != null) {
7234 mergedSubscriberIds.add(subscriberId);
7235 }
7236 }
7237
7238 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241
7242 }
7243 }
7244
7245 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007246 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007247 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007248 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 final Phone phone = getPhone(subId);
7253 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007257 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007258
7259 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007260 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007261 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7262 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007263 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7264 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007265
7266 final long identity = Binder.clearCallingIdentity();
7267 try {
7268 final Phone phone = getPhone(subId);
7269 if (phone == null) {
7270 return false;
7271 }
7272 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7273 cdmaNonRoamingList);
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007276 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007277 }
7278
7279 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007280 @Deprecated
7281 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7282 enforceModifyPermission();
7283
7284 int returnValue = 0;
7285 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007286 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007287 if(result.exception == null) {
7288 if (result.result != null) {
7289 byte[] responseData = (byte[])(result.result);
7290 if(responseData.length > oemResp.length) {
7291 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7292 responseData.length + "bytes. Buffer Size is " +
7293 oemResp.length + "bytes.");
7294 }
7295 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7296 returnValue = responseData.length;
7297 }
7298 } else {
7299 CommandException ex = (CommandException) result.exception;
7300 returnValue = ex.getCommandError().ordinal();
7301 if(returnValue > 0) returnValue *= -1;
7302 }
7303 } catch (RuntimeException e) {
7304 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7305 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7306 if(returnValue > 0) returnValue *= -1;
7307 }
7308
7309 return returnValue;
7310 }
7311
7312 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007313 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007314 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007315 try {
7316 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007317 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007318 mApp, phone.getSubId(), "getRadioAccessFamily");
7319 } catch (SecurityException e) {
7320 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7321 throw e;
7322 }
chen xub97461a2018-10-26 14:17:57 -07007323 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007324 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007325 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 final long identity = Binder.clearCallingIdentity();
7328 try {
chen xub97461a2018-10-26 14:17:57 -07007329 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007330 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007331 mApp, phone.getSubId(), "getRadioAccessFamily");
7332 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 } finally {
7334 Binder.restoreCallingIdentity(identity);
7335 }
chen xub97461a2018-10-26 14:17:57 -07007336 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007337 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007338
7339 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007340 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007341 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007342 try {
7343 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7344 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007345 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007346 }
7347 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007348 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007349 }
7350 RoleManager rm = mApp.getSystemService(RoleManager.class);
7351 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7352 if (!dialerRoleHolders.contains(callingPackage)) {
7353 throw new SecurityException("App must be the dialer role holder to"
7354 + " upload a call composer pic");
7355 }
7356
7357 Executors.newSingleThreadExecutor().execute(() -> {
7358 ByteArrayOutputStream output = new ByteArrayOutputStream(
7359 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7360 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7361 boolean readUntilEnd = false;
7362 int totalBytesRead = 0;
7363 byte[] buffer = new byte[16 * 1024];
7364 while (true) {
7365 int numRead;
7366 try {
7367 numRead = input.read(buffer);
7368 } catch (IOException e) {
7369 try {
7370 fd.checkError();
7371 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7372 null);
7373 } catch (IOException e1) {
7374 // This means that the other side closed explicitly with an error. If this
7375 // happens, log and ignore.
7376 loge("Remote end of call composer picture pipe closed: " + e1);
7377 }
7378 break;
7379 }
7380 if (numRead == -1) {
7381 readUntilEnd = true;
7382 break;
7383 }
7384 totalBytesRead += numRead;
7385 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7386 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7387 try {
7388 input.close();
7389 } catch (IOException e) {
7390 // ignore
7391 }
7392 break;
7393 }
7394 output.write(buffer, 0, numRead);
7395 }
7396 // Generally, the remote end will close the file descriptors. The only case where we
7397 // close is above, where the picture size is too big.
7398
7399 try {
7400 fd.checkError();
7401 } catch (IOException e) {
7402 loge("Remote end for call composer closed with an error: " + e);
7403 return;
7404 }
7405
Hall Liuaa4211e2021-01-20 15:43:39 -08007406 if (!readUntilEnd) {
7407 loge("Did not finish reading entire image; aborting");
7408 return;
7409 }
Hall Liu82694d52020-12-11 18:22:04 -08007410
Hall Liuaa4211e2021-01-20 15:43:39 -08007411 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7412 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7413 new CallComposerPictureTransfer.Factory() {},
7414 imageData,
7415 (result) -> {
7416 if (result.first != null) {
7417 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7418 Bundle outputResult = new Bundle();
7419 outputResult.putParcelable(
7420 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7421 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7422 outputResult);
7423 } else {
7424 callback.send(result.second, null);
7425 }
7426 }
7427 );
Hall Liu82694d52020-12-11 18:22:04 -08007428 });
7429 }
7430
7431 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007432 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007433 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007434 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435
7436 final long identity = Binder.clearCallingIdentity();
7437 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007438 ImsManager.getInstance(defaultPhone.getContext(),
7439 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 } finally {
7441 Binder.restoreCallingIdentity(identity);
7442 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007443 }
7444
7445 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007446 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007447 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7449 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007450 return false;
7451 }
Svet Ganovb320e182015-04-16 12:30:10 -07007452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 // Check the user preference and the system-level IMS setting. Even if the user has
7456 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7457 // In the long run, we may instead need to check if there exists a connection service
7458 // which can support video calling.
7459 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007460 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 return imsManager.isVtEnabledByPlatform()
7462 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7463 && imsManager.isVtEnabledByUser();
7464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007467 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007468
Andrew Leea1239f22015-03-02 17:44:07 -08007469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007470 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7471 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007473 mApp, subId, callingPackage, callingFeatureId,
7474 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 return false;
7476 }
7477
7478 final long identity = Binder.clearCallingIdentity();
7479 try {
7480 CarrierConfigManager configManager =
7481 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007482 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7484 } finally {
7485 Binder.restoreCallingIdentity(identity);
7486 }
Andrew Leea1239f22015-03-02 17:44:07 -08007487 }
7488
7489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007490 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007492 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 return false;
7494 }
7495
7496 final long identity = Binder.clearCallingIdentity();
7497 try {
7498 CarrierConfigManager configManager =
7499 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007500 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7502 } finally {
7503 Binder.restoreCallingIdentity(identity);
7504 }
Andrew Leea1239f22015-03-02 17:44:07 -08007505 }
7506
Andrew Lee9431b832015-03-09 18:46:45 -07007507 @Override
7508 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007509 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007510 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007511 }
7512
7513 @Override
7514 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 final long identity = Binder.clearCallingIdentity();
7516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 } finally {
7519 Binder.restoreCallingIdentity(identity);
7520 }
Andrew Lee9431b832015-03-09 18:46:45 -07007521 }
7522
Hall Liuf6668912018-10-31 17:05:23 -07007523 /**
7524 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7525 * support for the feature and device firmware support.
7526 *
7527 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7528 */
7529 @Override
7530 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 final Phone phone = getPhone(subscriptionId);
7533 if (phone == null) {
7534 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7535 return false;
7536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007538 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7540 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007541 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 return isCarrierSupported && isDeviceSupported;
7543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
Hall Liu98187582018-01-22 19:15:32 -08007546 }
7547
Hall Liuf6668912018-10-31 17:05:23 -07007548 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007549 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7550 * RTT setting, will return true if the device and carrier both support RTT.
7551 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007552 */
7553 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 final long identity = Binder.clearCallingIdentity();
7555 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007556 boolean isRttSupported = isRttSupported(subscriptionId);
7557 boolean isUserRttSettingOn = Settings.Secure.getInt(
7558 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7559 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7560 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7561 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007565 }
7566
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007567 @Deprecated
7568 @Override
7569 public String getDeviceId(String callingPackage) {
7570 return getDeviceIdWithFeature(callingPackage, null);
7571 }
7572
Sanket Padawe7310cc72015-01-14 09:53:20 -08007573 /**
7574 * Returns the unique device ID of phone, for example, the IMEI for
7575 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7576 *
7577 * <p>Requires Permission:
7578 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7579 */
7580 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007581 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007582 try {
7583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7584 } catch (SecurityException se) {
7585 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7586 throw new SecurityException("Package " + callingPackage + " does not belong to "
7587 + Binder.getCallingUid());
7588 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007589 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007590 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007591 return null;
7592 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007593 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007594 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007595 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007596 return null;
7597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007598
7599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 return phone.getDeviceId();
7602 } finally {
7603 Binder.restoreCallingIdentity(identity);
7604 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007605 }
7606
Ping Sunc67b7c22016-03-02 19:16:45 +08007607 /**
7608 * {@hide}
7609 * Returns the IMS Registration Status on a particular subid
7610 *
7611 * @param subId
7612 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007613 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007614 Phone phone = getPhone(subId);
7615 if (phone != null) {
7616 return phone.isImsRegistered();
7617 } else {
7618 return false;
7619 }
7620 }
7621
Santos Cordon7a1885b2015-02-03 11:15:19 -08007622 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007623 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007624 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007626 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007627 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7628 }
7629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7632 } finally {
7633 Binder.restoreCallingIdentity(identity);
7634 }
7635 }
7636
7637 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007638 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007639 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007640 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007641 mApp,
7642 subscriptionId,
7643 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 Phone phone = getPhone(subscriptionId);
7647 if (phone == null) {
7648 return null;
7649 }
7650 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
7654 }
7655
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007656 /**
7657 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007658 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007659 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 final long identity = Binder.clearCallingIdentity();
7661 try {
7662 Phone phone = getPhone(subId);
7663 if (phone != null) {
7664 return phone.isWifiCallingEnabled();
7665 } else {
7666 return false;
7667 }
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007670 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007671 }
7672
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007673 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007674 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007675 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007676 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 final long identity = Binder.clearCallingIdentity();
7678 try {
7679 Phone phone = getPhone(subId);
7680 if (phone != null) {
7681 return phone.isVideoEnabled();
7682 } else {
7683 return false;
7684 }
7685 } finally {
7686 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007687 }
7688 }
7689
7690 /**
7691 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7692 * defined in {@link ImsRegistrationImplBase}.
7693 */
7694 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 final long identity = Binder.clearCallingIdentity();
7696 try {
7697 Phone phone = getPhone(subId);
7698 if (phone != null) {
7699 return phone.getImsRegistrationTech();
7700 } else {
7701 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7702 }
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007706 }
7707
Stuart Scott8eef64f2015-04-08 15:13:54 -07007708 @Override
7709 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007710 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007711 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7712 return;
7713 }
Kai Shif70f46f2021-03-03 13:59:46 -08007714 Phone defaultPhone = getDefaultPhone();
7715 if (defaultPhone != null) {
7716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7717 mApp, getDefaultPhone().getSubId(), "factoryReset");
7718 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007719 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007720
Svet Ganovcc087f82015-05-12 20:35:54 -07007721 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007722 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7723 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007724 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007725 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007726 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007727 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007728 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007729 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007730 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007731 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007732 // There has been issues when Sms raw table somehow stores orphan
7733 // fragments. They lead to garbled message when new fragments come
7734 // in and combined with those stale ones. In case this happens again,
7735 // user can reset all network settings which will clean up this table.
7736 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007737 // Clean up IMS settings as well here.
7738 int slotId = getSlotIndex(subId);
7739 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7740 ImsManager.getInstance(mApp, slotId).factoryReset();
7741 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007742
Kai Shif70f46f2021-03-03 13:59:46 -08007743 if (defaultPhone == null) {
7744 return;
7745 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007746 // Erase modem config if erase modem on network setting is enabled.
7747 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7748 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7749 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007750 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007751 }
Kai Shif70f46f2021-03-03 13:59:46 -08007752
7753 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007754 } finally {
7755 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007756 }
7757 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007758
SongFerngWangfd89b102021-05-27 22:44:54 +08007759 @VisibleForTesting
7760 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7761 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7762 return;
7763 }
7764 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7765 RILConstants.PREFERRED_NETWORK_MODE);
7766 SubscriptionManager.setSubscriptionProperty(subId,
7767 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7768 "user=" + defaultNetworkType);
7769 phone.loadAllowedNetworksFromSubscriptionDatabase();
7770 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7771 defaultNetworkType, null);
7772 }
7773
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007774 private void cleanUpSmsRawTable(Context context) {
7775 ContentResolver resolver = context.getContentResolver();
7776 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7777 resolver.delete(uri, null, null);
7778 }
7779
Narayan Kamath1c496c22015-04-16 14:40:19 +01007780 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007781 public String getSimLocaleForSubscriber(int subId) {
7782 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7783 final Phone phone = getPhone(subId);
7784 if (phone == null) {
7785 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007786 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 final long identity = Binder.clearCallingIdentity();
7789 try {
chen xu5d3637b2019-01-21 23:31:38 -08007790 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007791 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007792 if (info == null) {
7793 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7794 return null;
7795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 // Try and fetch the locale from the carrier properties or from the SIM language
7797 // preferences (EF-PL and EF-LI)...
7798 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007800 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7801 if (localeFromDefaultSim != null) {
7802 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7803 if (DBG) log("Using locale from subId: " + subId + " locale: "
7804 + localeFromDefaultSim);
7805 return localeFromDefaultSim.toLanguageTag();
7806 } else {
7807 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 }
7809 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811 // The SIM language preferences only store a language (e.g. fr = French), not an
7812 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7813 // the SIM and carrier preferences does not include a country we add the country
7814 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007815 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007817 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 return mccLocale.toLanguageTag();
7819 }
7820
7821 if (DBG) log("No locale found - returning null");
7822 return null;
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
7825 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007826 }
7827
7828 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007829 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007830 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007831 }
7832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833 /**
7834 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7835 */
7836 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007837 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007838 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007839 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007840
Gary Jian3aa9a762022-01-24 16:41:19 +08007841 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7842 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007843
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007844 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007845 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7846 * representing the state of the modem.
7847 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007848 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7849 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007850 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007851 */
7852 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007853 public void requestModemActivityInfo(ResultReceiver result) {
7854 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007855 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856
7857 final long identity = Binder.clearCallingIdentity();
7858 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007859 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 } finally {
7861 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007862 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007863 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007864
Siddharth Rayb8114062018-06-17 15:02:38 -07007865 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7866 // less than total activity duration.
7867 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7868 if (info == null) {
7869 return false;
7870 }
7871 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007872 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7873 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7874
Siddharth Rayb8114062018-06-17 15:02:38 -07007875 return (info.isValid()
7876 && (info.getSleepTimeMillis() <= activityDurationMs)
7877 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007878 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007879 && (totalTxTimeMs <= activityDurationMs));
7880 }
7881
Gary Jian3aa9a762022-01-24 16:41:19 +08007882 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7883 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7884 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7885 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7886
7887 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7888 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7889 }
7890
7891 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7892 mLastModemActivityInfo.setReceiveTimeMillis(
7893 rat,
7894 freq,
7895 info.getReceiveTimeMillis(rat, freq)
7896 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7897 }
7898
7899 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7900 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7901 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7902 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7903
7904 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7905 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7906 }
7907 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7908 mLastModemActivityInfo.setReceiveTimeMillis(
7909 rat,
7910 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7911 }
7912
7913 /**
7914 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7915 * @param info recent ModemActivityInfo
7916 */
7917 private void mergeModemActivityInfo(ModemActivityInfo info) {
7918 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7919 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7920 boolean matched;
7921 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7922 matched = false;
7923 int rat = info.getSpecificInfoRat(i);
7924 int freq = info.getSpecificInfoFrequencyRange(i);
7925 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7926 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7927 //if it already exists
7928 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7929 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7930 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7931 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7932 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7933 updateLastModemActivityInfo(info, rat, freq);
7934 matched = true;
7935 }
7936 } else {
7937 updateLastModemActivityInfo(info, rat);
7938 matched = true;
7939 }
7940 }
7941 }
7942
7943 if (!matched) {
7944 mDeltaSpecificInfo =
7945 new ActivityStatsTechSpecificInfo(
7946 rat,
7947 freq,
7948 info.getTransmitTimeMillis(rat, freq),
7949 (int) info.getReceiveTimeMillis(rat, freq));
7950 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7951 }
7952 }
7953 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7954 mLastModemActivitySpecificInfo =
7955 new ActivityStatsTechSpecificInfo[merged.size()];
7956 merged.toArray(mLastModemActivitySpecificInfo);
7957
7958 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7959 mLastModemActivityInfo.setSleepTimeMillis(
7960 info.getSleepTimeMillis()
7961 + mLastModemActivityInfo.getSleepTimeMillis());
7962 mLastModemActivityInfo.setIdleTimeMillis(
7963 info.getIdleTimeMillis()
7964 + mLastModemActivityInfo.getIdleTimeMillis());
7965 }
7966
Jack Yu85bd38a2015-11-09 11:34:32 -08007967 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007968 * Returns the service state information on specified subscription.
7969 */
7970 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007971 public ServiceState getServiceStateForSubscriber(int subId,
7972 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7973 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007975 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007976 return null;
7977 }
7978
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007979 boolean hasFinePermission = false;
7980 boolean hasCoarsePermission = false;
7981 if (!renounceFineLocationAccess) {
7982 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7983 LocationAccessPolicy.checkLocationPermission(mApp,
7984 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7985 .setCallingPackage(callingPackage)
7986 .setCallingFeatureId(callingFeatureId)
7987 .setCallingPid(Binder.getCallingPid())
7988 .setCallingUid(Binder.getCallingUid())
7989 .setMethod("getServiceStateForSubscriber")
7990 .setLogAsInfo(true)
7991 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7992 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7993 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7994 .build());
7995 hasFinePermission =
7996 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7997 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007998
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007999 if (!renounceCoarseLocationAccess) {
8000 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8001 LocationAccessPolicy.checkLocationPermission(mApp,
8002 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8003 .setCallingPackage(callingPackage)
8004 .setCallingFeatureId(callingFeatureId)
8005 .setCallingPid(Binder.getCallingPid())
8006 .setCallingUid(Binder.getCallingUid())
8007 .setMethod("getServiceStateForSubscriber")
8008 .setLogAsInfo(true)
8009 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8010 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8011 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8012 .build());
8013 hasCoarsePermission =
8014 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8015 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008016
Jack Yu479f40e2020-10-27 21:29:25 -07008017 final Phone phone = getPhone(subId);
8018 if (phone == null) {
8019 return null;
8020 }
8021
Jordan Liu0f2bc442020-11-18 16:47:37 -08008022 final long identity = Binder.clearCallingIdentity();
8023
Jack Yu479f40e2020-10-27 21:29:25 -07008024 boolean isCallingPackageDataService = phone.getDataServicePackages()
8025 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008027 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8028 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8029 Rlog.d(LOG_TAG,
8030 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8031 return null;
8032 }
8033
Hall Liuf19c44f2018-11-27 14:38:17 -08008034 ServiceState ss = phone.getServiceState();
8035
8036 // Scrub out the location info in ServiceState depending on what level of access
8037 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008038 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008039 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8040 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041 } finally {
8042 Binder.restoreCallingIdentity(identity);
8043 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008044 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008045
8046 /**
8047 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8048 *
8049 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8050 * voicemail ringtone.
8051 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8052 * PhoneAccount.
8053 */
8054 @Override
8055 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 final long identity = Binder.clearCallingIdentity();
8057 try {
8058 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8059 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008060 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008067 }
8068
8069 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008070 * Sets the per-account voicemail ringtone.
8071 *
8072 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8073 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8074 *
8075 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8076 * voicemail ringtone.
8077 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8078 * PhoneAccount.
8079 */
8080 @Override
8081 public void setVoicemailRingtoneUri(String callingPackage,
8082 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008083 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008084 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008085 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8086 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8088 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8089 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091
8092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8095 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008096 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 }
8098 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8099 } finally {
8100 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008101 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008102 }
8103
8104 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008105 * Returns whether vibration is set for voicemail notification in Phone settings.
8106 *
8107 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8108 * voicemail vibration setting.
8109 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8110 */
8111 @Override
8112 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 final long identity = Binder.clearCallingIdentity();
8114 try {
8115 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8116 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008117 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008124 }
8125
Youhan Wange64578a2016-05-02 15:32:42 -07008126 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008127 * Sets the per-account voicemail vibration.
8128 *
8129 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8130 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8131 *
8132 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8133 * voicemail vibration setting.
8134 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8135 * specific PhoneAccount.
8136 */
8137 @Override
8138 public void setVoicemailVibrationEnabled(String callingPackage,
8139 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008140 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008141 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008142 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8143 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8145 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8146 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008147 }
8148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149 final long identity = Binder.clearCallingIdentity();
8150 try {
8151 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8152 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008153 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008154 }
8155 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8156 } finally {
8157 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008158 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008159 }
8160
8161 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008162 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8163 *
8164 * @throws SecurityException if the caller does not have the required permission
8165 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008166 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008167 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008168 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008169 }
8170
8171 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008172 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8173 * permission.
8174 *
8175 * @throws SecurityException if the caller does not have the required permission
8176 */
8177 private void enforceSendSmsPermission() {
8178 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8179 }
8180
8181 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008182 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008183 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008184 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008185 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008186 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187 final long identity = Binder.clearCallingIdentity();
8188 try {
8189 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008190 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191 if (componentName == null) {
8192 throw new SecurityException(
8193 "Caller not current active visual voicemail package[null]");
8194 }
8195 String vvmPackage = componentName.getPackageName();
8196 if (!callingPackage.equals(vvmPackage)) {
8197 throw new SecurityException("Caller not current active visual voicemail package["
8198 + vvmPackage + "]");
8199 }
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008202 }
8203 }
8204
8205 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008206 * Return the application ID for the app type.
8207 *
8208 * @param subId the subscription ID that this request applies to.
8209 * @param appType the uicc app type.
8210 * @return Application ID for specificied app type, or null if no uicc.
8211 */
8212 @Override
8213 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008214 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008215 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216
8217 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008218 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 if (phone == null) {
8220 return null;
8221 }
8222 String aid = null;
8223 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008224 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 .getApplicationByType(appType).getAid();
8226 } catch (Exception e) {
8227 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8228 }
8229 return aid;
8230 } finally {
8231 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008232 }
Youhan Wange64578a2016-05-02 15:32:42 -07008233 }
8234
Youhan Wang4001d252016-05-11 10:29:41 -07008235 /**
8236 * Return the Electronic Serial Number.
8237 *
8238 * @param subId the subscription ID that this request applies to.
8239 * @return ESN or null if error.
8240 */
8241 @Override
8242 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008243 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008244 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245
8246 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008247 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 if (phone == null) {
8249 return null;
8250 }
8251 String esn = null;
8252 try {
8253 esn = phone.getEsn();
8254 } catch (Exception e) {
8255 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8256 }
8257 return esn;
8258 } finally {
8259 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008260 }
Youhan Wang4001d252016-05-11 10:29:41 -07008261 }
8262
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008263 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008264 * Return the Preferred Roaming List Version.
8265 *
8266 * @param subId the subscription ID that this request applies to.
8267 * @return PRLVersion or null if error.
8268 */
8269 @Override
8270 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008271 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008272 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273
8274 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008275 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276 if (phone == null) {
8277 return null;
8278 }
8279 String cdmaPrlVersion = null;
8280 try {
8281 cdmaPrlVersion = phone.getCdmaPrlVersion();
8282 } catch (Exception e) {
8283 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8284 }
8285 return cdmaPrlVersion;
8286 } finally {
8287 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008288 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008289 }
8290
8291 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008292 * Get snapshot of Telephony histograms
8293 * @return List of Telephony histograms
8294 * @hide
8295 */
8296 @Override
8297 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8299 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300
8301 final long identity = Binder.clearCallingIdentity();
8302 try {
8303 return RIL.getTelephonyRILTimingHistograms();
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008307 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008308
8309 /**
8310 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008311 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8312 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008313 * Require system privileges. In the future we may add this to carrier APIs.
8314 *
Michele Berionne482f8202018-11-27 18:57:59 -08008315 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008316 */
8317 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008318 @TelephonyManager.SetCarrierRestrictionResult
8319 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008320 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008321 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008322
Michele Berionne482f8202018-11-27 18:57:59 -08008323 if (carrierRestrictionRules == null) {
8324 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008325 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 final long identity = Binder.clearCallingIdentity();
8328 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008329 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008330 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008334 }
8335
8336 /**
8337 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008338 * Get the allowed carrier list and the excluded carrier list, including the priority between
8339 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008340 * Require system privileges. In the future we may add this to carrier APIs.
8341 *
Michele Berionne482f8202018-11-27 18:57:59 -08008342 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008343 */
8344 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008345 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008346 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348
8349 final long identity = Binder.clearCallingIdentity();
8350 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008351 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8352 if (response instanceof CarrierRestrictionRules) {
8353 return (CarrierRestrictionRules) response;
8354 }
8355 // Response is an Exception of some kind,
8356 // which is signalled to the user as a NULL retval
8357 return null;
8358 } catch (Exception e) {
8359 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8360 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008364 }
8365
fionaxu59545b42016-05-25 15:53:37 -07008366 /**
fionaxu59545b42016-05-25 15:53:37 -07008367 * Action set from carrier signalling broadcast receivers to enable/disable radio
8368 * @param subId the subscription ID that this action applies to.
8369 * @param enabled control enable or disable radio.
8370 * {@hide}
8371 */
8372 @Override
8373 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8374 enforceModifyPermission();
8375 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376
8377 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008378 if (phone == null) {
8379 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8380 return;
8381 }
8382 try {
8383 phone.carrierActionSetRadioEnabled(enabled);
8384 } catch (Exception e) {
8385 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 } finally {
8387 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008388 }
8389 }
8390
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008391 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008392 * Enable or disable Voice over NR (VoNR)
8393 * @param subId the subscription ID that this action applies to.
8394 * @param enabled enable or disable VoNR.
8395 * @return operation result.
8396 */
8397 @Override
8398 public int setVoNrEnabled(int subId, boolean enabled) {
8399 enforceModifyPermission();
8400 final Phone phone = getPhone(subId);
8401
8402 final long identity = Binder.clearCallingIdentity();
8403 if (phone == null) {
8404 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8405 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8406 }
8407
8408 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8409 try {
8410 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8411 workSource);
8412 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008413
8414 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8415 if (DBG) {
8416 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8417 }
8418 SubscriptionManager.setSubscriptionProperty(
8419 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8420 (enabled ? "1" : "0"));
8421 }
8422
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008423 return result;
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
8427 }
8428
8429 /**
8430 * Is voice over NR enabled
8431 * @return true if VoNR is enabled else false
8432 */
8433 @Override
8434 public boolean isVoNrEnabled(int subId) {
8435 enforceReadPrivilegedPermission("isVoNrEnabled");
8436 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8437 final long identity = Binder.clearCallingIdentity();
8438 try {
8439 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8440 null, subId, workSource);
8441 if (DBG) log("isVoNrEnabled: " + isEnabled);
8442 return isEnabled;
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
8445 }
8446 }
8447
8448 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008449 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8450 * network status based on which carrier apps could apply actions accordingly,
8451 * enable/disable default url handler for example.
8452 *
8453 * @param subId the subscription ID that this action applies to.
8454 * @param report control start/stop reporting the default network status.
8455 * {@hide}
8456 */
8457 @Override
8458 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8459 enforceModifyPermission();
8460 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461
8462 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008463 if (phone == null) {
8464 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8465 return;
8466 }
8467 try {
8468 phone.carrierActionReportDefaultNetworkStatus(report);
8469 } catch (Exception e) {
8470 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 } finally {
8472 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008473 }
8474 }
8475
8476 /**
fionaxud9622282017-07-17 17:51:30 -07008477 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8478 * @param subId the subscription ID that this action applies to.
8479 * {@hide}
8480 */
8481 @Override
8482 public void carrierActionResetAll(int subId) {
8483 enforceModifyPermission();
8484 final Phone phone = getPhone(subId);
8485 if (phone == null) {
8486 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8487 return;
8488 }
8489 try {
8490 phone.carrierActionResetAll();
8491 } catch (Exception e) {
8492 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8493 }
8494 }
8495
8496 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008497 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8498 * bug report is being generated.
8499 */
8500 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008501 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008502 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8503 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008504 writer.println("Permission Denial: can't dump Phone from pid="
8505 + Binder.getCallingPid()
8506 + ", uid=" + Binder.getCallingUid()
8507 + "without permission "
8508 + android.Manifest.permission.DUMP);
8509 return;
8510 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008511 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008512 }
Jack Yueb89b242016-06-22 13:27:47 -07008513
Brad Ebingerdac2f002018-04-03 15:17:52 -07008514 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008515 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8516 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8517 @NonNull String[] args) {
8518 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8519 this, in.getFileDescriptor(), out.getFileDescriptor(),
8520 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008521 }
8522
Jack Yueb89b242016-06-22 13:27:47 -07008523 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008524 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008525 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008526 * @param reason the reason the data enable change is taking place
8527 * @param enabled True if enabling the data, otherwise disabling.
8528 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008529 */
8530 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008531 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008532 boolean enabled) {
8533 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8534 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8535 try {
8536 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008537 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008538 } catch (SecurityException se) {
8539 enforceModifyPermission();
8540 }
8541 } else {
8542 enforceModifyPermission();
8543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008544
8545 final long identity = Binder.clearCallingIdentity();
8546 try {
8547 Phone phone = getPhone(subId);
8548 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008549 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8550 phone.carrierActionSetMeteredApnsEnabled(enabled);
8551 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008552 if (phone.isUsingNewDataStack()) {
8553 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8554 } else {
8555 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8556 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008558 }
8559 } finally {
8560 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008561 }
8562 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008563
8564 /**
8565 * Get Client request stats
8566 * @return List of Client Request Stats
8567 * @hide
8568 */
8569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008570 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8571 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008573 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008574 return null;
8575 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008576 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 final long identity = Binder.clearCallingIdentity();
8579 try {
8580 if (phone != null) {
8581 return phone.getClientRequestStats();
8582 }
8583
8584 return null;
8585 } finally {
8586 Binder.restoreCallingIdentity(identity);
8587 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008588 }
8589
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008590 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008591 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008592 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008593 }
Jack Yueb4124c2017-02-16 15:32:43 -08008594
8595 /**
Grace Chen70990072017-03-24 17:21:30 -07008596 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008597 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008598 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008599 * @param state State of SIM (power down, power up, pass through)
8600 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8601 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8602 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008603 *
8604 **/
8605 @Override
Grace Chen70990072017-03-24 17:21:30 -07008606 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008607 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008608 Phone phone = PhoneFactory.getPhone(slotIndex);
8609
vagdeviaf9a5b92018-08-15 16:01:53 -07008610 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008612 final long identity = Binder.clearCallingIdentity();
8613 try {
8614 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008615 phone.setSimPowerState(state, null, workSource);
8616 }
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
8619 }
8620 }
8621
8622 /**
8623 * Set SIM card power state.
8624 *
8625 * @param slotIndex SIM slot id.
8626 * @param state State of SIM (power down, power up, pass through)
8627 * @param callback callback to trigger after success or failure
8628 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8629 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8630 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8631 *
8632 **/
8633 @Override
8634 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8635 IIntegerConsumer callback) {
8636 enforceModifyPermission();
8637 Phone phone = PhoneFactory.getPhone(slotIndex);
8638
8639 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8640
8641 final long identity = Binder.clearCallingIdentity();
8642 try {
8643 if (phone != null) {
8644 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8645 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008646 }
8647 } finally {
8648 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008649 }
8650 }
Shuo Qiandd210312017-04-12 22:11:33 +00008651
Tyler Gunn65d45c22017-06-05 11:22:26 -07008652 private boolean isUssdApiAllowed(int subId) {
8653 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008654 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008655 if (configManager == null) {
8656 return false;
8657 }
8658 PersistableBundle pb = configManager.getConfigForSubId(subId);
8659 if (pb == null) {
8660 return false;
8661 }
8662 return pb.getBoolean(
8663 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8664 }
8665
Shuo Qiandd210312017-04-12 22:11:33 +00008666 /**
8667 * Check if phone is in emergency callback mode
8668 * @return true if phone is in emergency callback mode
8669 * @param subId sub id
8670 */
goneil9c5f4872017-12-05 14:07:56 -08008671 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008672 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008673 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008674 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008675
8676 final long identity = Binder.clearCallingIdentity();
8677 try {
8678 if (phone != null) {
8679 return phone.isInEcm();
8680 } else {
8681 return false;
8682 }
8683 } finally {
8684 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008685 }
8686 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008687
8688 /**
8689 * Get the current signal strength information for the given subscription.
8690 * Because this information is not updated when the device is in a low power state
8691 * it should not be relied-upon to be current.
8692 * @param subId Subscription index
8693 * @return the most recent cached signal strength info from the modem
8694 */
8695 @Override
8696 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008697 final long identity = Binder.clearCallingIdentity();
8698 try {
8699 Phone p = getPhone(subId);
8700 if (p == null) {
8701 return null;
8702 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008704 return p.getSignalStrength();
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008708 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008709
Pengquan Meng77b7f132018-08-22 14:49:57 -07008710 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008711 * Get the current modem radio state for the given slot.
8712 * @param slotIndex slot index.
8713 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008714 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008715 * @return the current radio power state from the modem
8716 */
8717 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008718 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008719 Phone phone = PhoneFactory.getPhone(slotIndex);
8720 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8722 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008723 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8724 }
8725
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
8728 return phone.getRadioPowerState();
8729 } finally {
8730 Binder.restoreCallingIdentity(identity);
8731 }
8732 }
8733 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8734 }
8735
8736 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008737 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8738 *
8739 * <p>Requires one of the following permissions:
8740 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008741 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008742 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8743 * privileges.
8744 *
8745 * @param subId subscription id
8746 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8747 * {@code false}.
8748 */
8749 @Override
8750 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008751 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008752 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008753 try {
8754 mApp.enforceCallingOrSelfPermission(
8755 android.Manifest.permission.ACCESS_NETWORK_STATE,
8756 functionName);
8757 } catch (Exception e) {
8758 mApp.enforceCallingOrSelfPermission(
8759 permission.READ_BASIC_PHONE_STATE, functionName);
8760 }
Shuo Qian093013d2020-08-13 15:42:55 -07008761 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008762 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008763 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008764 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008765
Pengquan Menga1bb6272018-09-06 09:59:22 -07008766 boolean isEnabled = false;
8767 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008768 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008769 Phone phone = getPhone(subId);
8770 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008771 } finally {
8772 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008774 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008775 }
8776
8777
8778 /**
8779 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8780 *
8781 * <p> Requires permission:
8782 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8783 * privileges.
8784 *
8785 * @param subId subscription id
8786 * @param isEnabled {@code true} means enable, {@code false} means disable.
8787 */
8788 @Override
8789 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8791 mApp, subId, "setDataRoamingEnabled");
8792
Pengquan Menga1bb6272018-09-06 09:59:22 -07008793 final long identity = Binder.clearCallingIdentity();
8794 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008795 Phone phone = getPhone(subId);
8796 if (phone != null) {
8797 phone.setDataRoamingEnabled(isEnabled);
8798 }
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008801 }
8802 }
8803
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008804 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008805 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008806 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008807 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008808 mApp, subId, "isManualNetworkSelectionAllowed");
8809
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008810 boolean isAllowed = true;
8811 final long identity = Binder.clearCallingIdentity();
8812 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008813 Phone phone = getPhone(subId);
8814 if (phone != null) {
8815 isAllowed = phone.isCspPlmnEnabled();
8816 }
8817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 return isAllowed;
8821 }
8822
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008823 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8824 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008825 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008826 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008827 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008828 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8829 if (phone == null) {
8830 return false;
8831 }
8832 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8833 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8834 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008835 }
8836
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008837 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008838 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008839 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008840 mApp.getSystemService(AppOpsManager.class)
8841 .checkPackage(Binder.getCallingUid(), callingPackage);
8842
Jordan Liu1e142fc2019-04-22 15:10:43 -07008843 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008844 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008845 try {
8846 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008847 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008848 } catch (SecurityException e) {
8849 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8850 // has carrier privileges on an active UICC
8851 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8852 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008853 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008854 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008855 }
sandeepjsb6c87872021-09-27 15:34:44 +00008856 // checking compatibility, if calling app's target SDK is T and beyond.
8857 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8858 Binder.getCallingUid())) {
8859 isIccIdAccessRestricted = true;
8860 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008861 final long identity = Binder.clearCallingIdentity();
8862 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008863 UiccController uiccController = UiccController.getInstance();
8864 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008865 if (hasReadPermission) {
8866 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008867 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008868
8869 // Remove private info if the caller doesn't have access
8870 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8871 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008872 //setting the value after compatibility check
8873 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008874 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8875 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008876 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008877 if (card == null) {
8878 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008879 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008880 continue;
8881 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008882 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8883 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008884 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008885 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008886 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008887 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8888 for (UiccPortInfo portInfo : portInfos) {
8889 UiccPort port = uiccController.getUiccPortForSlot(
8890 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8891 if (port == null) {
8892 // assume no access if port is null
8893 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8894 continue;
8895 }
8896 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8897 uiccPortInfos.add(portInfo);
8898 } else {
8899 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8900 }
8901 }
8902 filteredInfos.add(new UiccCardInfo(
8903 cardInfo.isEuicc(),
8904 cardInfo.getCardId(),
8905 null,
8906 cardInfo.getPhysicalSlotIndex(),
8907 cardInfo.isRemovable(),
8908 cardInfo.isMultipleEnabledProfilesSupported(),
8909 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008910 }
8911 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008912 } finally {
8913 Binder.restoreCallingIdentity(identity);
8914 }
8915 }
8916
sandeepjsb6c87872021-09-27 15:34:44 +00008917 /**
8918 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8919 * generally private and require carrier privileges to view.
8920 *
8921 * @hide
8922 */
8923 @NonNull
8924 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8925 List<UiccPortInfo> portinfo = new ArrayList<>();
8926 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8927 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8928 }
8929 return new UiccCardInfo(
8930 cardInfo.isEuicc(),
8931 cardInfo.getCardId(),
8932 null,
8933 cardInfo.getPhysicalSlotIndex(),
8934 cardInfo.isRemovable(),
8935 cardInfo.isMultipleEnabledProfilesSupported(),
8936 portinfo
8937 );
8938 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008939
sandeepjsb6c87872021-09-27 15:34:44 +00008940 /**
8941 * @hide
8942 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8943 * These values are generally private and require carrier privileges to view.
8944 */
8945 @NonNull
8946 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8947 return new UiccPortInfo(
8948 UiccPortInfo.ICCID_REDACTED,
8949 portInfo.getPortIndex(),
8950 portInfo.getLogicalSlotIndex(),
8951 portInfo.isActive()
8952 );
8953 }
8954 @Override
8955 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008956 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008957 mApp.getSystemService(AppOpsManager.class)
8958 .checkPackage(Binder.getCallingUid(), callingPackage);
8959
8960 boolean hasReadPermission = false;
8961 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008962
8963 try {
8964 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8965 hasReadPermission = true;
8966 } catch (SecurityException e) {
8967 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8968 // has carrier privileges on an active UICC
8969 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8970 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8971 hasReadPermission = true;
8972 }
8973 }
8974
8975 // checking compatibility, if calling app's target SDK is T and beyond.
8976 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8977 Binder.getCallingUid())) {
8978 isLogicalSlotAccessRestricted = true;
8979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 final long identity = Binder.clearCallingIdentity();
8981 try {
8982 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008983 if (slots == null || slots.length == 0) {
8984 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 return null;
8986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8988 for (int i = 0; i < slots.length; i++) {
8989 UiccSlot slot = slots[i];
8990 if (slot == null) {
8991 continue;
8992 }
8993
Jordan Liu7be7e652019-05-06 18:55:02 +00008994 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008995 UiccCard card = slot.getUiccCard();
8996 if (card != null) {
8997 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008998 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008999 cardId = slot.getEid();
9000 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009001 // If cardId is null, use iccId of default port as cardId. Check if has
9002 // read permission otherwise set to null.(card is null which means no
9003 // carrier permission)
9004 cardId = hasReadPermission ? slot.getIccId(
9005 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07009006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009007 }
9008
Jordan Liu857451f2019-05-09 16:35:35 -07009009 if (cardId != null) {
9010 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9011 // if cardId is an EID, it's all digits so this is fine
9012 cardId = IccUtils.stripTrailingFs(cardId);
9013 }
9014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009015 int cardState = 0;
9016 switch (slot.getCardState()) {
9017 case CARDSTATE_ABSENT:
9018 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9019 break;
9020 case CARDSTATE_PRESENT:
9021 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9022 break;
9023 case CARDSTATE_ERROR:
9024 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9025 break;
9026 case CARDSTATE_RESTRICTED:
9027 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9028 break;
9029 default:
9030 break;
9031
9032 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009033 List<UiccPortInfo> portInfos = new ArrayList<>();
9034 int[] portIndexes = slot.getPortList();
9035 for (int portIdx : portIndexes) {
9036 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9037 callingPackage, hasReadPermission));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009038 portInfos.add(new UiccPortInfo(iccId, portIdx,
9039 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 slot.isEuicc(),
9043 cardId,
9044 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009045 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009046 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009047 //setting the value after compatibility check
9048 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 }
9050 return infos;
9051 } finally {
9052 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009053 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009054 }
9055
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009056 /* Returns null if doesn't have read permission or carrier privilege access. */
9057 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9058 boolean hasReadPermission) {
9059 String iccId = slot.getIccId(portIndex);
9060 if (hasReadPermission) { // if has read permission
9061 return iccId;
9062 } else {
9063 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9064 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9065 // if no read permission, checking carrier privilege access
9066 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9067 return iccId;
9068 }
9069 }
9070 }
9071 // No read permission or carrier privilege access.
9072 return UiccPortInfo.ICCID_REDACTED;
9073 }
9074
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009075 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009076 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009077 public boolean switchSlots(int[] physicalSlots) {
9078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079
9080 final long identity = Binder.clearCallingIdentity();
9081 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009082 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9083 for (int i = 0; i < physicalSlots.length; i++) {
9084 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9085 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9086 physicalSlots[i], i));
9087 }
9088 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009092 }
Jack Yu4c988042018-02-27 15:30:01 -08009093
9094 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009095 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9096 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9097 enforceModifyPermission();
9098
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009101 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009102 } finally {
9103 Binder.restoreCallingIdentity(identity);
9104 }
9105 }
9106
9107 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009108 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009109 final long identity = Binder.clearCallingIdentity();
9110 try {
9111 return UiccController.getInstance().getCardIdForDefaultEuicc();
9112 } finally {
9113 Binder.restoreCallingIdentity(identity);
9114 }
9115 }
9116
Pengquan Meng85728fb2018-03-12 16:31:21 -07009117 /**
goneil47ffb6e2018-04-06 15:40:58 -07009118 * A test API to reload the UICC profile.
9119 *
9120 * <p>Requires that the calling app has permission
9121 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9122 * @hide
9123 */
9124 @Override
9125 public void refreshUiccProfile(int subId) {
9126 enforceModifyPermission();
9127
9128 final long identity = Binder.clearCallingIdentity();
9129 try {
9130 Phone phone = getPhone(subId);
9131 if (phone == null) {
9132 return;
9133 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009134 UiccPort uiccPort = phone.getUiccPort();
9135 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009136 return;
9137 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009138 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009139 if (uiccProfile == null) {
9140 return;
9141 }
9142 uiccProfile.refresh();
9143 } finally {
9144 Binder.restoreCallingIdentity(identity);
9145 }
9146 }
9147
9148 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009149 * Returns false if the mobile data is disabled by default, otherwise return true.
9150 */
9151 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009152 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009153 }
9154
9155 /**
9156 * Returns true if the data roaming is enabled by default, i.e the system property
9157 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9158 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9159 */
9160 private boolean getDefaultDataRoamingEnabled(int subId) {
9161 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009162 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009163 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009164 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9165 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9166 return isDataRoamingEnabled;
9167 }
9168
9169 /**
9170 * Returns the default network type for the given {@code subId}, if the default network type is
9171 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9172 */
9173 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009174 List<Integer> list = TelephonyProperties.default_network();
9175 int phoneId = mSubscriptionController.getPhoneId(subId);
9176 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9177 return list.get(phoneId);
9178 }
9179 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009180 }
fionaxua13278b2018-03-21 00:08:13 -07009181
9182 @Override
9183 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009184 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009185 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009186
9187 final long identity = Binder.clearCallingIdentity();
9188 try {
9189 final Phone phone = getPhone(subId);
9190 if (phone == null) {
9191 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9192 return;
9193 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009194 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9195 if (cpt != null) {
9196 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9197 }
9198 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009199 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9200 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009201 if (carrierPrivilegeRules == null) {
9202 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9203 } else {
9204 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009206 } finally {
9207 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009208 }
fionaxua13278b2018-03-21 00:08:13 -07009209 }
9210
9211 @Override
9212 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009213 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009214
9215 final long identity = Binder.clearCallingIdentity();
9216 try {
9217 final Phone phone = getPhone(subId);
9218 if (phone == null) {
9219 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9220 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9221 }
9222 return phone.getCarrierIdListVersion();
9223 } finally {
9224 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009225 }
fionaxua13278b2018-03-21 00:08:13 -07009226 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009227
9228 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009229 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9230 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009232 mApp, subId, callingPackage, callingFeatureId,
9233 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009234 return -1;
9235 }
9236
9237 final long identity = Binder.clearCallingIdentity();
9238 try {
9239 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9240 } finally {
9241 Binder.restoreCallingIdentity(identity);
9242 }
9243 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009244
9245 @Override
9246 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009247 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009248 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009249 mApp, subId, "getCdmaRoamingMode");
9250
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
9257 }
9258
9259 @Override
9260 public boolean setCdmaRoamingMode(int subId, int mode) {
9261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9262 mApp, subId, "setCdmaRoamingMode");
9263
9264 final long identity = Binder.clearCallingIdentity();
9265 try {
9266 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 }
9271
9272 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009273 public int getCdmaSubscriptionMode(int subId) {
9274 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009275 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009276 mApp, subId, "getCdmaSubscriptionMode");
9277
9278 final long identity = Binder.clearCallingIdentity();
9279 try {
9280 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 }
9285
9286 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009287 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9289 mApp, subId, "setCdmaSubscriptionMode");
9290
9291 final long identity = Binder.clearCallingIdentity();
9292 try {
9293 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9294 } finally {
9295 Binder.restoreCallingIdentity(identity);
9296 }
9297 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009298
sqianc5eccab2018-10-19 18:46:41 -07009299 @Override
sqian8c685422019-02-22 15:55:18 -08009300 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009301 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009303 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9304 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009305 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9306 }
9307 final long identity = Binder.clearCallingIdentity();
9308 try {
sqian854d44b2018-12-12 16:48:18 -08009309 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9310 for (Phone phone: PhoneFactory.getPhones()) {
9311 if (phone.getEmergencyNumberTracker() != null
9312 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9313 emergencyNumberListInternal.put(
9314 phone.getSubId(),
9315 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9316 }
sqian11b7a0e2018-12-05 18:48:28 -08009317 }
sqian854d44b2018-12-12 16:48:18 -08009318 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009319 } finally {
9320 Binder.restoreCallingIdentity(identity);
9321 }
sqianc5eccab2018-10-19 18:46:41 -07009322 }
9323
9324 @Override
sqian8c685422019-02-22 15:55:18 -08009325 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009326 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009327 if (!exactMatch) {
9328 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009329 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009330 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009331 }
9332 final long identity = Binder.clearCallingIdentity();
9333 try {
sqian854d44b2018-12-12 16:48:18 -08009334 for (Phone phone: PhoneFactory.getPhones()) {
9335 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009336 && phone.getEmergencyNumberTracker()
9337 .isEmergencyNumber(number, exactMatch)) {
9338 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009339 }
sqian11b7a0e2018-12-05 18:48:28 -08009340 }
9341 return false;
9342 } finally {
9343 Binder.restoreCallingIdentity(identity);
9344 }
9345 }
9346
sqianf4ca7ed2019-01-15 18:32:07 -08009347 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009348 * Start emergency callback mode for GsmCdmaPhone for testing.
9349 */
9350 @Override
9351 public void startEmergencyCallbackMode() {
9352 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9353 "startEmergencyCallbackMode");
9354 enforceModifyPermission();
9355 final long identity = Binder.clearCallingIdentity();
9356 try {
9357 for (Phone phone : PhoneFactory.getPhones()) {
9358 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9359 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9360 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9361 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9362 gsmCdmaPhone.obtainMessage(
9363 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9364 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9365 }
9366 }
9367 } finally {
9368 Binder.restoreCallingIdentity(identity);
9369 }
9370 }
9371
9372 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009373 * Update emergency number list for test mode.
9374 */
9375 @Override
9376 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9378 "updateEmergencyNumberListTestMode");
9379
9380 final long identity = Binder.clearCallingIdentity();
9381 try {
9382 for (Phone phone: PhoneFactory.getPhones()) {
9383 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9384 if (tracker != null) {
9385 tracker.executeEmergencyNumberTestModeCommand(action, num);
9386 }
9387 }
9388 } finally {
9389 Binder.restoreCallingIdentity(identity);
9390 }
9391 }
9392
9393 /**
9394 * Get the full emergency number list for test mode.
9395 */
9396 @Override
9397 public List<String> getEmergencyNumberListTestMode() {
9398 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9399 "getEmergencyNumberListTestMode");
9400
9401 final long identity = Binder.clearCallingIdentity();
9402 try {
9403 Set<String> emergencyNumbers = new HashSet<>();
9404 for (Phone phone: PhoneFactory.getPhones()) {
9405 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9406 if (tracker != null) {
9407 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9408 emergencyNumbers.add(num.getNumber());
9409 }
9410 }
9411 }
9412 return new ArrayList<>(emergencyNumbers);
9413 } finally {
9414 Binder.restoreCallingIdentity(identity);
9415 }
9416 }
9417
chen xud6b45bd2018-10-30 22:27:10 -07009418 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009419 public int getEmergencyNumberDbVersion(int subId) {
9420 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9421
9422 final long identity = Binder.clearCallingIdentity();
9423 try {
9424 final Phone phone = getPhone(subId);
9425 if (phone == null) {
9426 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9427 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9428 }
9429 return phone.getEmergencyNumberDbVersion();
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
9435 @Override
9436 public void notifyOtaEmergencyNumberDbInstalled() {
9437 enforceModifyPermission();
9438
9439 final long identity = Binder.clearCallingIdentity();
9440 try {
9441 for (Phone phone: PhoneFactory.getPhones()) {
9442 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9443 if (tracker != null) {
9444 tracker.updateOtaEmergencyNumberDatabase();
9445 }
9446 }
9447 } finally {
9448 Binder.restoreCallingIdentity(identity);
9449 }
9450 }
9451
9452 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009453 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009454 enforceActiveEmergencySessionPermission();
9455
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
9458 for (Phone phone: PhoneFactory.getPhones()) {
9459 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9460 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009461 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9462 }
9463 }
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
9469 @Override
9470 public void resetOtaEmergencyNumberDbFilePath() {
9471 enforceActiveEmergencySessionPermission();
9472
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
9475 for (Phone phone: PhoneFactory.getPhones()) {
9476 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9477 if (tracker != null) {
9478 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009479 }
9480 }
9481 } finally {
9482 Binder.restoreCallingIdentity(identity);
9483 }
9484 }
9485
9486 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009487 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9488 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9489 Phone phone = getPhone(subId);
9490 if (phone == null) {
9491 return null;
9492 }
9493 final long identity = Binder.clearCallingIdentity();
9494 try {
9495 UiccProfile profile = UiccController.getInstance()
9496 .getUiccProfileForPhone(phone.getPhoneId());
9497 if (profile != null) {
9498 return profile.getCertsFromCarrierPrivilegeAccessRules();
9499 }
9500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
9503 return null;
9504 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009505
9506 /**
9507 * Enable or disable a modem stack.
9508 */
9509 @Override
9510 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9511 enforceModifyPermission();
9512
9513 final long identity = Binder.clearCallingIdentity();
9514 try {
9515 Phone phone = PhoneFactory.getPhone(slotIndex);
9516 if (phone == null) {
9517 return false;
9518 } else {
9519 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9520 }
9521 } finally {
9522 Binder.restoreCallingIdentity(identity);
9523 }
9524 }
Michelecea4cf22018-12-21 15:00:11 -08009525
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009526 /**
9527 * Whether a modem stack is enabled or not.
9528 */
9529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009530 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9531 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009532 Phone phone = PhoneFactory.getPhone(slotIndex);
9533 if (phone == null) return false;
9534
9535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009536 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9537 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009538 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9539 }
9540
9541 final long identity = Binder.clearCallingIdentity();
9542 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009543 try {
9544 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9545 } catch (NoSuchElementException ex) {
9546 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9547 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009548 } finally {
9549 Binder.restoreCallingIdentity(identity);
9550 }
9551 }
9552
Michelecea4cf22018-12-21 15:00:11 -08009553 @Override
Michele0ea7d782019-03-19 14:58:42 -07009554 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009555 enforceModifyPermission();
9556
9557 final long identity = Binder.clearCallingIdentity();
9558 try {
9559 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009560 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009561 .commit();
9562 } finally {
9563 Binder.restoreCallingIdentity(identity);
9564 }
9565 }
9566
9567 @Override
Michele0ea7d782019-03-19 14:58:42 -07009568 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009569 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009571 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9572 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009573 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009574 }
Michelecea4cf22018-12-21 15:00:11 -08009575
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
Michele0ea7d782019-03-19 14:58:42 -07009578 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009583
Michele0ea7d782019-03-19 14:58:42 -07009584 @TelephonyManager.IsMultiSimSupportedResult
9585 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009586 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9587 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9588 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009589 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9590 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009591 }
9592 // Check if the hardware supports multisim functionality. If usage of multisim is not
9593 // supported by the modem, indicate that it is restricted.
9594 PhoneCapability staticCapability =
9595 mPhoneConfigurationManager.getStaticPhoneCapability();
9596 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009597 loge("isMultiSimSupportedInternal: no static configuration available");
9598 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009599 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009600 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009601 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9602 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009603 }
9604 // Check if support of multiple SIMs is restricted by carrier
9605 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009606 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009607 }
9608
Michele0ea7d782019-03-19 14:58:42 -07009609 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009610 }
9611
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009612 /**
9613 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009614 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9615 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9616 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009617 * @param numOfSims number of active sims we want to switch to
9618 */
9619 @Override
9620 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009621 if (numOfSims == 1) {
9622 enforceModifyPermission();
9623 } else {
9624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9625 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9626 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009627 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009628
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009629 try {
Michele30b57b22019-03-01 12:01:14 -08009630 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009631 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009632 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9633 return;
9634 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009635 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9636 } finally {
9637 Binder.restoreCallingIdentity(identity);
9638 }
9639 }
9640
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009641 @Override
9642 public boolean isApplicationOnUicc(int subId, int appType) {
9643 enforceReadPrivilegedPermission("isApplicationOnUicc");
9644 Phone phone = getPhone(subId);
9645 if (phone == null) {
9646 return false;
9647 }
9648 final long identity = Binder.clearCallingIdentity();
9649 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009650 UiccPort uiccPort = phone.getUiccPort();
9651 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009652 return false;
9653 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009654 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009655 if (uiccProfile == null) {
9656 return false;
9657 }
9658 if (TelephonyManager.APPTYPE_SIM <= appType
9659 && appType <= TelephonyManager.APPTYPE_ISIM) {
9660 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9661 }
9662 return false;
9663 } finally {
9664 Binder.restoreCallingIdentity(identity);
9665 }
9666 }
9667
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009668 /**
chen xub4baa772019-04-03 10:23:41 -07009669 * Get whether making changes to modem configurations will trigger reboot.
9670 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009671 */
9672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009673 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9674 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009676 mApp, subId, callingPackage, callingFeatureId,
9677 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009678 return false;
9679 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009680 final long identity = Binder.clearCallingIdentity();
9681 try {
9682 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9683 } finally {
9684 Binder.restoreCallingIdentity(identity);
9685 }
9686 }
9687
Nathan Harold29f5f052019-02-15 13:41:57 -08009688 private void updateModemStateMetrics() {
9689 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9690 // TODO: check the state for each modem if the api is ready.
9691 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9692 }
9693
Pengquan Meng3889a572019-01-23 11:16:29 -08009694 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009695 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009696 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009697 // Verify that the callingPackage belongs to the calling UID
9698 mApp.getSystemService(AppOpsManager.class)
9699 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009700 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009701 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009702 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009703 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9704 if (slotInfos != null) {
9705 for (int i = 0; i < slotInfos.length; i++) {
9706 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9707 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9708 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9709 portInfo.getLogicalSlotIndex()));
9710 }
9711 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009712 }
9713 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009714 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
9718 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009719
9720 /**
9721 * Get the IRadio HAL Version
9722 */
9723 @Override
9724 public int getRadioHalVersion() {
9725 Phone phone = getDefaultPhone();
9726 if (phone == null) return -1;
9727 HalVersion hv = phone.getHalVersion();
9728 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9729 return hv.major * 100 + hv.minor;
9730 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009731
9732 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009733 * Get the current calling package name.
9734 * @return the current calling package name
9735 */
9736 @Override
9737 public String getCurrentPackageName() {
9738 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9739 }
9740
9741 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009742 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9743 * corresponding network requests on a subId.
9744 *
9745 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009746 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009747 * 2) APN is un-metered for this subscription, or
9748 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009749 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009750 *
9751 * @return whether data is allowed for a apn type.
9752 *
9753 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009754 */
9755 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009756 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009757 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9758 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009759
9760 // Now that all security checks passes, perform the operation as ourselves.
9761 final long identity = Binder.clearCallingIdentity();
9762 try {
9763 Phone phone = getPhone(subId);
9764 if (phone == null) return false;
9765
Jack Yu41407ee2019-05-13 16:54:09 -07009766 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009767 boolean isDataEnabled;
9768 if (phone.isUsingNewDataStack()) {
9769 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9770 } else {
9771 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9772 }
9773 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009774 } finally {
9775 Binder.restoreCallingIdentity(identity);
9776 }
9777 }
9778
9779 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009780 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009781 enforceReadPrivilegedPermission("isApnMetered");
9782
9783 // Now that all security checks passes, perform the operation as ourselves.
9784 final long identity = Binder.clearCallingIdentity();
9785 try {
9786 Phone phone = getPhone(subId);
9787 if (phone == null) return true; // By default return true.
9788
Jack Yu41407ee2019-05-13 16:54:09 -07009789 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009794
9795 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009796 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9797 int subscriptionId, IBooleanConsumer resultCallback) {
9798 enforceModifyPermission();
9799 long token = Binder.clearCallingIdentity();
9800 try {
9801 Phone phone = getPhone(subscriptionId);
9802 if (phone == null) {
9803 try {
9804 if (resultCallback != null) {
9805 resultCallback.accept(false);
9806 }
9807 } catch (RemoteException e) {
9808 // ignore
9809 }
9810 return;
9811 }
9812 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9813 Pair.create(specifiers, (x) -> {
9814 try {
9815 if (resultCallback != null) {
9816 resultCallback.accept(x);
9817 }
9818 } catch (RemoteException e) {
9819 // ignore
9820 }
9821 });
9822 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9823 } finally {
9824 Binder.restoreCallingIdentity(token);
9825 }
9826 }
9827
9828 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009829 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9830 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009831 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009832 mApp, subId, "getSystemSelectionChannels");
9833 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9834 final long identity = Binder.clearCallingIdentity();
9835 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009836 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9837 if (result instanceof IllegalStateException) {
9838 throw (IllegalStateException) result;
9839 }
9840 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009841 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9842 return specifiers;
9843 } finally {
9844 Binder.restoreCallingIdentity(identity);
9845 }
9846 }
9847
9848 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009849 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009850 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009851 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9852 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9853 if (iccRecords == null) {
9854 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9855 return false;
9856 }
9857 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9858 }
9859
9860 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009861 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9862 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009863 if (callingPackage == null) {
9864 callingPackage = getCurrentPackageName();
9865 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009866 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9867 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009868 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9869 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009870 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9871 }
9872 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9873 Intent intent = new Intent();
9874 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9875 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9876 // Bring up choose default SMS subscription dialog right now
9877 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9878 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9879 mApp.startActivity(intent);
9880 }
chen xud5ca2d52019-05-28 15:20:57 -07009881
9882 @Override
9883 public String getMmsUAProfUrl(int subId) {
9884 //TODO investigate if this API should require proper permission check in R b/133791609
9885 final long identity = Binder.clearCallingIdentity();
9886 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009887 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9888 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9889 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9890 return carrierUAProfUrl;
9891 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009892 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9893 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009894 } finally {
9895 Binder.restoreCallingIdentity(identity);
9896 }
9897 }
9898
9899 @Override
9900 public String getMmsUserAgent(int subId) {
9901 //TODO investigate if this API should require proper permission check in R b/133791609
9902 final long identity = Binder.clearCallingIdentity();
9903 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009904 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9905 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9906 if (!TextUtils.isEmpty(carrierUserAgent)) {
9907 return carrierUserAgent;
9908 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009909 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9910 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009911 } finally {
9912 Binder.restoreCallingIdentity(identity);
9913 }
9914 }
Jack Yub07d4972019-05-28 16:12:25 -07009915
9916 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009917 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9918 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009919
Jack Yub07d4972019-05-28 16:12:25 -07009920 final long identity = Binder.clearCallingIdentity();
9921 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009922 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009923 if (phone == null) return false;
9924
Hall Liua62f5da2020-09-25 10:42:19 -07009925 switch (policy) {
9926 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009927 if (phone.isUsingNewDataStack()) {
9928 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9929 } else {
9930 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9931 }
Hall Liua62f5da2020-09-25 10:42:19 -07009932 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009933 if (phone.isUsingNewDataStack()) {
9934 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9935 } else {
9936 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9937 }
Hall Liua62f5da2020-09-25 10:42:19 -07009938 default:
9939 throw new IllegalArgumentException(policy + " is not a valid policy");
9940 }
Jack Yub07d4972019-05-28 16:12:25 -07009941 } finally {
9942 Binder.restoreCallingIdentity(identity);
9943 }
9944 }
9945
9946 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009947 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009948 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009949 enforceModifyPermission();
9950
changbettyd5c246e2019-12-24 15:40:37 +08009951 final long identity = Binder.clearCallingIdentity();
9952 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009953 Phone phone = getPhone(subscriptionId);
9954 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009955
Hall Liua62f5da2020-09-25 10:42:19 -07009956 switch (policy) {
9957 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009958 if (phone.isUsingNewDataStack()) {
9959 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9960 } else {
9961 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9962 }
Hall Liua62f5da2020-09-25 10:42:19 -07009963 break;
9964 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009965 if (phone.isUsingNewDataStack()) {
9966 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9967 } else {
9968 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9969 }
Hall Liua62f5da2020-09-25 10:42:19 -07009970 break;
9971 default:
9972 throw new IllegalArgumentException(policy + " is not a valid policy");
9973 }
changbettyd5c246e2019-12-24 15:40:37 +08009974 } finally {
9975 Binder.restoreCallingIdentity(identity);
9976 }
9977 }
9978
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009979 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009980 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009981 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9982 * otherwise.
9983 */
9984 @Override
9985 public void setCepEnabled(boolean isCepEnabled) {
9986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9987
9988 final long identity = Binder.clearCallingIdentity();
9989 try {
9990 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9991 for (Phone phone : PhoneFactory.getPhones()) {
9992 Phone defaultPhone = phone.getImsPhone();
9993 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9994 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9995 ImsPhoneCallTracker imsPhoneCallTracker =
9996 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9997 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9998 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9999 + imsPhone.getMsisdn());
10000 }
10001 }
10002 } finally {
10003 Binder.restoreCallingIdentity(identity);
10004 }
10005 }
allenwtsu46dcc572020-01-08 18:24:03 +080010006
10007 /**
10008 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10009 *
10010 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10011 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10012 * before being read.
10013 */
10014 @Override
10015 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10016 isCompressed) {
10017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10018 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010019 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10020 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10021 }
10022 if (!isImsAvailableOnDevice()) {
10023 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10024 "IMS not available on device.");
10025 }
10026
10027 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010028 try {
Hui Wang761a6682020-10-31 05:12:53 +000010029 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10030 } finally {
10031 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010032 }
10033 }
zoey chene02881a2019-12-30 16:11:23 +080010034
10035 @Override
10036 public boolean isIccLockEnabled(int subId) {
10037 enforceReadPrivilegedPermission("isIccLockEnabled");
10038
10039 // Now that all security checks passes, perform the operation as ourselves.
10040 final long identity = Binder.clearCallingIdentity();
10041 try {
10042 Phone phone = getPhone(subId);
10043 if (phone != null && phone.getIccCard() != null) {
10044 return phone.getIccCard().getIccLockEnabled();
10045 } else {
10046 return false;
10047 }
10048 } finally {
10049 Binder.restoreCallingIdentity(identity);
10050 }
10051 }
10052
10053 /**
10054 * Set the ICC pin lock enabled or disabled.
10055 *
10056 * @return an integer representing the status of IccLock enabled or disabled in the following
10057 * three cases:
10058 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10059 * successfully.
10060 * - Positive number and zero for remaining password attempts.
10061 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10062 *
10063 */
10064 @Override
10065 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10066 enforceModifyPermission();
10067
10068 Phone phone = getPhone(subId);
10069 if (phone == null) {
10070 return 0;
10071 }
10072 // Now that all security checks passes, perform the operation as ourselves.
10073 final long identity = Binder.clearCallingIdentity();
10074 try {
10075 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10076 new Pair<Boolean, String>(enabled, password), phone, null);
10077 return attemptsRemaining;
10078
10079 } catch (Exception e) {
10080 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10081 } finally {
10082 Binder.restoreCallingIdentity(identity);
10083 }
10084 return 0;
10085 }
10086
10087 /**
10088 * Change the ICC password used in ICC pin lock.
10089 *
10090 * @return an integer representing the status of IccLock changed in the following three cases:
10091 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10092 * - Positive number and zero for remaining password attempts.
10093 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10094 *
10095 */
10096 @Override
10097 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10098 enforceModifyPermission();
10099
10100 Phone phone = getPhone(subId);
10101 if (phone == null) {
10102 return 0;
10103 }
10104 // Now that all security checks passes, perform the operation as ourselves.
10105 final long identity = Binder.clearCallingIdentity();
10106 try {
10107 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10108 new Pair<String, String>(oldPassword, newPassword), phone, null);
10109 return attemptsRemaining;
10110
10111 } catch (Exception e) {
10112 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10113 } finally {
10114 Binder.restoreCallingIdentity(identity);
10115 }
10116 return 0;
10117 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010118
10119 /**
10120 * Request for receiving user activity notification
10121 */
10122 @Override
10123 public void requestUserActivityNotification() {
10124 if (!mNotifyUserActivity.get()
10125 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10126 mNotifyUserActivity.set(true);
10127 }
10128 }
10129
10130 /**
10131 * Called when userActivity is signalled in the power manager.
10132 * This is safe to call from any thread, with any window manager locks held or not.
10133 */
10134 @Override
10135 public void userActivity() {
10136 // ***************************************
10137 // * Inherited from PhoneWindowManager *
10138 // ***************************************
10139 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10140 // WITH ITS LOCKS HELD.
10141 //
10142 // This code must be VERY careful about the locks
10143 // it acquires.
10144 // In fact, the current code acquires way too many,
10145 // and probably has lurking deadlocks.
10146
10147 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10148 throw new SecurityException("Only the OS may call notifyUserActivity()");
10149 }
10150
10151 if (mNotifyUserActivity.getAndSet(false)) {
10152 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10153 USER_ACTIVITY_NOTIFICATION_DELAY);
10154 }
10155 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010156
10157 @Override
10158 public boolean canConnectTo5GInDsdsMode() {
10159 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10160 }
Jack Yud10cdd42020-09-28 20:28:01 -070010161
10162 @Override
10163 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10164 String callingFeatureId) {
10165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10166 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10167 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10168 }
10169
10170 Phone phone = getPhone(subId);
10171 if (phone == null) {
10172 throw new RuntimeException("phone is not available");
10173 }
10174 // Now that all security checks passes, perform the operation as ourselves.
10175 final long identity = Binder.clearCallingIdentity();
10176 try {
10177 return phone.getEquivalentHomePlmns();
10178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
10181 }
Daniel Bright59e67312020-11-13 11:49:37 -080010182
10183 @Override
10184 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010185 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10186 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010187 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010188 if (radioInterfaceCapabilities == null) {
10189 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010190 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010191 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010192 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010193
Hui Wang641e81c2020-10-12 12:14:23 -070010194 @Override
10195 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10196 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010197 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10198 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10199 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10200 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10201 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010202 if (DBG) {
10203 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10204 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10205 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10206 }
10207
10208 if (!SubscriptionManager.isValidSubscriptionId(subId)
10209 || appType < TelephonyManager.APPTYPE_UNKNOWN
10210 || appType > TelephonyManager.APPTYPE_ISIM
10211 || nafUrl == null || securityProtocol == null || callback == null) {
10212 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10213 if (callback != null) {
10214 try {
10215 callback.onAuthenticationFailure(
10216 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10217 } catch (RemoteException exception) {
10218 log("Fail to notify onAuthenticationFailure due to " + exception);
10219 }
10220 return;
10221 }
10222 }
10223
10224 final long token = Binder.clearCallingIdentity();
10225 try {
10226 getGbaManager(subId).bootstrapAuthenticationRequest(
10227 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10228 forceBootStrapping, callback));
10229 } finally {
10230 Binder.restoreCallingIdentity(token);
10231 }
10232 }
10233
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010234 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010235 * Attempts to set the radio power state for all phones for thermal reason.
10236 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010237 * requested radio power state will actually be set. See {@link
10238 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10239 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010240 * @param enable {@code true} if trying to turn radio on.
10241 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10242 * false}.
10243 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010244 private boolean setRadioPowerForThermal(boolean enable) {
10245 boolean isPhoneAvailable = false;
10246 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10247 Phone phone = PhoneFactory.getPhone(i);
10248 if (phone != null) {
10249 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10250 isPhoneAvailable = true;
10251 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010252 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010253
10254 // return true if successfully informed the phone object about the thermal radio power
10255 // request.
10256 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 }
10258
10259 private int handleDataThrottlingRequest(int subId,
10260 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010261 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10262 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10263 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10264 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10265 throw new IllegalArgumentException("modem does not support data throttling");
10266 }
10267
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010268 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10269 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010270 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010271 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10272 }
10273
10274 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10275
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010276 if (isDataThrottlingSupported) {
10277 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010278 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010279 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10280 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10281 } else if (thermalMitigationResult
10282 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010283 log("Modem likely does not support data throttling on secondary carrier. Data " +
10284 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10285 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010286 }
10287 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010288 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010289
10290 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010291 }
10292
Jack Nudelman644b91a2021-03-12 14:09:48 -080010293 private static List<String> getThermalMitigationAllowlist(Context context) {
10294 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10295 for (String pckg : context.getResources()
10296 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10297 sThermalMitigationAllowlistedPackages.add(pckg);
10298 }
10299 }
10300
10301 return sThermalMitigationAllowlistedPackages;
10302 }
10303
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010304 private boolean isAnyPhoneInEmergencyState() {
10305 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10306 if (tm.isInEmergencyCall()) {
10307 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10308 return true;
10309 }
10310 for (Phone phone : PhoneFactory.getPhones()) {
10311 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10312 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10313 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10314 + phone.isInEcm());
10315 return true;
10316 }
10317 }
10318
10319 return false;
10320 }
10321
Jack Nudelman644b91a2021-03-12 14:09:48 -080010322 /**
10323 * Used by shell commands to add an authorized package name for thermal mitigation.
10324 * @param packageName name of package to be allowlisted
10325 * @param context
10326 */
10327 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10328 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10329 sThermalMitigationAllowlistedPackages.add(packageName);
10330 }
10331
10332 /**
10333 * Used by shell commands to remove an authorized package name for thermal mitigation.
10334 * @param packageName name of package to remove from allowlist
10335 * @param context
10336 */
10337 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10338 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10339 sThermalMitigationAllowlistedPackages.remove(packageName);
10340 }
10341
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010342 /**
10343 * Thermal mitigation request to control functionalities at modem.
10344 *
10345 * @param subId the id of the subscription.
10346 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010347 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010348 *
10349 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10350 */
10351 @Override
10352 @ThermalMitigationResult
10353 public int sendThermalMitigationRequest(
10354 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010355 ThermalMitigationRequest thermalMitigationRequest,
10356 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010357 enforceModifyPermission();
10358
Jack Nudelman644b91a2021-03-12 14:09:48 -080010359 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10360 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10361 .contains(callingPackage)) {
10362 throw new SecurityException("Calling package must be configured in the device config. "
10363 + "calling package: " + callingPackage);
10364 }
10365
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010366 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10367 final long identity = Binder.clearCallingIdentity();
10368
10369 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10370 try {
10371 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10372 switch (thermalMitigationAction) {
10373 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10374 thermalMitigationResult =
10375 handleDataThrottlingRequest(subId,
10376 thermalMitigationRequest.getDataThrottlingRequest());
10377 break;
10378 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10379 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10380 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10381 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10382 }
10383
10384 // Ensure that radio is on. If not able to power on due to phone being
10385 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010386 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010387 thermalMitigationResult =
10388 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10389 break;
10390 }
10391
10392 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10393 false);
10394 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10395 break;
10396 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10397 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10398 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10399 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10400 }
10401
10402 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10403 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010404 Phone phone = getPhone(subId);
10405 if (phone == null) {
10406 thermalMitigationResult =
10407 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10408 break;
10409 }
10410
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010411 TelephonyConnectionService service =
10412 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010413 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010414 Log.e(LOG_TAG, "An emergency call is pending");
10415 thermalMitigationResult =
10416 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10417 break;
10418 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010419 thermalMitigationResult =
10420 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10421 break;
10422 }
10423 } else {
10424 thermalMitigationResult =
10425 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10426 break;
10427 }
10428
10429 // Turn radio off. If not able to power off due to phone being unavailable,
10430 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010431 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010432 thermalMitigationResult =
10433 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10434 break;
10435 }
10436 thermalMitigationResult =
10437 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10438 break;
10439 default:
10440 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10441 + "not exist. Requested action: " + thermalMitigationAction);
10442 }
10443 } catch (IllegalArgumentException e) {
10444 throw e;
10445 } catch (Exception e) {
10446 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10447 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10448 } finally {
10449 Binder.restoreCallingIdentity(identity);
10450 }
10451
10452 if (DBG) {
10453 log("thermalMitigationRequest returning with thermalMitigationResult: "
10454 + thermalMitigationResult);
10455 }
10456
10457 return thermalMitigationResult;
10458 }
Hui Wang641e81c2020-10-12 12:14:23 -070010459
10460 /**
10461 * Set the GbaService Package Name that Telephony will bind to.
10462 *
10463 * @param subId The sim that the GbaService is associated with.
10464 * @param packageName The name of the package to be replaced with.
10465 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10466 */
10467 @Override
10468 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10469 enforceModifyPermission();
10470
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 return getGbaManager(subId).overrideServicePackage(packageName);
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477 }
10478
10479 /**
10480 * Return the package name of the currently bound GbaService.
10481 *
10482 * @param subId The sim that the GbaService is associated with.
10483 * @return the package name of the GbaService configuration, null if GBA is not supported.
10484 */
10485 @Override
10486 public String getBoundGbaService(int subId) {
10487 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10488
10489 final long identity = Binder.clearCallingIdentity();
10490 try {
10491 return getGbaManager(subId).getServicePackage();
10492 } finally {
10493 Binder.restoreCallingIdentity(identity);
10494 }
10495 }
10496
10497 /**
10498 * Set the release time for telephony to unbind GbaService.
10499 *
10500 * @param subId The sim that the GbaService is associated with.
10501 * @param interval The release time to unbind GbaService by millisecond.
10502 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10503 */
10504 @Override
10505 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10506 enforceModifyPermission();
10507
10508 final long identity = Binder.clearCallingIdentity();
10509 try {
10510 return getGbaManager(subId).overrideReleaseTime(interval);
10511 } finally {
10512 Binder.restoreCallingIdentity(identity);
10513 }
10514 }
10515
10516 /**
10517 * Return the release time for telephony to unbind GbaService.
10518 *
10519 * @param subId The sim that the GbaService is associated with.
10520 * @return The release time to unbind GbaService by millisecond.
10521 */
10522 @Override
10523 public int getGbaReleaseTime(int subId) {
10524 enforceReadPrivilegedPermission("getGbaReleaseTime");
10525
10526 final long identity = Binder.clearCallingIdentity();
10527 try {
10528 return getGbaManager(subId).getReleaseTime();
10529 } finally {
10530 Binder.restoreCallingIdentity(identity);
10531 }
10532 }
10533
10534 private GbaManager getGbaManager(int subId) {
10535 GbaManager instance = GbaManager.getInstance(subId);
10536 if (instance == null) {
10537 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10538 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10539 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10540 }
10541 return instance;
10542 }
Hui Wang761a6682020-10-31 05:12:53 +000010543
10544 /**
10545 * indicate whether the device and the carrier can support
10546 * RCS VoLTE single registration.
10547 */
10548 @Override
10549 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010550 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10551 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10552 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10553 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010554
10555 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10556 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10557 }
10558
10559 final long identity = Binder.clearCallingIdentity();
10560 try {
10561 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10562 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010563 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10564 if (isCapable != null) {
10565 return isCapable;
10566 }
Hui Wang761a6682020-10-31 05:12:53 +000010567 }
Hui Wang67af90e2021-06-04 16:57:15 -070010568 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10569 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010570 } finally {
10571 Binder.restoreCallingIdentity(identity);
10572 }
10573 }
10574
10575 /**
10576 * Register RCS provisioning callback.
10577 */
10578 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010579 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010580 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010581 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010582 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010583 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10584 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010585
10586 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10587 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10588 }
10589 if (!isImsAvailableOnDevice()) {
10590 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10591 "IMS not available on device.");
10592 }
10593
10594 final long identity = Binder.clearCallingIdentity();
10595 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010596 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010597 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010598 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10599 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010600 }
Hui Wang761a6682020-10-31 05:12:53 +000010601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
10605
10606 /**
10607 * Unregister RCS provisioning callback.
10608 */
10609 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010610 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010611 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010612 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010613 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010614 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10615 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010616
10617 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10618 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10619 }
10620 if (!isImsAvailableOnDevice()) {
10621 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10622 "IMS not available on device.");
10623 }
10624
10625 final long identity = Binder.clearCallingIdentity();
10626 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010627 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010628 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010629 } finally {
10630 Binder.restoreCallingIdentity(identity);
10631 }
10632 }
10633
10634 /**
10635 * trigger RCS reconfiguration.
10636 */
10637 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010638 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10639 "triggerRcsReconfiguration",
10640 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010641
10642 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10643 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10644 }
10645 if (!isImsAvailableOnDevice()) {
10646 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10647 "IMS not available on device.");
10648 }
10649
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
10652 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
10658 /**
10659 * Provide the client configuration parameters of the RCS application.
10660 */
10661 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010662 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10663 "setRcsClientConfiguration",
10664 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010665
10666 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10667 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10668 }
10669 if (!isImsAvailableOnDevice()) {
10670 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10671 "IMS not available on device.");
10672 }
10673
10674 final long identity = Binder.clearCallingIdentity();
10675
10676 try {
10677 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10678 if (configBinder == null) {
10679 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010680 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10681 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010682 } else {
10683 configBinder.setRcsClientConfiguration(rcc);
10684 }
joonhunshin3e154242021-09-17 06:33:39 +000010685
10686 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10687 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010688 } catch (RemoteException e) {
10689 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010690 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10691 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
10696
10697 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010698 * Enables or disables the test mode for RCS VoLTE single registration.
10699 */
10700 @Override
10701 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10702 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10703 "setRcsSingleRegistrationTestModeEnabled");
10704
10705 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10706 }
10707
10708 /**
10709 * Gets the test mode for RCS VoLTE single registration.
10710 */
10711 @Override
10712 public boolean getRcsSingleRegistrationTestModeEnabled() {
10713 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10714 "getRcsSingleRegistrationTestModeEnabled");
10715
10716 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10717 }
10718
10719 /**
Hui Wang761a6682020-10-31 05:12:53 +000010720 * Overrides the config of RCS VoLTE single registration enabled for the device.
10721 */
10722 @Override
10723 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10725 "setDeviceSingleRegistrationEnabledOverride");
10726 enforceModifyPermission();
10727
10728 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10729 : Boolean.parseBoolean(enabledStr);
10730 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010731 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010732 }
10733
10734 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010735 * Sends a device to device communication message. Only usable via shell.
10736 * @param message message to send.
10737 * @param value message value.
10738 */
10739 @Override
10740 public void sendDeviceToDeviceMessage(int message, int value) {
10741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010742 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010743 enforceModifyPermission();
10744
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 TelephonyConnectionService service =
10748 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10749 if (service == null) {
10750 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10751 return;
10752 }
10753 service.sendTestDeviceToDeviceMessage(message, value);
10754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757 }
10758
Tyler Gunnbabbda02021-02-10 11:05:02 -080010759 /**
10760 * Sets the specified device to device transport active.
10761 * @param transport The transport to set active.
10762 */
10763 @Override
10764 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10766 "setActiveDeviceToDeviceTransport");
10767 enforceModifyPermission();
10768
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 TelephonyConnectionService service =
10772 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10773 if (service == null) {
10774 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10775 return;
10776 }
10777 service.setActiveDeviceToDeviceTransport(transport);
10778 } finally {
10779 Binder.restoreCallingIdentity(identity);
10780 }
10781 }
Tyler Gunn92479152021-01-20 16:30:10 -080010782
Tyler Gunnd4339262021-05-03 14:46:49 -070010783 @Override
10784 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10786 "setDeviceToDeviceForceEnabled");
10787
10788 final long identity = Binder.clearCallingIdentity();
10789 try {
10790 Arrays.stream(PhoneFactory.getPhones()).forEach(
10791 p -> {
10792 Phone thePhone = p.getImsPhone();
10793 if (thePhone != null && thePhone instanceof ImsPhone) {
10794 ImsPhone imsPhone = (ImsPhone) thePhone;
10795 CallTracker tracker = imsPhone.getCallTracker();
10796 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10797 ImsPhoneCallTracker imsPhoneCallTracker =
10798 (ImsPhoneCallTracker) tracker;
10799 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10800 }
10801 }
10802 }
10803 );
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
10808
Tyler Gunn92479152021-01-20 16:30:10 -080010809 /**
Hui Wang761a6682020-10-31 05:12:53 +000010810 * Gets the config of RCS VoLTE single registration enabled for the device.
10811 */
10812 @Override
10813 public boolean getDeviceSingleRegistrationEnabled() {
10814 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10815 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10816 }
10817
10818 /**
10819 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10820 */
10821 @Override
10822 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10823 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10824 "setCarrierSingleRegistrationEnabledOverride");
10825 enforceModifyPermission();
10826
10827 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10828 : Boolean.parseBoolean(enabledStr);
10829 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10830 subId, enabled);
10831 }
10832
10833 /**
10834 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10835 */
10836 @Override
10837 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10838 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10839 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10840 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010841
10842 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010843 * Overrides the ims feature validation result
10844 */
10845 @Override
10846 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10848 "setImsFeatureValidationOverride");
10849
10850 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10851 : Boolean.parseBoolean(enabledStr);
10852 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10853 subId, enabled);
10854 }
10855
10856 /**
10857 * Gets the ims feature validation override value
10858 */
10859 @Override
10860 public boolean getImsFeatureValidationOverride(int subId) {
10861 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10862 "getImsFeatureValidationOverride");
10863 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10864 }
10865
10866 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010867 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10868 * their mobile plan.
10869 */
10870 @Override
10871 public String getMobileProvisioningUrl() {
10872 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10873 final long identity = Binder.clearCallingIdentity();
10874 try {
10875 return getDefaultPhone().getMobileProvisioningUrl();
10876 } finally {
10877 Binder.restoreCallingIdentity(identity);
10878 }
10879 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010880
James.cf Linbcdf8b32021-01-14 16:44:13 +080010881 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010882 * Get the EAB contact from the EAB database.
10883 */
10884 @Override
10885 public String getContactFromEab(String contact) {
10886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10887 enforceModifyPermission();
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
10895
10896 /**
Calvin Pana1434322021-07-01 19:27:01 +080010897 * Get the EAB capability from the EAB database.
10898 */
10899 @Override
10900 public String getCapabilityFromEab(String contact) {
10901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10902 enforceModifyPermission();
10903 final long identity = Binder.clearCallingIdentity();
10904 try {
10905 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10906 } finally {
10907 Binder.restoreCallingIdentity(identity);
10908 }
10909 }
10910
10911 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010912 * Remove the EAB contacts from the EAB database.
10913 */
10914 @Override
10915 public int removeContactFromEab(int subId, String contacts) {
10916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10917 enforceModifyPermission();
10918 final long identity = Binder.clearCallingIdentity();
10919 try {
10920 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10921 } finally {
10922 Binder.restoreCallingIdentity(identity);
10923 }
10924 }
10925
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010926 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010927 public boolean getDeviceUceEnabled() {
10928 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
10931 return mApp.getDeviceUceEnabled();
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
10936
10937 @Override
10938 public void setDeviceUceEnabled(boolean isEnabled) {
10939 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10940 final long identity = Binder.clearCallingIdentity();
10941 try {
10942 mApp.setDeviceUceEnabled(isEnabled);
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
10947
Brad Ebinger14d467f2021-02-12 06:18:28 +000010948 /**
10949 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10950 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10951 */
10952 // Used for SHELL command only right now.
10953 @Override
10954 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10955 List<String> featureTags) {
10956 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10957 "addUceRegistrationOverrideShell");
10958 final long identity = Binder.clearCallingIdentity();
10959 try {
10960 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10961 new ArraySet<>(featureTags));
10962 } catch (ImsException e) {
10963 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
10969 /**
10970 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10971 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10972 */
10973 // Used for SHELL command only right now.
10974 @Override
10975 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10976 List<String> featureTags) {
10977 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10978 "removeUceRegistrationOverrideShell");
10979 final long identity = Binder.clearCallingIdentity();
10980 try {
10981 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10982 new ArraySet<>(featureTags));
10983 } catch (ImsException e) {
10984 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10985 } finally {
10986 Binder.restoreCallingIdentity(identity);
10987 }
10988 }
10989
10990 /**
10991 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10992 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10993 */
10994 // Used for SHELL command only right now.
10995 @Override
10996 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10997 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10998 "clearUceRegistrationOverrideShell");
10999 final long identity = Binder.clearCallingIdentity();
11000 try {
11001 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11002 } catch (ImsException e) {
11003 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11004 } finally {
11005 Binder.restoreCallingIdentity(identity);
11006 }
11007 }
11008
11009 /**
11010 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11011 */
11012 // Used for SHELL command only right now.
11013 @Override
11014 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11015 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11016 "getLatestRcsContactUceCapabilityShell");
11017 final long identity = Binder.clearCallingIdentity();
11018 try {
11019 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11020 } catch (ImsException e) {
11021 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11022 } finally {
11023 Binder.restoreCallingIdentity(identity);
11024 }
11025 }
11026
11027 /**
11028 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11029 * device does not have an active PUBLISH.
11030 */
11031 // Used for SHELL command only right now.
11032 @Override
11033 public String getLastUcePidfXmlShell(int subId) {
11034 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11035 final long identity = Binder.clearCallingIdentity();
11036 try {
11037 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11038 } catch (ImsException e) {
11039 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11040 } finally {
11041 Binder.restoreCallingIdentity(identity);
11042 }
11043 }
11044
James.cf Line8713a42021-04-29 16:04:26 +080011045 /**
11046 * Remove UCE requests cannot be sent to the network status.
11047 */
11048 // Used for SHELL command only right now.
11049 @Override
11050 public boolean removeUceRequestDisallowedStatus(int subId) {
11051 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11052 final long identity = Binder.clearCallingIdentity();
11053 try {
11054 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11055 } catch (ImsException e) {
11056 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11057 } finally {
11058 Binder.restoreCallingIdentity(identity);
11059 }
11060 }
11061
James.cf Lin18bb9002021-05-25 01:37:38 +080011062 /**
11063 * Remove UCE requests cannot be sent to the network status.
11064 */
11065 // Used for SHELL command only.
11066 @Override
11067 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11069 final long identity = Binder.clearCallingIdentity();
11070 try {
11071 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11072 } catch (ImsException e) {
11073 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11074 } finally {
11075 Binder.restoreCallingIdentity(identity);
11076 }
11077 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011078
James.cf Lin4b784aa2021-01-31 03:25:15 +080011079 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011080 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11081 String callingPackage) {
11082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11083 mApp, subId, "setSignalStrengthUpdateRequest");
11084
11085 final int callingUid = Binder.getCallingUid();
11086 // Verify that tha callingPackage belongs to the calling UID
11087 mApp.getSystemService(AppOpsManager.class)
11088 .checkPackage(callingUid, callingPackage);
11089
Rambo Wang3607f502021-02-01 21:51:40 -080011090 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011091
11092 final long identity = Binder.clearCallingIdentity();
11093 try {
11094 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11095 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11096
11097 if (result instanceof IllegalStateException) {
11098 throw (IllegalStateException) result;
11099 }
11100 } finally {
11101 Binder.restoreCallingIdentity(identity);
11102 }
11103 }
11104
11105 @Override
11106 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11107 String callingPackage) {
11108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11109 mApp, subId, "clearSignalStrengthUpdateRequest");
11110
11111 final int callingUid = Binder.getCallingUid();
11112 // Verify that tha callingPackage belongs to the calling UID
11113 mApp.getSystemService(AppOpsManager.class)
11114 .checkPackage(callingUid, callingPackage);
11115
11116 final long identity = Binder.clearCallingIdentity();
11117 try {
11118 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11119 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11120
11121 if (result instanceof IllegalStateException) {
11122 throw (IllegalStateException) result;
11123 }
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
Rambo Wang3607f502021-02-01 21:51:40 -080011129 private static void validateSignalStrengthUpdateRequest(Context context,
11130 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011131 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11132 // phone/system process do not have further restriction on request
11133 return;
11134 }
11135
11136 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011137 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011138 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011139 context.enforceCallingOrSelfPermission(
11140 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11141 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011142 }
11143
11144 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11145 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11146 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11147 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11148 || info.isEnabled()) {
11149 throw new IllegalArgumentException(
11150 "Only system can set hide fields in SignalThresholdInfo");
11151 }
11152
11153 // Thresholds length for each RAN need in range. This has been validated in
11154 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11155 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11156 final int[] thresholds = info.getThresholds();
11157 Objects.requireNonNull(thresholds);
11158 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11159 || thresholds.length
11160 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11161 throw new IllegalArgumentException(
11162 "thresholds length is out of range: " + thresholds.length);
11163 }
11164 }
11165 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011166
11167 /**
11168 * Gets the current phone capability.
11169 *
11170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11171 * @return the PhoneCapability which describes the data connection capability of modem.
11172 * It's used to evaluate possible phone config change, for example from single
11173 * SIM device to multi-SIM device.
11174 */
11175 @Override
11176 public PhoneCapability getPhoneCapability() {
11177 enforceReadPrivilegedPermission("getPhoneCapability");
11178 final long identity = Binder.clearCallingIdentity();
11179 try {
11180 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11181 } finally {
11182 Binder.restoreCallingIdentity(identity);
11183 }
11184 }
Michele Berionne5e411512020-11-13 02:36:59 +000011185
11186 /**
11187 * Prepare TelephonyManager for an unattended reboot. The reboot is
11188 * required to be done shortly after the API is invoked.
11189 */
11190 @Override
11191 @TelephonyManager.PrepareUnattendedRebootResult
11192 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011193 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011194 enforceRebootPermission();
11195
11196 final long identity = Binder.clearCallingIdentity();
11197 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011198 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011199 } finally {
11200 Binder.restoreCallingIdentity(identity);
11201 }
11202 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011203
11204 /**
11205 * Request to get the current slicing configuration including URSP rules and
11206 * NSSAIs (configured, allowed and rejected).
11207 *
11208 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11209 */
11210 @Override
11211 public void getSlicingConfig(ResultReceiver callback) {
11212 enforceReadPrivilegedPermission("getSlicingConfig");
11213
11214 final long identity = Binder.clearCallingIdentity();
11215 try {
11216 Phone phone = getDefaultPhone();
11217 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11218 } finally {
11219 Binder.restoreCallingIdentity(identity);
11220 }
11221 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011222
11223 /**
11224 * Register an IMS connection state callback
11225 */
11226 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011227 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11228 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011229 if (feature == ImsFeature.FEATURE_MMTEL) {
11230 // ImsMmTelManager
11231 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11232 TelephonyPermissions
11233 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11234 mApp, subId, "registerImsStateCallback");
11235 } else if (feature == ImsFeature.FEATURE_RCS) {
11236 // ImsRcsManager or SipDelegateManager
11237 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11238 Binder.getCallingUid(), "registerImsStateCallback",
11239 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11240 Manifest.permission.READ_PRECISE_PHONE_STATE,
11241 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11242 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11243 }
11244
11245 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11247 "IMS not available on device.");
11248 }
11249
11250 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11251 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11252 }
11253
11254 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11255 if (controller == null) {
11256 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11257 "IMS not available on device.");
11258 }
11259
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011260 if (callingPackage == null) {
11261 callingPackage = getCurrentPackageName();
11262 }
11263
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011264 final long token = Binder.clearCallingIdentity();
11265 try {
11266 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011267 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011268 } catch (ImsException e) {
11269 throw new ServiceSpecificException(e.getCode());
11270 } finally {
11271 Binder.restoreCallingIdentity(token);
11272 }
11273 }
11274
11275 /**
11276 * Unregister an IMS connection state callback
11277 */
11278 @Override
11279 public void unregisterImsStateCallback(IImsStateCallback cb) {
11280 final long token = Binder.clearCallingIdentity();
11281 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11282 if (controller == null) {
11283 return;
11284 }
11285 try {
11286 controller.unregisterImsStateCallback(cb);
11287 } finally {
11288 Binder.restoreCallingIdentity(token);
11289 }
11290 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011291
11292 /**
11293 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11294 *
11295 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11296 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11297 * SecurityException.
11298 * If there is current registered network this value will be same as the registered cell
11299 * identity. If the device goes out of service the previous cell identity is cached and
11300 * will be returned. If the cache age of the Cell identity is more than 24 hours
11301 * it will be cleared and null will be returned.
11302 *
11303 */
11304 @Override
11305 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11306 String callingFeatureId) {
11307 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11308 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11309 LocationAccessPolicy.checkLocationPermission(mApp,
11310 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11311 .setCallingPackage(callingPackage)
11312 .setCallingFeatureId(callingFeatureId)
11313 .setCallingPid(Binder.getCallingPid())
11314 .setCallingUid(Binder.getCallingUid())
11315 .setMethod("getLastKnownCellIdentity")
11316 .setLogAsInfo(true)
11317 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11318 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11319 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11320 .build());
11321
11322 boolean hasFinePermission =
11323 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11324 if (!hasFinePermission
11325 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11326 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11327 + "and BIND_CONNECTION_SERVICE permission.");
11328 }
11329
11330 final long identity = Binder.clearCallingIdentity();
11331 try {
11332 Phone phone = getPhone(subId);
11333 if (phone == null) return null;
11334 ServiceStateTracker sst = phone.getServiceStateTracker();
11335 if (sst == null) return null;
11336 return sst.getLastKnownCellIdentity();
11337 } finally {
11338 Binder.restoreCallingIdentity(identity);
11339 }
11340 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011341
11342 @Override
11343 public boolean isUsingNewDataStack() {
11344 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11345 return getDefaultPhone().isUsingNewDataStack();
11346 }
jimsun3b9ccac2021-10-26 15:01:23 +080011347
11348 /**
11349 * Sets the modem service class Name that Telephony will bind to.
11350 *
11351 * @param serviceName The class name of the modem service.
11352 * @return true if the operation is succeed, otherwise false.
11353 */
11354 public boolean setModemService(String serviceName) {
11355 Log.d(LOG_TAG, "setModemService - " + serviceName);
11356 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11358 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11359 "setModemService");
11360 return mPhoneConfigurationManager.setModemService(serviceName);
11361 }
11362
11363 /**
11364 * Return the class name of the currently bounded modem service.
11365 *
11366 * @return the class name of the modem service.
11367 */
11368 public String getModemService() {
11369 String result;
11370 Log.d(LOG_TAG, "getModemService");
11371 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11372 TelephonyPermissions
11373 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11374 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11375 "getModemService");
11376 result = mPhoneConfigurationManager.getModemService();
11377 Log.d(LOG_TAG, "result = " + result);
11378 return result;
11379 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011380
11381 @Override
11382 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11383 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11384 mApp.enforceCallingOrSelfPermission(
11385 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11387
11388 final long identity = Binder.clearCallingIdentity();
11389 try {
11390 Phone phone = getPhone(subId);
11391 if (phone == null) return;
11392 phone.setVoiceServiceStateOverride(hasService);
11393 } finally {
11394 Binder.restoreCallingIdentity(identity);
11395 }
11396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011397}