blob: f76e0fac39959e099b05bdc74a443c5bac7067b1 [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;
sandeepjsb6c87872021-09-27 15:34:44 +000036import android.compat.annotation.ChangeId;
37import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070038import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070039import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.content.Context;
41import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070043import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070044import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.net.Uri;
46import android.os.AsyncResult;
47import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080048import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Bundle;
50import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Looper;
53import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080055import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070056import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070057import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080058import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080059import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070060import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070061import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080062import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070064import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070066import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070067import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080068import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070069import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090070import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080071import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080072import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070073import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080074import android.telephony.AccessNetworkConstants;
75import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070076import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080077import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080078import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070079import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080080import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070081import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080082import android.telephony.CellIdentityCdma;
83import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070085import android.telephony.CellInfoGsm;
86import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070087import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080088import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070089import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070090import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070091import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080092import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070093import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080094import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070095import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080096import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080097import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070098import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080099import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800101import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800102import android.telephony.SignalStrengthUpdateRequest;
103import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800104import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800105import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800106import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700107import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700108import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800109import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800110import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800111import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000112import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000113import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700115import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700116import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800118import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800119import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700120import android.telephony.gba.GbaAuthRequest;
121import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700122import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000124import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000125import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700126import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000127import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700128import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700130import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800131import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700132import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000133import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700134import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800136import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800137import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800138import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700141import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800143import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144
Andrew Lee312e8172014-10-23 17:01:36 -0700145import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800146import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800147import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800148import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700151import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700152import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800153import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800154import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800157import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800169import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700171import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700174import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800175import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700176import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700177import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700178import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700179import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800180import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800181import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700182import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700183import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800185import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800186import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700188import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700190import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800191import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700192import com.android.internal.telephony.imsphone.ImsPhone;
193import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000194import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800195import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700196import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800198import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700201import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000204import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800205import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000206import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800207import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700208import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700209import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800210import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800211import com.android.phone.callcomposer.CallComposerPictureManager;
212import com.android.phone.callcomposer.CallComposerPictureTransfer;
213import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700214import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800216import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700218import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800219import com.android.services.telephony.TelecomAccountRegistry;
220import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800221import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800222
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.IOException;
226import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000230import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800231import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800232import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800234import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100235import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700237import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800239import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800240import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800241import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800242import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243
244/**
245 * Implementation of the ITelephony interface.
246 */
Santos Cordon117fee72014-05-16 17:56:12 -0700247public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 private static final String LOG_TAG = "PhoneInterfaceManager";
249 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
250 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800251 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252
253 // Message codes used with mMainThreadHandler
254 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700255 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
256 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700257 private static final int CMD_OPEN_CHANNEL = 9;
258 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
259 private static final int CMD_CLOSE_CHANNEL = 11;
260 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800261 private static final int CMD_NV_READ_ITEM = 13;
262 private static final int EVENT_NV_READ_ITEM_DONE = 14;
263 private static final int CMD_NV_WRITE_ITEM = 15;
264 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
265 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
266 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700267 private static final int CMD_RESET_MODEM_CONFIG = 19;
268 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800269 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
270 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800271 private static final int CMD_SEND_ENVELOPE = 25;
272 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000273 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
274 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700275 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
276 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
277 private static final int CMD_EXCHANGE_SIM_IO = 31;
278 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800279 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
280 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700281 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
282 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700283 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
284 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700285 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
286 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
287 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
288 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700289 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
290 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
291 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
292 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700293 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800294 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
295 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000296 private static final int CMD_SWITCH_SLOTS = 50;
297 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700298 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
299 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
300 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
301 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
302 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
303 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
304 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
305 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700306 private static final int CMD_GET_ALL_CELL_INFO = 60;
307 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
308 private static final int CMD_GET_CELL_LOCATION = 62;
309 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700310 private static final int CMD_MODEM_REBOOT = 64;
311 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700312 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
313 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800314 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
315 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700316 private static final int CMD_GET_MODEM_STATUS = 70;
317 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700318 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
319 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700320 private static final int CMD_ERASE_MODEM_CONFIG = 74;
321 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800322 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
323 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
324 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
325 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800326 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
327 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800328 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800329 private static final int CMD_GET_CALL_FORWARDING = 83;
330 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
331 private static final int CMD_SET_CALL_FORWARDING = 85;
332 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
333 private static final int CMD_GET_CALL_WAITING = 87;
334 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
335 private static final int CMD_SET_CALL_WAITING = 89;
336 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700337 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
338 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
339 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
340 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700341 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
342 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800343 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
344 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800345 private static final int CMD_SET_DATA_THROTTLING = 99;
346 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800347 private static final int CMD_SET_SIM_POWER = 101;
348 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800349 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
350 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
351 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
352 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800353 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
354 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000355 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800356 private static final int CMD_GET_SLICING_CONFIG = 110;
357 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800358 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700359 private static final int CMD_ENABLE_VONR = 113;
360 private static final int EVENT_ENABLE_VONR_DONE = 114;
361 private static final int CMD_IS_VONR_ENABLED = 115;
362 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800364 // Parameters of select command.
365 private static final int SELECT_COMMAND = 0xA4;
366 private static final int SELECT_P1 = 0x04;
367 private static final int SELECT_P2 = 0;
368 private static final int SELECT_P3 = 0x10;
369
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 /** The singleton instance. */
371 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800372 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800376 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700377 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700379 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800381 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800382 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700383 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800384 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 /** User Activity */
387 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800388 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
389
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700390 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
391
Derek Tan97ebb422014-09-05 16:55:38 -0700392 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
393 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800394 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800395 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700396
Michelecea4cf22018-12-21 15:00:11 -0800397 // String to store multi SIM allowed
398 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
399
Derek Tan740e1672017-06-27 14:56:27 -0700400 // The AID of ISD-R.
401 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
402
yinxub1bed742017-04-17 11:45:04 -0700403 private NetworkScanRequestTracker mNetworkScanRequestTracker;
404
David Kelly5e06a7f2018-03-12 14:10:59 +0000405 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
406 private static final int MANUFACTURER_CODE_LENGTH = 8;
407
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800409 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800410
Derek Tan89e89d42014-07-08 17:00:10 -0700411 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700412 * Experiment flag to enable erase modem config on reset network, default value is false
413 */
414 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
415 "reset_network_erase_modem_config_enabled";
416
Rambo Wang0f050d82021-02-12 11:43:36 -0800417 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800418
sandeepjsb6c87872021-09-27 15:34:44 +0000419 /**
420 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
421 * one ICCID active at the same time.
422 * Apps should use below API signatures if targeting SDK is T and beyond.
423 *
424 * @hide
425 */
426 @ChangeId
427 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
428 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800429
Naina Nallurid63128d2019-09-17 14:10:30 -0700430 /**
Chen Xu540470b2021-12-14 17:15:47 -0800431 * Apps targeting on Android T and beyond will get exception whenever icc close channel
432 * operation fails.
433 */
434 @ChangeId
435 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
436 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
437
438 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 * A request object to use for transmitting data to an ICC.
440 */
441 private static final class IccAPDUArgument {
442 public int channel, cla, command, p1, p2, p3;
443 public String data;
444
445 public IccAPDUArgument(int channel, int cla, int command,
446 int p1, int p2, int p3, String data) {
447 this.channel = channel;
448 this.cla = cla;
449 this.command = command;
450 this.p1 = p1;
451 this.p2 = p2;
452 this.p3 = p3;
453 this.data = data;
454 }
455 }
456
457 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700458 * A request object to use for transmitting data to an ICC.
459 */
460 private static final class ManualNetworkSelectionArgument {
461 public OperatorInfo operatorInfo;
462 public boolean persistSelection;
463
464 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
465 this.operatorInfo = operatorInfo;
466 this.persistSelection = persistSelection;
467 }
468 }
469
470 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
472 * request after sending. The main thread will notify the request when it is complete.
473 */
474 private static final class MainThreadRequest {
475 /** The argument to use for the request */
476 public Object argument;
477 /** The result of the request that is run on the main thread */
478 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800479 // The subscriber id that this request applies to. Defaults to
480 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
481 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482
Nathan Harold92bed182018-10-12 18:16:49 -0700483 // In cases where subId is unavailable, the caller needs to specify the phone.
484 public Phone phone;
485
vagdeviaf9a5b92018-08-15 16:01:53 -0700486 public WorkSource workSource;
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 public MainThreadRequest(Object argument) {
489 this.argument = argument;
490 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800491
Nathan Harold92bed182018-10-12 18:16:49 -0700492 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
493 this.argument = argument;
494 if (phone != null) {
495 this.phone = phone;
496 }
497 this.workSource = workSource;
498 }
499
vagdeviaf9a5b92018-08-15 16:01:53 -0700500 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800501 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800502 if (subId != null) {
503 this.subId = subId;
504 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700505 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 }
508
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800509 private static final class IncomingThirdPartyCallArgs {
510 public final ComponentName component;
511 public final String callId;
512 public final String callerDisplayName;
513
514 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
515 String callerDisplayName) {
516 this.component = component;
517 this.callId = callId;
518 this.callerDisplayName = callerDisplayName;
519 }
520 }
521
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 /**
523 * A handler that processes messages on the main thread in the phone process. Since many
524 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
525 * inbound binder threads to the main thread in the phone process. The Binder thread
526 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
527 * on, which will be notified when the operation completes and will contain the result of the
528 * request.
529 *
530 * <p>If a MainThreadRequest object is provided in the msg.obj field,
531 * note that request.result must be set to something non-null for the calling thread to
532 * unblock.
533 */
534 private final class MainThreadHandler extends Handler {
535 @Override
536 public void handleMessage(Message msg) {
537 MainThreadRequest request;
538 Message onCompleted;
539 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000540 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800542 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543
544 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 case CMD_HANDLE_USSD_REQUEST: {
546 request = (MainThreadRequest) msg.obj;
547 final Phone phone = getPhoneFromRequest(request);
548 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800549 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700551
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 if (!isUssdApiAllowed(request.subId)) {
553 // Carrier does not support use of this API, return failure.
554 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
555 UssdResponse response = new UssdResponse(ussdRequest, null);
556 Bundle returnData = new Bundle();
557 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
558 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700559
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 request.result = true;
561 notifyRequester(request);
562 return;
563 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700564
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 try {
566 request.result = phone != null
567 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
568 } catch (CallStateException cse) {
569 request.result = false;
570 }
571 // Wake up the requesting thread
572 notifyRequester(request);
573 break;
pkanwar32d516d2016-10-14 19:37:38 -0700574 }
575
Yorke Lee716f67e2015-06-17 15:39:16 -0700576 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700578 final Phone phone = getPhoneFromRequest(request);
579 request.result = phone != null ?
580 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
581 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700586
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000590 uiccPort = getUiccPortFromRequest(request);
591 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800593 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800597 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000598 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800599 iccArgument.channel, iccArgument.cla, iccArgument.command,
600 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
601 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 break;
604
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 ar = (AsyncResult) msg.obj;
607 request = (MainThreadRequest) ar.userObj;
608 if (ar.exception == null && ar.result != null) {
609 request.result = ar.result;
610 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800611 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.result == null) {
613 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800614 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800616 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 } else {
618 loge("iccTransmitApduLogicalChannel: Unknown exception");
619 }
620 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
625 request = (MainThreadRequest) msg.obj;
626 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000627 uiccPort = getUiccPortFromRequest(request);
628 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800630 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 } else {
633 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800634 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000635 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800636 iccArgument.cla, iccArgument.command, iccArgument.p1,
637 iccArgument.p2,
638 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 break;
641
642 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
645 if (ar.exception == null && ar.result != null) {
646 request.result = ar.result;
647 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800648 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 if (ar.result == null) {
650 loge("iccTransmitApduBasicChannel: Empty response");
651 } else if (ar.exception instanceof CommandException) {
652 loge("iccTransmitApduBasicChannel: CommandException: " +
653 ar.exception);
654 } else {
655 loge("iccTransmitApduBasicChannel: Unknown exception");
656 }
657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 break;
660
661 case CMD_EXCHANGE_SIM_IO:
662 request = (MainThreadRequest) msg.obj;
663 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000664 uiccPort = getUiccPortFromRequest(request);
665 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 } else {
670 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
671 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000672 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
674 iccArgument.data, onCompleted);
675 }
676 break;
677
678 case EVENT_EXCHANGE_SIM_IO_DONE:
679 ar = (AsyncResult) msg.obj;
680 request = (MainThreadRequest) ar.userObj;
681 if (ar.exception == null && ar.result != null) {
682 request.result = ar.result;
683 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800684 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700686 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 break;
688
Derek Tan4d5e5c12014-02-04 11:54:58 -0800689 case CMD_SEND_ENVELOPE:
690 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 uiccPort = getUiccPortFromRequest(request);
692 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800694 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 } else {
697 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800698 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800700 break;
701
702 case EVENT_SEND_ENVELOPE_DONE:
703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700705 if (ar.exception == null && ar.result != null) {
706 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800707 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800708 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700709 if (ar.result == null) {
710 loge("sendEnvelopeWithStatus: Empty response");
711 } else if (ar.exception instanceof CommandException) {
712 loge("sendEnvelopeWithStatus: CommandException: " +
713 ar.exception);
714 } else {
715 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
716 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800719 break;
720
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 case CMD_OPEN_CHANNEL:
722 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000723 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800724 IccLogicalChannelRequest openChannelRequest =
725 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000726 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800728 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800729 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700730 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700731 } else {
732 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800733 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
734 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700735 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700736 break;
737
738 case EVENT_OPEN_CHANNEL_DONE:
739 ar = (AsyncResult) msg.obj;
740 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 int[] result = (int[]) ar.result;
744 int channelId = result[0];
745 byte[] selectResponse = null;
746 if (result.length > 1) {
747 selectResponse = new byte[result.length - 1];
748 for (int i = 1; i < result.length; ++i) {
749 selectResponse[i - 1] = (byte) result[i];
750 }
751 }
752 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800753 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800754
755 uiccPort = getUiccPortFromRequest(request);
756 IccLogicalChannelRequest channelRequest =
757 (IccLogicalChannelRequest) request.argument;
758 channelRequest.channel = channelId;
759 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 if (ar.result == null) {
762 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700764 if (ar.exception != null) {
765 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
766 }
767
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700768 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700769 if (ar.exception instanceof CommandException) {
770 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800771 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700772 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700773 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700774 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700775 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700776 }
777 }
778 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800779 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700781 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700782 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 break;
784
785 case CMD_CLOSE_CHANNEL:
786 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000787 uiccPort = getUiccPortFromRequest(request);
788 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700789 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800790 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800791 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800792 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700793 } else {
794 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000795 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700796 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700797 break;
798
799 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800800 ar = (AsyncResult) msg.obj;
801 request = (MainThreadRequest) ar.userObj;
802 if (ar.exception == null) {
803 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800804 uiccPort = getUiccPortFromRequest(request);
805 final int channelId = (Integer) request.argument;
806 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800807 } else {
808 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800809 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800810 if (ar.exception instanceof CommandException) {
811 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
812 CommandException.Error error =
813 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800814 if (error == CommandException.Error.INVALID_ARGUMENTS) {
815 // should only throw exceptions from the binder threads.
816 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800817 "iccCloseLogicalChannel: invalid argument ");
818 }
819 } else {
820 loge("iccCloseLogicalChannel: Unknown exception");
821 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800822 request.result = (exception != null) ? exception :
823 new IllegalStateException(
824 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800825 }
826 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800827 break;
828
829 case CMD_NV_READ_ITEM:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800832 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
833 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
836 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800842 request.result = "";
843 if (ar.result == null) {
844 loge("nvReadItem: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("nvReadItem: CommandException: " +
847 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800849 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 }
851 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700852 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 break;
854
Jake Hambye994d462014-02-03 13:10:13 -0800855 case CMD_NV_WRITE_ITEM:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
858 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800859 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700860 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800861 break;
862
863 case EVENT_NV_WRITE_ITEM_DONE:
864 handleNullReturnEvent(msg, "nvWriteItem");
865 break;
866
867 case CMD_NV_WRITE_CDMA_PRL:
868 request = (MainThreadRequest) msg.obj;
869 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800870 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800871 break;
872
873 case EVENT_NV_WRITE_CDMA_PRL_DONE:
874 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
875 break;
876
chen xu6dac5ab2018-10-26 17:39:23 -0700877 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800878 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700879 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800880 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800881 break;
882
chen xu6dac5ab2018-10-26 17:39:23 -0700883 case EVENT_RESET_MODEM_CONFIG_DONE:
884 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800885 break;
886
Sooraj Sasindran37444802020-08-11 10:40:43 -0700887 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
890 request);
891 Phone phone = getPhoneFromRequest(request);
892 if (phone != null) {
893 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
894 } else {
895 loge("isNRDualConnectivityEnabled: No phone object");
896 request.result = false;
897 notifyRequester(request);
898 }
899 break;
900 }
901
902 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
903 ar = (AsyncResult) msg.obj;
904 request = (MainThreadRequest) ar.userObj;
905 if (ar.exception == null && ar.result != null) {
906 request.result = ar.result;
907 } else {
908 // request.result must be set to something non-null
909 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700910 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700911 request.result = ar.result;
912 } else {
913 request.result = false;
914 }
915 if (ar.result == null) {
916 loge("isNRDualConnectivityEnabled: Empty response");
917 } else if (ar.exception instanceof CommandException) {
918 loge("isNRDualConnectivityEnabled: CommandException: "
919 + ar.exception);
920 } else {
921 loge("isNRDualConnectivityEnabled: Unknown exception");
922 }
923 }
924 notifyRequester(request);
925 break;
926
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700927 case CMD_IS_VONR_ENABLED: {
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
930 request);
931 Phone phone = getPhoneFromRequest(request);
932 if (phone != null) {
933 phone.isVoNrEnabled(onCompleted, request.workSource);
934 } else {
935 loge("isVoNrEnabled: No phone object");
936 request.result = false;
937 notifyRequester(request);
938 }
939 break;
940 }
941
942 case EVENT_IS_VONR_ENABLED_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 // request.result must be set to something non-null
949 // for the calling thread to unblock
950 if (ar.result != null) {
951 request.result = ar.result;
952 } else {
953 request.result = false;
954 }
955 if (ar.result == null) {
956 loge("isVoNrEnabled: Empty response");
957 } else if (ar.exception instanceof CommandException) {
958 loge("isVoNrEnabled: CommandException: "
959 + ar.exception);
960 } else {
961 loge("isVoNrEnabled: Unknown exception");
962 }
963 }
964 notifyRequester(request);
965 break;
966
Sooraj Sasindran37444802020-08-11 10:40:43 -0700967 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
970 Phone phone = getPhoneFromRequest(request);
971 if (phone != null) {
972 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
973 request.workSource);
974 } else {
975 loge("enableNrDualConnectivity: No phone object");
976 request.result =
977 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
978 notifyRequester(request);
979 }
980 break;
981 }
982
983 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception == null) {
987 request.result =
988 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
989 } else {
990 request.result =
991 TelephonyManager
992 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
993 if (ar.exception instanceof CommandException) {
994 CommandException.Error error =
995 ((CommandException) (ar.exception)).getCommandError();
996 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
997 request.result =
998 TelephonyManager
999 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001000 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1001 request.result =
1002 TelephonyManager
1003 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001004 }
1005 loge("enableNrDualConnectivity" + ": CommandException: "
1006 + ar.exception);
1007 } else {
1008 loge("enableNrDualConnectivity" + ": Unknown exception");
1009 }
1010 }
1011 notifyRequester(request);
1012 break;
1013 }
1014
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001015 case CMD_ENABLE_VONR: {
1016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1018 Phone phone = getPhoneFromRequest(request);
1019 if (phone != null) {
1020 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1021 request.workSource);
1022 } else {
1023 loge("setVoNrEnabled: No phone object");
1024 request.result =
1025 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1026 notifyRequester(request);
1027 }
1028 break;
1029 }
1030
1031 case EVENT_ENABLE_VONR_DONE: {
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 if (ar.exception == null) {
1035 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1036 } else {
1037 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1038 if (ar.exception instanceof CommandException) {
1039 CommandException.Error error =
1040 ((CommandException) (ar.exception)).getCommandError();
1041 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1042 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1043 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1044 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1045 } else {
1046 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1047 }
1048 loge("setVoNrEnabled" + ": CommandException: "
1049 + ar.exception);
1050 } else {
1051 loge("setVoNrEnabled" + ": Unknown exception");
1052 }
1053 }
1054 notifyRequester(request);
1055 break;
1056 }
1057
SongFerngWang3ef3e072020-12-21 16:41:52 +08001058 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001059 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001060 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1061 request);
1062 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001063 break;
1064
SongFerngWang3ef3e072020-12-21 16:41:52 +08001065 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null && ar.result != null) {
1069 request.result = ar.result; // Integer
1070 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301071 // request.result must be set to something non-null
1072 // for the calling thread to unblock
1073 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001076 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001077 loge("getAllowedNetworkTypesBitmask: CommandException: "
1078 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001079 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001080 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001081 }
1082 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001083 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001084 break;
1085
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1089 request);
1090 Pair<Integer, Long> reasonWithNetworkTypes =
1091 (Pair<Integer, Long>) request.argument;
1092 getPhoneFromRequest(request).setAllowedNetworkTypes(
1093 reasonWithNetworkTypes.first,
1094 reasonWithNetworkTypes.second,
1095 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001096 break;
1097
SongFerngWang3ef3e072020-12-21 16:41:52 +08001098 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1099 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001100 break;
1101
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001102 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1103 request = (MainThreadRequest)msg.obj;
1104 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001105 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001106 break;
1107
1108 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1109 ar = (AsyncResult)msg.obj;
1110 request = (MainThreadRequest)ar.userObj;
1111 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001112 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001113 break;
1114
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001115 case CMD_SET_VOICEMAIL_NUMBER:
1116 request = (MainThreadRequest) msg.obj;
1117 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1118 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001119 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1120 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001121 break;
1122
1123 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1124 handleNullReturnEvent(msg, "setVoicemailNumber");
1125 break;
1126
Stuart Scott54788802015-03-30 13:18:01 -07001127 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1130 request);
1131 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1132 break;
1133
1134 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1135 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1136 break;
1137
Shishir Agrawal302c8692015-06-19 13:49:39 -07001138 case CMD_PERFORM_NETWORK_SCAN:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1141 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1142 break;
1143
Hall Liu27d24262020-09-18 19:04:59 -07001144 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001147 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1148 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1149 request.argument;
1150 int callForwardingReason = args.first;
1151 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001152 break;
Hall Liu27d24262020-09-18 19:04:59 -07001153 }
1154 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001157 TelephonyManager.CallForwardingInfoCallback callback =
1158 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1159 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001160 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001161 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001162 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1163 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1164 // Service Class is a bit mask per 3gpp 27.007. Search for
1165 // any service for voice call.
1166 if ((callForwardInfo.serviceClass
1167 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001168 callForwardingInfo = new CallForwardingInfo(
1169 callForwardInfo.status
1170 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001171 callForwardInfo.reason,
1172 callForwardInfo.number,
1173 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001174 break;
1175 }
1176 }
1177 // Didn't find a call forward info for voice call.
1178 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001179 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1180 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 }
Hall Liu27d24262020-09-18 19:04:59 -07001182 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001183 } else {
1184 if (ar.result == null) {
1185 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1186 }
1187 if (ar.exception != null) {
1188 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1189 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001190 int errorCode = TelephonyManager
1191 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001192 if (ar.exception instanceof CommandException) {
1193 CommandException.Error error =
1194 ((CommandException) (ar.exception)).getCommandError();
1195 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001196 errorCode = TelephonyManager
1197 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001199 errorCode = TelephonyManager
1200 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 }
1202 }
Hall Liu27d24262020-09-18 19:04:59 -07001203 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205 break;
Hall Liu27d24262020-09-18 19:04:59 -07001206 }
Shuo Qian4a594052020-01-23 11:59:30 -08001207
Hall Liu27d24262020-09-18 19:04:59 -07001208 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001211 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001212 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001213 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1214 request.argument).first;
1215 request.phone.setCallForwardingOption(
1216 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001217 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001218 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001219 callForwardingInfoToSet.getReason(),
1220 callForwardingInfoToSet.getNumber(),
1221 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1222 break;
Hall Liu27d24262020-09-18 19:04:59 -07001223 }
Shuo Qian4a594052020-01-23 11:59:30 -08001224
Hall Liu27d24262020-09-18 19:04:59 -07001225 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001226 ar = (AsyncResult) msg.obj;
1227 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001228 Consumer<Integer> callback =
1229 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1230 request.argument).second;
1231 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001233 int errorCode = TelephonyManager.CallForwardingInfoCallback
1234 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 errorCode = TelephonyManager.CallForwardingInfoCallback
1240 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001241 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001242 errorCode = TelephonyManager.CallForwardingInfoCallback
1243 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001244 }
1245 }
1246 callback.accept(errorCode);
1247 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250 break;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252
Hall Liu27d24262020-09-18 19:04:59 -07001253 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001254 request = (MainThreadRequest) msg.obj;
1255 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1256 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1257 break;
Hall Liu27d24262020-09-18 19:04:59 -07001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259
Hall Liu27d24262020-09-18 19:04:59 -07001260 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001263 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001264 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001266 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 // Service Class is a bit mask per 3gpp 27.007.
1268 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001269 if (callForwardResults.length > 1
1270 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001271 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001272 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001273 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1274 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001276 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 }
1278 } else {
1279 if (ar.result == null) {
1280 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1281 }
1282 if (ar.exception != null) {
1283 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1284 }
1285 if (ar.exception instanceof CommandException) {
1286 CommandException.Error error =
1287 ((CommandException) (ar.exception)).getCommandError();
1288 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001289 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001290 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001291 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1292 callWaitingStatus =
1293 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001294 }
1295 }
1296 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001297 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001298 break;
Hall Liu27d24262020-09-18 19:04:59 -07001299 }
Shuo Qian4a594052020-01-23 11:59:30 -08001300
Hall Liu27d24262020-09-18 19:04:59 -07001301 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 request = (MainThreadRequest) msg.obj;
1303 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001304 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1305 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001306 break;
Hall Liu27d24262020-09-18 19:04:59 -07001307 }
Shuo Qian4a594052020-01-23 11:59:30 -08001308
Hall Liu27d24262020-09-18 19:04:59 -07001309 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001312 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1313 Consumer<Integer> callback =
1314 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1315 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001317 if (ar.exception instanceof CommandException) {
1318 CommandException.Error error =
1319 ((CommandException) (ar.exception)).getCommandError();
1320 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1321 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001322 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1323 callback.accept(
1324 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001325 } else {
1326 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1327 }
1328 } else {
1329 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1330 }
1331 } else {
1332 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1333 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001334 }
Shuo Qian4a594052020-01-23 11:59:30 -08001335 break;
Hall Liu27d24262020-09-18 19:04:59 -07001336 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001337 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1338 ar = (AsyncResult) msg.obj;
1339 request = (MainThreadRequest) ar.userObj;
1340 CellNetworkScanResult cellScanResult;
1341 if (ar.exception == null && ar.result != null) {
1342 cellScanResult = new CellNetworkScanResult(
1343 CellNetworkScanResult.STATUS_SUCCESS,
1344 (List<OperatorInfo>) ar.result);
1345 } else {
1346 if (ar.result == null) {
1347 loge("getCellNetworkScanResults: Empty response");
1348 }
1349 if (ar.exception != null) {
1350 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1351 }
1352 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1353 if (ar.exception instanceof CommandException) {
1354 CommandException.Error error =
1355 ((CommandException) (ar.exception)).getCommandError();
1356 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1357 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1358 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1359 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1360 }
1361 }
1362 cellScanResult = new CellNetworkScanResult(errorCode, null);
1363 }
1364 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001365 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001366 break;
1367
1368 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1369 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001370 ManualNetworkSelectionArgument selArg =
1371 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001372 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1373 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001374 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1375 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001376 break;
1377
1378 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
1381 if (ar.exception == null) {
1382 request.result = true;
1383 } else {
1384 request.result = false;
1385 loge("setNetworkSelectionModeManual " + ar.exception);
1386 }
1387 notifyRequester(request);
1388 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001389 break;
1390
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001391 case CMD_GET_MODEM_ACTIVITY_INFO:
1392 request = (MainThreadRequest) msg.obj;
1393 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001394 if (defaultPhone != null) {
1395 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001396 } else {
1397 ResultReceiver result = (ResultReceiver) request.argument;
1398 Bundle bundle = new Bundle();
1399 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001400 new ModemActivityInfo(0, 0, 0,
1401 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001402 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001403 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001404 break;
1405
Hall Liud0f208c2020-10-14 16:54:44 -07001406 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001409 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001410 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001411 if (mLastModemActivityInfo == null) {
1412 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1413 mLastModemActivitySpecificInfo[0] =
1414 new ActivityStatsTechSpecificInfo(
1415 0,
1416 0,
1417 new int[ModemActivityInfo.getNumTxPowerLevels()],
1418 0);
1419 mLastModemActivityInfo =
1420 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1421 }
1422
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001423 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001424 // Update the last modem activity info and the result of the request.
1425 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1426 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001427 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001428 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001429 mLastModemActivityInfo =
1430 new ModemActivityInfo(
1431 mLastModemActivityInfo.getTimestampMillis(),
1432 mLastModemActivityInfo.getSleepTimeMillis(),
1433 mLastModemActivityInfo.getIdleTimeMillis(),
1434 mLastModemActivitySpecificInfo);
1435
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001436 } else {
1437 if (ar.result == null) {
1438 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001439 error = TelephonyManager.ModemActivityInfoException
1440 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001441 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001442 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001443 error = TelephonyManager.ModemActivityInfoException
1444 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001445 } else {
1446 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001447 error = TelephonyManager.ModemActivityInfoException
1448 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001449 }
1450 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001451 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001452 if (mLastModemActivityInfo != null) {
1453 bundle.putParcelable(
1454 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1455 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001456 } else {
1457 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1458 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001459 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001460 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001462 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 case CMD_SET_ALLOWED_CARRIERS:
1465 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001466 CarrierRestrictionRules argument =
1467 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001468 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001469 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001470 break;
1471
1472 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1473 ar = (AsyncResult) msg.obj;
1474 request = (MainThreadRequest) ar.userObj;
1475 if (ar.exception == null && ar.result != null) {
1476 request.result = ar.result;
1477 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001478 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1479 if (ar.exception instanceof CommandException) {
1480 loge("setAllowedCarriers: CommandException: " + ar.exception);
1481 CommandException.Error error =
1482 ((CommandException) (ar.exception)).getCommandError();
1483 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1484 request.result =
1485 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1486 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001487 } else {
1488 loge("setAllowedCarriers: Unknown exception");
1489 }
1490 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001491 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 break;
1493
1494 case CMD_GET_ALLOWED_CARRIERS:
1495 request = (MainThreadRequest) msg.obj;
1496 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001497 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 break;
1499
1500 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1501 ar = (AsyncResult) msg.obj;
1502 request = (MainThreadRequest) ar.userObj;
1503 if (ar.exception == null && ar.result != null) {
1504 request.result = ar.result;
1505 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001506 request.result = new IllegalStateException(
1507 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001508 if (ar.result == null) {
1509 loge("getAllowedCarriers: Empty response");
1510 } else if (ar.exception instanceof CommandException) {
1511 loge("getAllowedCarriers: CommandException: " +
1512 ar.exception);
1513 } else {
1514 loge("getAllowedCarriers: Unknown exception");
1515 }
1516 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001517 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518 break;
1519
Nathan Haroldb3014052017-01-25 15:57:32 -08001520 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1521 ar = (AsyncResult) msg.obj;
1522 request = (MainThreadRequest) ar.userObj;
1523 if (ar.exception == null && ar.result != null) {
1524 request.result = ar.result;
1525 } else {
1526 request.result = new IllegalArgumentException(
1527 "Failed to retrieve Forbidden Plmns");
1528 if (ar.result == null) {
1529 loge("getForbiddenPlmns: Empty response");
1530 } else {
1531 loge("getForbiddenPlmns: Unknown exception");
1532 }
1533 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001534 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001535 break;
1536
1537 case CMD_GET_FORBIDDEN_PLMNS:
1538 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001539 uiccPort = getUiccPortFromRequest(request);
1540 if (uiccPort == null) {
1541 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001542 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001543 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001545 break;
1546 }
1547 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001548 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001549 if (uiccApp == null) {
1550 loge("getForbiddenPlmns() no app with specified type -- "
1551 + appType);
1552 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001553 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001554 break;
1555 } else {
1556 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1557 + " specified type -- " + appType);
1558 }
1559 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1560 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1561 onCompleted);
1562 break;
1563
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001564 case CMD_SWITCH_SLOTS:
1565 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001566 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001567 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001568 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001569 break;
1570
1571 case EVENT_SWITCH_SLOTS_DONE:
1572 ar = (AsyncResult) msg.obj;
1573 request = (MainThreadRequest) ar.userObj;
1574 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001575 notifyRequester(request);
1576 break;
1577 case CMD_GET_NETWORK_SELECTION_MODE:
1578 request = (MainThreadRequest) msg.obj;
1579 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1580 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1581 break;
1582
1583 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
1586 if (ar.exception != null) {
1587 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1588 } else {
1589 int mode = ((int[]) ar.result)[0];
1590 if (mode == 0) {
1591 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1592 } else {
1593 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1594 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001595 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001596 notifyRequester(request);
1597 break;
1598 case CMD_GET_CDMA_ROAMING_MODE:
1599 request = (MainThreadRequest) msg.obj;
1600 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1601 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1602 break;
1603 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1604 ar = (AsyncResult) msg.obj;
1605 request = (MainThreadRequest) ar.userObj;
1606 if (ar.exception != null) {
1607 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1608 } else {
1609 request.result = ((int[]) ar.result)[0];
1610 }
1611 notifyRequester(request);
1612 break;
1613 case CMD_SET_CDMA_ROAMING_MODE:
1614 request = (MainThreadRequest) msg.obj;
1615 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1616 int mode = (int) request.argument;
1617 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1618 break;
1619 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 request.result = ar.exception == null;
1623 notifyRequester(request);
1624 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001625 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1628 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1629 break;
1630 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception != null) {
1634 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1635 } else {
1636 request.result = ((int[]) ar.result)[0];
1637 }
1638 notifyRequester(request);
1639 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1641 request = (MainThreadRequest) msg.obj;
1642 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1643 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001644 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1645 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 break;
1647 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 request.result = ar.exception == null;
1651 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001652 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001653 case CMD_GET_ALL_CELL_INFO:
1654 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001655 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001656 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 case EVENT_GET_ALL_CELL_INFO_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001661 // If a timeout occurs, the response will be null
1662 request.result = (ar.exception == null && ar.result != null)
1663 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 synchronized (request) {
1665 request.notifyAll();
1666 }
1667 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001668 case CMD_REQUEST_CELL_INFO_UPDATE:
1669 request = (MainThreadRequest) msg.obj;
1670 request.phone.requestCellInfoUpdate(request.workSource,
1671 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1672 break;
1673 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1674 ar = (AsyncResult) msg.obj;
1675 request = (MainThreadRequest) ar.userObj;
1676 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1677 try {
1678 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001679 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001680 cb.onError(
1681 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1682 ar.exception.getClass().getName(),
1683 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001684 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001686 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001687 } else {
1688 // use the result as returned
1689 cb.onCellInfo((List<CellInfo>) ar.result);
1690 }
1691 } catch (RemoteException re) {
1692 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1693 }
1694 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001695 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 request = (MainThreadRequest) msg.obj;
1697 WorkSource ws = (WorkSource) request.argument;
1698 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001699 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001700 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001701 }
1702 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 if (ar.exception == null) {
1706 request.result = ar.result;
1707 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001708 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001710 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001711 }
1712
1713 synchronized (request) {
1714 request.notifyAll();
1715 }
1716 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001717 }
chen xu6dac5ab2018-10-26 17:39:23 -07001718 case CMD_MODEM_REBOOT:
1719 request = (MainThreadRequest) msg.obj;
1720 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001721 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001722 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001723 case EVENT_CMD_MODEM_REBOOT_DONE:
1724 handleNullReturnEvent(msg, "rebootModem");
1725 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001726 case CMD_REQUEST_ENABLE_MODEM:
1727 request = (MainThreadRequest) msg.obj;
1728 boolean enable = (boolean) request.argument;
1729 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001730 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001731 PhoneConfigurationManager.getInstance()
1732 .enablePhone(request.phone, enable, onCompleted);
1733 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001734 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001738 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001739 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001740 if ((boolean) request.result) {
1741 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1742 updateModemStateMetrics();
1743 } else {
1744 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1745 + ar.exception);
1746 }
1747 notifyRequester(request);
1748 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001749 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001750 case CMD_GET_MODEM_STATUS:
1751 request = (MainThreadRequest) msg.obj;
1752 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1753 PhoneConfigurationManager.getInstance()
1754 .getPhoneStatusFromModem(request.phone, onCompleted);
1755 break;
1756 case EVENT_GET_MODEM_STATUS_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 int id = request.phone.getPhoneId();
1760 if (ar.exception == null && ar.result != null) {
1761 request.result = ar.result;
1762 //update the cache as modem status has changed
1763 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1764 (boolean) request.result);
1765 } else {
1766 // Return true if modem status cannot be retrieved. For most cases,
1767 // modem status is on. And for older version modems, GET_MODEM_STATUS
1768 // and disable modem are not supported. Modem is always on.
1769 // TODO: this should be fixed in R to support a third
1770 // status UNKNOWN b/131631629
1771 request.result = true;
1772 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1773 + ar.exception);
1774 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001775 notifyRequester(request);
1776 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001777 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1778 request = (MainThreadRequest) msg.obj;
1779 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1780 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1781 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1782 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1783 break;
1784 }
1785 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1786 ar = (AsyncResult) msg.obj;
1787 request = (MainThreadRequest) ar.userObj;
1788 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1789 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1790 args.second.accept(ar.exception == null);
1791 notifyRequester(request);
1792 break;
1793 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001794 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1795 request = (MainThreadRequest) msg.obj;
1796 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1797 Phone phone = getPhoneFromRequest(request);
1798 if (phone != null) {
1799 phone.getSystemSelectionChannels(onCompleted);
1800 } else {
1801 loge("getSystemSelectionChannels: No phone object");
1802 request.result = new ArrayList<RadioAccessSpecifier>();
1803 notifyRequester(request);
1804 }
1805 break;
1806 }
1807 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1808 ar = (AsyncResult) msg.obj;
1809 request = (MainThreadRequest) ar.userObj;
1810 if (ar.exception == null && ar.result != null) {
1811 request.result = ar.result;
1812 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001813 request.result = new IllegalStateException(
1814 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001815 if (ar.result == null) {
1816 loge("getSystemSelectionChannels: Empty response");
1817 } else {
1818 loge("getSystemSelectionChannels: Unknown exception");
1819 }
1820 }
1821 notifyRequester(request);
1822 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001823 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1824 ar = (AsyncResult) msg.obj;
1825 request = (MainThreadRequest) ar.userObj;
1826 if (ar.exception == null && ar.result != null) {
1827 request.result = ar.result;
1828 } else {
1829 request.result = -1;
1830 loge("Failed to set Forbidden Plmns");
1831 if (ar.result == null) {
1832 loge("setForbidenPlmns: Empty response");
1833 } else if (ar.exception != null) {
1834 loge("setForbiddenPlmns: Exception: " + ar.exception);
1835 request.result = -1;
1836 } else {
1837 loge("setForbiddenPlmns: Unknown exception");
1838 }
1839 }
1840 notifyRequester(request);
1841 break;
1842 case CMD_SET_FORBIDDEN_PLMNS:
1843 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001844 uiccPort = getUiccPortFromRequest(request);
1845 if (uiccPort == null) {
1846 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001847 request.result = -1;
1848 notifyRequester(request);
1849 break;
1850 }
1851 Pair<Integer, List<String>> setFplmnsArgs =
1852 (Pair<Integer, List<String>>) request.argument;
1853 appType = setFplmnsArgs.first;
1854 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001855 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001856 if (uiccApp == null) {
1857 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1858 request.result = -1;
1859 loge("Failed to get UICC App");
1860 notifyRequester(request);
1861 } else {
1862 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1863 ((SIMRecords) uiccApp.getIccRecords())
1864 .setForbiddenPlmns(onCompleted, fplmns);
1865 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001866 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001867 case CMD_ERASE_MODEM_CONFIG:
1868 request = (MainThreadRequest) msg.obj;
1869 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1870 defaultPhone.eraseModemConfig(onCompleted);
1871 break;
1872 case EVENT_ERASE_MODEM_CONFIG_DONE:
1873 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001874 break;
zoey chene02881a2019-12-30 16:11:23 +08001875
Kai Shif70f46f2021-03-03 13:59:46 -08001876 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1877 request = (MainThreadRequest) msg.obj;
1878 request.result = defaultPhone.eraseDataInSharedPreferences();
1879 notifyRequester(request);
1880 break;
1881
zoey chene02881a2019-12-30 16:11:23 +08001882 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1883 request = (MainThreadRequest) msg.obj;
1884 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1885 Pair<String, String> changed = (Pair<String, String>) request.argument;
1886 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1887 changed.first, changed.second, onCompleted);
1888 break;
1889 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1890 ar = (AsyncResult) msg.obj;
1891 request = (MainThreadRequest) ar.userObj;
1892 if (ar.exception == null) {
1893 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001894 // If the operation is successful, update the PIN storage
1895 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1896 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001897 UiccController.getInstance().getPinStorage()
1898 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001899 } else {
1900 request.result = msg.arg1;
1901 }
1902 notifyRequester(request);
1903 break;
1904
Michele Berionne5e411512020-11-13 02:36:59 +00001905 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001906 request = (MainThreadRequest) msg.obj;
1907 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1908 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1909 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1910 enabled.first, enabled.second, onCompleted);
1911 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001912 }
zoey chene02881a2019-12-30 16:11:23 +08001913 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1914 ar = (AsyncResult) msg.obj;
1915 request = (MainThreadRequest) ar.userObj;
1916 if (ar.exception == null) {
1917 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001918 // If the operation is successful, update the PIN storage
1919 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1920 int phoneId = getPhoneFromRequest(request).getPhoneId();
1921 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001922 UiccController.getInstance().getPinStorage()
1923 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001924 } else {
1925 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1926 }
zoey chene02881a2019-12-30 16:11:23 +08001927 } else {
1928 request.result = msg.arg1;
1929 }
Michele Berionne5e411512020-11-13 02:36:59 +00001930
1931
zoey chene02881a2019-12-30 16:11:23 +08001932 notifyRequester(request);
1933 break;
1934
Peter Wangdafb9ac2020-01-15 14:13:38 -08001935 case MSG_NOTIFY_USER_ACTIVITY:
1936 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001937 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001938 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1939 getDefaultPhone().getContext().sendBroadcastAsUser(
1940 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1941 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001942
1943 case CMD_SET_DATA_THROTTLING: {
1944 request = (MainThreadRequest) msg.obj;
1945 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1946 DataThrottlingRequest dataThrottlingRequest =
1947 (DataThrottlingRequest) request.argument;
1948 Phone phone = getPhoneFromRequest(request);
1949 if (phone != null) {
1950 phone.setDataThrottling(onCompleted,
1951 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1952 dataThrottlingRequest.getCompletionDurationMillis());
1953 } else {
1954 loge("setDataThrottling: No phone object");
1955 request.result =
1956 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1957 notifyRequester(request);
1958 }
1959
1960 break;
1961 }
1962 case EVENT_SET_DATA_THROTTLING_DONE:
1963 ar = (AsyncResult) msg.obj;
1964 request = (MainThreadRequest) ar.userObj;
1965
1966 if (ar.exception == null) {
1967 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1968 } else if (ar.exception instanceof CommandException) {
1969 loge("setDataThrottling: CommandException: " + ar.exception);
1970 CommandException.Error error =
1971 ((CommandException) (ar.exception)).getCommandError();
1972
1973 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1974 request.result = TelephonyManager
1975 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1976 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1977 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001978 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1979 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001980 } else {
1981 request.result =
1982 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1983 }
1984 } else {
1985 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1986 }
1987 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1988 notifyRequester(request);
1989 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001990
1991 case CMD_SET_SIM_POWER: {
1992 request = (MainThreadRequest) msg.obj;
1993 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1994 request = (MainThreadRequest) msg.obj;
1995 int stateToSet =
1996 ((Pair<Integer, IIntegerConsumer>)
1997 request.argument).first;
1998 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1999 break;
2000 }
2001 case EVENT_SET_SIM_POWER_DONE: {
2002 ar = (AsyncResult) msg.obj;
2003 request = (MainThreadRequest) ar.userObj;
2004 IIntegerConsumer callback =
2005 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2006 if (ar.exception != null) {
2007 loge("setSimPower exception: " + ar.exception);
2008 int errorCode = TelephonyManager.CallForwardingInfoCallback
2009 .RESULT_ERROR_UNKNOWN;
2010 if (ar.exception instanceof CommandException) {
2011 CommandException.Error error =
2012 ((CommandException) (ar.exception)).getCommandError();
2013 if (error == CommandException.Error.SIM_ERR) {
2014 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2015 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2016 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2017 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2018 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2019 } else {
2020 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2021 }
2022 }
2023 try {
2024 callback.accept(errorCode);
2025 } catch (RemoteException e) {
2026 // Ignore if the remote process is no longer available to call back.
2027 Log.w(LOG_TAG, "setSimPower: callback not available.");
2028 }
2029 } else {
2030 try {
2031 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2032 } catch (RemoteException e) {
2033 // Ignore if the remote process is no longer available to call back.
2034 Log.w(LOG_TAG, "setSimPower: callback not available.");
2035 }
2036 }
2037 break;
2038 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002039 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2040 request = (MainThreadRequest) msg.obj;
2041
2042 final Phone phone = getPhoneFromRequest(request);
2043 if (phone == null || phone.getServiceStateTracker() == null) {
2044 request.result = new IllegalStateException("Phone or SST is null");
2045 notifyRequester(request);
2046 break;
2047 }
2048
2049 Pair<Integer, SignalStrengthUpdateRequest> pair =
2050 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2051 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2052 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002053 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002054 request.subId, pair.first /*callingUid*/,
2055 pair.second /*request*/, onCompleted);
2056 break;
2057 }
2058 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2059 ar = (AsyncResult) msg.obj;
2060 request = (MainThreadRequest) ar.userObj;
2061 // request.result will be the exception of ar if present, true otherwise.
2062 // Be cautious not to leave result null which will wait() forever
2063 request.result = ar.exception != null ? ar.exception : true;
2064 notifyRequester(request);
2065 break;
2066 }
2067 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2068 request = (MainThreadRequest) msg.obj;
2069
2070 Phone phone = getPhoneFromRequest(request);
2071 if (phone == null || phone.getServiceStateTracker() == null) {
2072 request.result = new IllegalStateException("Phone or SST is null");
2073 notifyRequester(request);
2074 break;
2075 }
2076
2077 Pair<Integer, SignalStrengthUpdateRequest> pair =
2078 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2079 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2080 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002081 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002082 request.subId, pair.first /*callingUid*/,
2083 pair.second /*request*/, onCompleted);
2084 break;
2085 }
2086 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2087 ar = (AsyncResult) msg.obj;
2088 request = (MainThreadRequest) ar.userObj;
2089 request.result = ar.exception != null ? ar.exception : true;
2090 notifyRequester(request);
2091 break;
2092 }
Jordan Liu109698e2020-11-24 14:50:34 -08002093
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002094 case CMD_GET_SLICING_CONFIG: {
2095 request = (MainThreadRequest) msg.obj;
2096 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2097 request.phone.getSlicingConfig(onCompleted);
2098 break;
2099 }
2100 case EVENT_GET_SLICING_CONFIG_DONE: {
2101 ar = (AsyncResult) msg.obj;
2102 request = (MainThreadRequest) ar.userObj;
2103 ResultReceiver result = (ResultReceiver) request.argument;
2104
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002105 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002106 Bundle bundle = new Bundle();
2107 int resultCode = 0;
2108 if (ar.exception != null) {
2109 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2110 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002112 } else if (ar.result == null) {
2113 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002114 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002115 } else {
2116 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002117 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2118 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002119 }
2120
2121 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002122 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002123 }
2124 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2125 result.send(resultCode, bundle);
2126 notifyRequester(request);
2127 break;
2128 }
2129
Michele Berionne5e411512020-11-13 02:36:59 +00002130 case CMD_PREPARE_UNATTENDED_REBOOT:
2131 request = (MainThreadRequest) msg.obj;
2132 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002133 UiccController.getInstance().getPinStorage()
2134 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002135 notifyRequester(request);
2136 break;
2137
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 default:
2139 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2140 break;
2141 }
2142 }
Jake Hambye994d462014-02-03 13:10:13 -08002143
Pengquan Menga1bb6272018-09-06 09:59:22 -07002144 private void notifyRequester(MainThreadRequest request) {
2145 synchronized (request) {
2146 request.notifyAll();
2147 }
2148 }
2149
Jake Hambye994d462014-02-03 13:10:13 -08002150 private void handleNullReturnEvent(Message msg, String command) {
2151 AsyncResult ar = (AsyncResult) msg.obj;
2152 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2153 if (ar.exception == null) {
2154 request.result = true;
2155 } else {
2156 request.result = false;
2157 if (ar.exception instanceof CommandException) {
2158 loge(command + ": CommandException: " + ar.exception);
2159 } else {
2160 loge(command + ": Unknown exception");
2161 }
2162 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002163 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
2167 /**
2168 * Posts the specified command to be executed on the main thread,
2169 * waits for the request to complete, and returns the result.
2170 * @see #sendRequestAsync
2171 */
2172 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002173 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2174 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002175 }
2176
2177 /**
2178 * Posts the specified command to be executed on the main thread,
2179 * waits for the request to complete, and returns the result.
2180 * @see #sendRequestAsync
2181 */
2182 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2183 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002184 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
2187 /**
2188 * Posts the specified command to be executed on the main thread,
2189 * waits for the request to complete, and returns the result.
2190 * @see #sendRequestAsync
2191 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002192 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002193 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2194 }
2195
2196 /**
2197 * Posts the specified command to be executed on the main thread,
2198 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2199 * if not timeout or null otherwise.
2200 * @see #sendRequestAsync
2201 */
2202 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2203 long timeoutInMs) {
2204 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002205 }
2206
2207 /**
2208 * Posts the specified command to be executed on the main thread,
2209 * waits for the request to complete, and returns the result.
2210 * @see #sendRequestAsync
2211 */
Nathan Harold92bed182018-10-12 18:16:49 -07002212 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002213 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002214 }
2215
2216 /**
2217 * Posts the specified command to be executed on the main thread,
2218 * waits for the request to complete, and returns the result.
2219 * @see #sendRequestAsync
2220 */
2221 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002222 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2223 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002224 }
2225
2226 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002227 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2228 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2229 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002230 * @see #sendRequestAsync
2231 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002232 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2233 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2235 throw new RuntimeException("This method will deadlock if called from the main thread.");
2236 }
2237
Nathan Harold92bed182018-10-12 18:16:49 -07002238 MainThreadRequest request = null;
2239 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2240 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2241 } else if (phone != null) {
2242 request = new MainThreadRequest(argument, phone, workSource);
2243 } else {
2244 request = new MainThreadRequest(argument, subId, workSource);
2245 }
2246
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 Message msg = mMainThreadHandler.obtainMessage(command, request);
2248 msg.sendToTarget();
2249
Rambo Wang0f050d82021-02-12 11:43:36 -08002250
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002252 if (timeoutInMs >= 0) {
2253 // Wait for at least timeoutInMs before returning null request result
2254 long now = SystemClock.elapsedRealtime();
2255 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002256 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002257 try {
2258 request.wait(deadline - now);
2259 } catch (InterruptedException e) {
2260 // Do nothing, go back and check if request is completed or timeout
2261 } finally {
2262 now = SystemClock.elapsedRealtime();
2263 }
2264 }
2265 } else {
2266 // Wait for the request to complete
2267 while (request.result == null) {
2268 try {
2269 request.wait();
2270 } catch (InterruptedException e) {
2271 // Do nothing, go back and wait until the request is complete
2272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274 }
2275 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002276 if (request.result == null) {
2277 Log.wtf(LOG_TAG,
2278 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 return request.result;
2281 }
2282
2283 /**
2284 * Asynchronous ("fire and forget") version of sendRequest():
2285 * Posts the specified command to be executed on the main thread, and
2286 * returns immediately.
2287 * @see #sendRequest
2288 */
2289 private void sendRequestAsync(int command) {
2290 mMainThreadHandler.sendEmptyMessage(command);
2291 }
2292
2293 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002294 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002295 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002296 */
2297 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002298 sendRequestAsync(command, argument, null, null);
2299 }
2300
2301 /**
2302 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2303 * @see {@link #sendRequest(int,Object)}
2304 */
2305 private void sendRequestAsync(
2306 int command, Object argument, Phone phone, WorkSource workSource) {
2307 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002308 Message msg = mMainThreadHandler.obtainMessage(command, request);
2309 msg.sendToTarget();
2310 }
2311
2312 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 * Initialize the singleton PhoneInterfaceManager instance.
2314 * This is only done once, at startup, from PhoneApp.onCreate().
2315 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002316 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 synchronized (PhoneInterfaceManager.class) {
2318 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002319 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 } else {
2321 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2322 }
2323 return sInstance;
2324 }
2325 }
2326
2327 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002328 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002331 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002332 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002334 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002336 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002337 mTelephonySharedPreferences =
2338 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002339 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002340 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002341 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002342 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 publish();
2345 }
2346
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002347 private Phone getDefaultPhone() {
2348 Phone thePhone = getPhone(getDefaultSubscription());
2349 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2350 }
2351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 private void publish() {
2353 if (DBG) log("publish: " + this);
2354
Peter Wangc035ce42020-01-08 21:00:22 -08002355 TelephonyFrameworkInitializer
2356 .getTelephonyServiceManager()
2357 .getTelephonyServiceRegisterer()
2358 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
Stuart Scott584921c2015-01-15 17:10:34 -08002361 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002362 if (request.phone != null) {
2363 return request.phone;
2364 } else {
2365 return getPhoneFromSubId(request.subId);
2366 }
2367 }
2368
2369 private Phone getPhoneFromSubId(int subId) {
2370 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2371 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002372 }
2373
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002374 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002375 Phone phone = getPhoneFromRequest(request);
2376 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002377 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002378 }
2379
Wink Saville36469e72014-06-11 15:17:00 -07002380 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002381 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002382 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384
Kai Shif70f46f2021-03-03 13:59:46 -08002385 private void sendEraseModemConfig(@NonNull Phone phone) {
2386 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2387 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2388 }
2389
2390 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2391 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2392 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002393 }
2394
Peter Wang44b186e2020-01-13 23:33:09 -08002395 private boolean isImsAvailableOnDevice() {
2396 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2397 if (pm == null) {
2398 // For some reason package manger is not available.. This will fail internally anyway,
2399 // so do not throw error and allow.
2400 return true;
2401 }
2402 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2403 }
2404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002406 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002407 }
2408
Wink Savilleb564aae2014-10-23 10:18:09 -07002409 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 if (DBG) log("dial: " + number);
2411 // No permission check needed here: This is just a wrapper around the
2412 // ACTION_DIAL intent, which is available to any app since it puts up
2413 // the UI before it does anything.
2414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 String url = createTelUrl(number);
2418 if (url == null) {
2419 return;
2420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 // PENDING: should we just silently fail if phone is offhook or ringing?
2423 PhoneConstants.State state = mCM.getState(subId);
2424 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2425 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2426 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2427 mApp.startActivity(intent);
2428 }
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432 }
2433
2434 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002435 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002436 }
2437
Wink Savilleb564aae2014-10-23 10:18:09 -07002438 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 if (DBG) log("call: " + number);
2440
2441 // This is just a wrapper around the ACTION_CALL intent, but we still
2442 // need to do a permission check since we're calling startActivity()
2443 // from the context of the phone app.
2444 enforceCallPermission();
2445
Jordan Liu1617b712019-07-10 15:06:26 -07002446 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 != AppOpsManager.MODE_ALLOWED) {
2448 return;
2449 }
2450
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 String url = createTelUrl(number);
2454 if (url == null) {
2455 return;
2456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458 boolean isValid = false;
2459 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2460 if (slist != null) {
2461 for (SubscriptionInfo subInfoRecord : slist) {
2462 if (subInfoRecord.getSubscriptionId() == subId) {
2463 isValid = true;
2464 break;
2465 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002466 }
Wink Saville08874612014-08-31 19:19:58 -07002467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 if (!isValid) {
2469 return;
2470 }
Wink Saville08874612014-08-31 19:19:58 -07002471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2473 intent.putExtra(SUBSCRIPTION_KEY, subId);
2474 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2475 mApp.startActivity(intent);
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
2478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 }
2480
Wink Savilleb564aae2014-10-23 10:18:09 -07002481 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002482 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002483 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2484 }
2485
Wink Savilleb564aae2014-10-23 10:18:09 -07002486 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002487 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002488 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2489 }
2490
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002496 Phone phone = getPhone(subId);
2497 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 checkSimPin.start();
2499 return checkSimPin.unlockSim(null, pin);
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
2502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 }
2504
Wink Savilleb564aae2014-10-23 10:18:09 -07002505 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002510 Phone phone = getPhone(subId);
2511 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 checkSimPuk.start();
2513 return checkSimPuk.unlockSim(puk, pin);
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002520 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 * a synchronous one.
2522 */
2523 private static class UnlockSim extends Thread {
2524
2525 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002526 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527
2528 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002529 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2530 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531
2532 // For replies from SimCard interface
2533 private Handler mHandler;
2534
2535 // For async handler to identify request type
2536 private static final int SUPPLY_PIN_COMPLETE = 100;
2537
Michele Berionne5e411512020-11-13 02:36:59 +00002538 UnlockSim(int phoneId, IccCard simCard) {
2539 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 mSimCard = simCard;
2541 }
2542
2543 @Override
2544 public void run() {
2545 Looper.prepare();
2546 synchronized (UnlockSim.this) {
2547 mHandler = new Handler() {
2548 @Override
2549 public void handleMessage(Message msg) {
2550 AsyncResult ar = (AsyncResult) msg.obj;
2551 switch (msg.what) {
2552 case SUPPLY_PIN_COMPLETE:
2553 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2554 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002555 mRetryCount = msg.arg1;
2556 if (ar.exception != null) {
2557 if (ar.exception instanceof CommandException &&
2558 ((CommandException)(ar.exception)).getCommandError()
2559 == CommandException.Error.PASSWORD_INCORRECT) {
2560 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002561 } //When UiccCardApp dispose,handle message and return exception
2562 else if (ar.exception instanceof CommandException &&
2563 ((CommandException) (ar.exception)).getCommandError()
2564 == CommandException.Error.ABORTED) {
2565 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002566 } else {
2567 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2568 }
2569 } else {
2570 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 mDone = true;
2573 UnlockSim.this.notifyAll();
2574 }
2575 break;
2576 }
2577 }
2578 };
2579 UnlockSim.this.notifyAll();
2580 }
2581 Looper.loop();
2582 }
2583
2584 /*
2585 * Use PIN or PUK to unlock SIM card
2586 *
2587 * If PUK is null, unlock SIM card with PIN
2588 *
2589 * If PUK is not null, unlock SIM card with PUK and set PIN code
2590 */
Wink Saville9de0f752013-10-22 19:04:03 -07002591 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
2593 while (mHandler == null) {
2594 try {
2595 wait();
2596 } catch (InterruptedException e) {
2597 Thread.currentThread().interrupt();
2598 }
2599 }
2600 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2601
2602 if (puk == null) {
2603 mSimCard.supplyPin(pin, callback);
2604 } else {
2605 mSimCard.supplyPuk(puk, pin, callback);
2606 }
2607
2608 while (!mDone) {
2609 try {
2610 Log.d(LOG_TAG, "wait for done");
2611 wait();
2612 } catch (InterruptedException e) {
2613 // Restore the interrupted status
2614 Thread.currentThread().interrupt();
2615 }
2616 }
2617 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002618 int[] resultArray = new int[2];
2619 resultArray[0] = mResult;
2620 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002621
2622 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002623 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002624 }
2625
Wink Saville9de0f752013-10-22 19:04:03 -07002626 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628 }
2629
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002630 /**
2631 * This method has been removed due to privacy and stability concerns.
2632 */
2633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002635 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2636 return;
Wink Saville36469e72014-06-11 15:17:00 -07002637 }
2638
Nathan Harold1f889d82020-06-04 17:05:26 -07002639 @Override
2640 public void updateServiceLocationWithPackageName(String callingPackage) {
2641 mApp.getSystemService(AppOpsManager.class)
2642 .checkPackage(Binder.getCallingUid(), callingPackage);
2643
Nathan Haroldf096d982020-11-18 17:18:06 -08002644 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002645 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2646 // Callers targeting S have no business invoking this method.
2647 return;
2648 }
2649
2650 LocationAccessPolicy.LocationPermissionResult locationResult =
2651 LocationAccessPolicy.checkLocationPermission(mApp,
2652 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2653 .setCallingPackage(callingPackage)
2654 .setCallingFeatureId(null)
2655 .setCallingPid(Binder.getCallingPid())
2656 .setCallingUid(Binder.getCallingUid())
2657 .setMethod("updateServiceLocation")
2658 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2659 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2660 .build());
2661 // Apps that lack location permission have no business calling this method;
2662 // however, because no permission was declared in the public API, denials must
2663 // all be "soft".
2664 switch (locationResult) {
2665 case DENIED_HARD: /* fall through */
2666 case DENIED_SOFT:
2667 return;
2668 }
2669
2670 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 final long identity = Binder.clearCallingIdentity();
2672 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002673 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002675 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 }
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
2681
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002682 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002683 @Override
2684 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002685 return isRadioOnWithFeature(callingPackage, null);
2686 }
2687
2688
2689 @Override
2690 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2691 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2692 callingFeatureId);
2693 }
2694
2695 @Deprecated
2696 @Override
2697 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2698 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002699 }
2700
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002702 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2703 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002705 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002706 return false;
2707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 return isRadioOnForSubscriber(subId);
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 }
2716
2717 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 if (phone != null) {
2722 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2723 } else {
2724 return false;
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 }
2730
2731 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002732 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 }
Wink Saville36469e72014-06-11 15:17:00 -07002734
Wink Savilleb564aae2014-10-23 10:18:09 -07002735 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 final Phone phone = getPhone(subId);
2741 if (phone != null) {
2742 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002746 }
Wink Saville36469e72014-06-11 15:17:00 -07002747 }
2748
2749 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002750 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002751 }
2752
Wink Savilleb564aae2014-10-23 10:18:09 -07002753 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755
2756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 final Phone phone = getPhone(subId);
2759 if (phone == null) {
2760 return false;
2761 }
2762 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2763 toggleRadioOnOffForSubscriber(subId);
2764 }
2765 return true;
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
Wink Saville36469e72014-06-11 15:17:00 -07002770
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002771 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002772 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002773 /*
2774 * If any of the Radios are available, it will need to be
2775 * shutdown. So return true if any Radio is available.
2776 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2780 Phone phone = PhoneFactory.getPhone(i);
2781 if (phone != null && phone.isRadioAvailable()) return true;
2782 }
2783 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2784 return false;
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002787 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002788 }
2789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002791 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 enforceModifyPermission();
2793
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2797 logv("Shutting down Phone " + i);
2798 shutdownRadioUsingPhoneId(i);
2799 }
2800 } finally {
2801 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002802 }
2803 }
2804
2805 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002806 Phone phone = PhoneFactory.getPhone(phoneId);
2807 if (phone != null && phone.isRadioAvailable()) {
2808 phone.shutdownRadio();
2809 }
2810 }
2811
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2818 if (defaultPhone != null) {
2819 defaultPhone.setRadioPower(turnOn);
2820 return true;
2821 } else {
2822 loge("There's no default phone.");
2823 return false;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002827 }
Wink Saville36469e72014-06-11 15:17:00 -07002828 }
2829
Wink Savilleb564aae2014-10-23 10:18:09 -07002830 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832
2833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 final Phone phone = getPhone(subId);
2836 if (phone != null) {
2837 phone.setRadioPower(turnOn);
2838 return true;
2839 } else {
2840 return false;
2841 }
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846
Wink Saville36469e72014-06-11 15:17:00 -07002847 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002848 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 public boolean enableDataConnectivity() {
2850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851
2852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 int subId = mSubscriptionController.getDefaultDataSubId();
2855 final Phone phone = getPhone(subId);
2856 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002857 if (phone.isUsingNewDataStack()) {
2858 phone.getDataSettingsManager().setDataEnabled(
2859 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2860 } else {
2861 phone.getDataEnabledSettings().setDataEnabled(
2862 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 return true;
2865 } else {
2866 return false;
2867 }
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 }
2872
Wink Saville36469e72014-06-11 15:17:00 -07002873 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 public boolean disableDataConnectivity() {
2876 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 int subId = mSubscriptionController.getDefaultDataSubId();
2881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002883 if (phone.isUsingNewDataStack()) {
2884 phone.getDataSettingsManager().setDataEnabled(
2885 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2886 } else {
2887 phone.getDataEnabledSettings().setDataEnabled(
2888 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 return true;
2891 } else {
2892 return false;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 }
2898
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002900 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002905 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 } else {
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
2914 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002915 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002916 }
2917
pkanwarae03a6b2016-11-06 20:37:09 -08002918 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 enforceCallPermission();
2920
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2924 return;
2925 }
2926 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2927 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
pkanwar32d516d2016-10-14 19:37:38 -07002931 };
2932
Wink Savilleb564aae2014-10-23 10:18:09 -07002933 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935
2936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2939 return false;
2940 }
2941 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 }
2946
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002947 /**
2948 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2949 * tag on getCallState Binder call.
2950 */
2951 @Deprecated
2952 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002954 if (CompatChanges.isChangeEnabled(
2955 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2956 Binder.getCallingUid())) {
2957 // Do not allow this API to be called on API version 31+, it should only be
2958 // called on old apps using this Binder call directly.
2959 throw new SecurityException("This method can only be used for applications "
2960 + "targeting API version 30 or less.");
2961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002964 Phone phone = getPhone(getDefaultSubscription());
2965 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2966 PhoneConstantConversions.convertCallState(phone.getState());
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
2973 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2974 if (CompatChanges.isChangeEnabled(
2975 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2976 Binder.getCallingUid())) {
2977 // Check READ_PHONE_STATE for API version 31+
2978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2979 featureId, "getCallStateForSubscription")) {
2980 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2981 + "targeting API level 31+.");
2982 }
2983 }
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2988 PhoneConstantConversions.convertCallState(phone.getState());
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
2993
Sanket Padawe356d7632015-06-22 14:03:32 -07002994 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002995 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002996 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2997 }
2998
2999 @Override
3000 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003003 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003005 if (phone.isUsingNewDataStack()) {
3006 return phone.getDataNetworkController().getInternetDataNetworkState();
3007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3009 } else {
3010 return PhoneConstantConversions.convertDataState(
3011 PhoneConstants.DataState.DISCONNECTED);
3012 }
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
Sanket Padawe356d7632015-06-22 14:03:32 -07003018 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003019 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003020 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3021 }
3022
3023 @Override
3024 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 final long identity = Binder.clearCallingIdentity();
3026 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003027 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 if (phone != null) {
3029 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3030 } else {
3031 return TelephonyManager.DATA_ACTIVITY_NONE;
3032 }
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 }
3037
3038 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003039 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003040 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003041 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003042
3043 LocationAccessPolicy.LocationPermissionResult locationResult =
3044 LocationAccessPolicy.checkLocationPermission(mApp,
3045 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3046 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003047 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003048 .setCallingPid(Binder.getCallingPid())
3049 .setCallingUid(Binder.getCallingUid())
3050 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003051 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003052 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3053 .build());
3054 switch (locationResult) {
3055 case DENIED_HARD:
3056 throw new SecurityException("Not allowed to access cell location");
3057 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003058 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3059 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060 }
3061
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003062 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003066 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003067 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
Svetoslav64fad262015-04-14 14:35:21 -07003071 }
3072
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003074 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003075 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3076 // registered cell info, so return a NULL country instead.
3077 final long identity = Binder.clearCallingIdentity();
3078 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003079 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3080 // Get default phone in this case.
3081 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3082 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003083 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003085 if (phone == null) return "";
3086 ServiceStateTracker sst = phone.getServiceStateTracker();
3087 if (sst == null) return "";
3088 LocaleTracker lt = sst.getLocaleTracker();
3089 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003090 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003094 }
3095
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003096 /**
3097 * This method was removed due to potential issues caused by performing partial
3098 * updates of service state, and lack of a credible use case.
3099 *
3100 * This has the ability to break the telephony implementation by disabling notification of
3101 * changes in device connectivity. DO NOT USE THIS!
3102 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003103 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 public void enableLocationUpdates() {
3105 mApp.enforceCallingOrSelfPermission(
3106 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 }
3108
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003109 /**
3110 * This method was removed due to potential issues caused by performing partial
3111 * updates of service state, and lack of a credible use case.
3112 *
3113 * This has the ability to break the telephony implementation by disabling notification of
3114 * changes in device connectivity. DO NOT USE THIS!
3115 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 @Override
3117 public void disableLocationUpdates() {
3118 mApp.enforceCallingOrSelfPermission(
3119 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121
3122 @Override
3123 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003124 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3125 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003126 try {
3127 mApp.getSystemService(AppOpsManager.class)
3128 .checkPackage(Binder.getCallingUid(), callingPackage);
3129 } catch (SecurityException e) {
3130 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3131 throw e;
3132 }
3133
Nathan Haroldf096d982020-11-18 17:18:06 -08003134 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003135 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3136 throw new SecurityException(
3137 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3138 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003139
Jordan Liu1617b712019-07-10 15:06:26 -07003140 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3142 return null;
3143 }
Svetoslav64fad262015-04-14 14:35:21 -07003144
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003145 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003147 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003148 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149
Nathan Haroldf180aac2018-06-01 18:43:55 -07003150 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3151 for (CellInfo ci : info) {
3152 if (ci instanceof CellInfoGsm) {
3153 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3154 } else if (ci instanceof CellInfoWcdma) {
3155 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003158 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 }
3160
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003161 private List<CellInfo> getCachedCellInfo() {
3162 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3163 for (Phone phone : PhoneFactory.getPhones()) {
3164 List<CellInfo> info = phone.getAllCellInfo();
3165 if (info != null) cellInfos.addAll(info);
3166 }
3167 return cellInfos;
3168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169
3170 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003171 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003172 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003173 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003174
3175 LocationAccessPolicy.LocationPermissionResult locationResult =
3176 LocationAccessPolicy.checkLocationPermission(mApp,
3177 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3178 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003179 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 .setCallingPid(Binder.getCallingPid())
3181 .setCallingUid(Binder.getCallingUid())
3182 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003183 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003184 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3185 .build());
3186 switch (locationResult) {
3187 case DENIED_HARD:
3188 throw new SecurityException("Not allowed to access cell info");
3189 case DENIED_SOFT:
3190 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 }
3192
Nathan Haroldf096d982020-11-18 17:18:06 -08003193 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003194 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3195 return getCachedCellInfo();
3196 }
3197
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003198 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3203 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003204 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003205 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 if (info != null) cellInfos.addAll(info);
3207 }
3208 return cellInfos;
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 }
3212 }
3213
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003214 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003215 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3216 String callingFeatureId) {
3217 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3218 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003219 }
3220
3221 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003222 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3223 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003224 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003225 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003226 }
3227
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003228 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3229 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003230 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003231 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003232
3233 LocationAccessPolicy.LocationPermissionResult locationResult =
3234 LocationAccessPolicy.checkLocationPermission(mApp,
3235 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3236 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003237 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003238 .setCallingPid(Binder.getCallingPid())
3239 .setCallingUid(Binder.getCallingUid())
3240 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003241 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3242 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003243 .build());
3244 switch (locationResult) {
3245 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003246 if (TelephonyPermissions
3247 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003248 // Safetynet logging for b/154934934
3249 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3250 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003251 throw new SecurityException("Not allowed to access cell info");
3252 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003253 if (TelephonyPermissions
3254 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003255 // Safetynet logging for b/154934934
3256 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3257 }
Nathan Harold5320c422019-05-09 10:26:08 -07003258 try {
3259 cb.onCellInfo(new ArrayList<CellInfo>());
3260 } catch (RemoteException re) {
3261 // Drop without consequences
3262 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003263 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003264 }
3265
Nathan Harolda939a962019-05-09 10:13:47 -07003266
3267 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003268 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3269
3270 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3271 }
3272
3273 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003275 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003280 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 }
3285
Shishir Agrawala9f32182016-04-12 12:00:16 -07003286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003287 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003288 Phone phone = PhoneFactory.getPhone(slotIndex);
3289 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 return null;
3291 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003292 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003293 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003294 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003295 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003296 return null;
3297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 return phone.getImei();
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003305 }
3306
3307 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003308 public String getTypeAllocationCodeForSlot(int slotIndex) {
3309 Phone phone = PhoneFactory.getPhone(slotIndex);
3310 String tac = null;
3311 if (phone != null) {
3312 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003313 try {
3314 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3315 } catch (IndexOutOfBoundsException e) {
3316 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3317 return null;
3318 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003319 }
3320 return tac;
3321 }
3322
3323 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003324 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003325 try {
3326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3327 } catch (SecurityException se) {
3328 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3329 throw new SecurityException("Package " + callingPackage + " does not belong to "
3330 + Binder.getCallingUid());
3331 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003332 Phone phone = PhoneFactory.getPhone(slotIndex);
3333 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003334 return null;
3335 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336
Jeff Davidson913390f2018-02-23 17:11:49 -08003337 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003338 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003339 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003340 return null;
3341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 return phone.getMeid();
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
Jack Yu2af8d712017-03-15 17:14:14 -07003349 }
3350
3351 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003352 public String getManufacturerCodeForSlot(int slotIndex) {
3353 Phone phone = PhoneFactory.getPhone(slotIndex);
3354 String manufacturerCode = null;
3355 if (phone != null) {
3356 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003357 try {
3358 manufacturerCode =
3359 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3360 } catch (IndexOutOfBoundsException e) {
3361 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3362 return null;
3363 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003364 }
3365 return manufacturerCode;
3366 }
3367
3368 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003369 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3370 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003371 Phone phone = PhoneFactory.getPhone(slotIndex);
3372 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003373 return null;
3374 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003375 int subId = phone.getSubId();
3376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003377 mApp, subId, callingPackage, callingFeatureId,
3378 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003379 return null;
3380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 return phone.getDeviceSvn();
3385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003388 }
3389
fionaxu43304da2017-11-27 22:51:16 -08003390 @Override
3391 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 final Phone phone = getPhone(subId);
3395 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
fionaxu43304da2017-11-27 22:51:16 -08003399 }
3400
3401 @Override
3402 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 final Phone phone = getPhone(subId);
3406 return phone == null ? null : phone.getCarrierName();
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
fionaxu43304da2017-11-27 22:51:16 -08003410 }
3411
calvinpanffe225e2018-11-01 19:43:06 +08003412 @Override
chen xu0026ca62019-03-06 15:28:50 -08003413 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 final Phone phone = getPhone(subId);
3417 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003418 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
3422 }
3423
3424 @Override
chen xu0026ca62019-03-06 15:28:50 -08003425 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003429 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
chen xu651eec72018-11-11 19:03:44 -08003435 @Override
chen xu864e11c2018-12-06 22:10:03 -08003436 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3437 if (!isSubscriptionMccMnc) {
3438 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3439 }
chen xu651eec72018-11-11 19:03:44 -08003440 final Phone phone = PhoneFactory.getPhone(slotIndex);
3441 if (phone == null) {
3442 return TelephonyManager.UNKNOWN_CARRIER_ID;
3443 }
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
3450 }
3451
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 //
3453 // Internal helper methods.
3454 //
3455
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003456 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003457 * Make sure the caller is the calling package itself
3458 *
3459 * @throws SecurityException if the caller is not the calling package
3460 */
3461 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3462 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003463 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3464 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003465 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003466 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003467 } catch (PackageManager.NameNotFoundException e) {
3468 // packageUid is -1
3469 }
3470 if (packageUid != callingUid) {
3471 throw new SecurityException(message + ": Package " + callingPackage
3472 + " does not belong to " + callingUid);
3473 }
3474 }
3475
3476 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003477 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3478 *
3479 * @throws SecurityException if the caller does not have the required permission
3480 */
3481 private void enforceModifyPermission() {
3482 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3483 }
3484
Shuo Qian3b6ee772019-11-13 17:43:31 -08003485 private void enforceActiveEmergencySessionPermission() {
3486 mApp.enforceCallingOrSelfPermission(
3487 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3488 }
3489
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 /**
3491 * Make sure the caller has the CALL_PHONE permission.
3492 *
3493 * @throws SecurityException if the caller does not have the required permission
3494 */
3495 private void enforceCallPermission() {
3496 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3497 }
3498
paulhu5a773602019-08-23 19:17:33 +08003499 private void enforceSettingsPermission() {
3500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003501 }
3502
Michele Berionne5e411512020-11-13 02:36:59 +00003503 private void enforceRebootPermission() {
3504 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3505 }
3506
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 private String createTelUrl(String number) {
3508 if (TextUtils.isEmpty(number)) {
3509 return null;
3510 }
3511
Jake Hambye994d462014-02-03 13:10:13 -08003512 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 }
3514
Ihab Awadf9e92732013-12-05 18:02:52 -08003515 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003516 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3517 }
3518
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003519 private static void logv(String msg) {
3520 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3521 }
3522
Ihab Awadf9e92732013-12-05 18:02:52 -08003523 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3525 }
3526
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003527 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003529 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003530 }
3531
Sanket Padawe356d7632015-06-22 14:03:32 -07003532 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003533 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 final Phone phone = PhoneFactory.getPhone(slotIndex);
3537 if (phone == null) {
3538 return PhoneConstants.PHONE_TYPE_NONE;
3539 } else {
3540 return phone.getPhoneType();
3541 }
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003545 }
3546
3547 /**
3548 * Returns the CDMA ERI icon index to display
3549 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003551 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3552 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3553 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003554 }
3555
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003557 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3558 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003560 mApp, subId, callingPackage, callingFeatureId,
3561 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003562 return -1;
3563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564
3565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 final Phone phone = getPhone(subId);
3568 if (phone != null) {
3569 return phone.getCdmaEriIconIndex();
3570 } else {
3571 return -1;
3572 }
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003576 }
3577
3578 /**
3579 * Returns the CDMA ERI icon mode,
3580 * 0 - ON
3581 * 1 - FLASHING
3582 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003583 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003584 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3585 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3586 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003587 }
3588
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003590 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3591 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003593 mApp, subId, callingPackage, callingFeatureId,
3594 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003595 return -1;
3596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597
3598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 final Phone phone = getPhone(subId);
3601 if (phone != null) {
3602 return phone.getCdmaEriIconMode();
3603 } else {
3604 return -1;
3605 }
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003609 }
3610
3611 /**
3612 * Returns the CDMA ERI text,
3613 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003615 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3616 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3617 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003618 }
3619
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003621 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3622 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003624 mApp, subId, callingPackage, callingFeatureId,
3625 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003626 return null;
3627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628
3629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 final Phone phone = getPhone(subId);
3632 if (phone != null) {
3633 return phone.getCdmaEriText();
3634 } else {
3635 return null;
3636 }
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 }
3641
3642 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003643 * Returns the CDMA MDN.
3644 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003645 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003646 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3648 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 return phone.getLine1Number();
3655 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 return null;
3658 }
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003661 }
3662 }
3663
3664 /**
3665 * Returns the CDMA MIN.
3666 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003667 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003668 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3670 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 final Phone phone = getPhone(subId);
3675 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3676 return phone.getCdmaMin();
3677 } else {
3678 return null;
3679 }
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003682 }
3683 }
3684
Hall Liud892bec2018-11-30 14:51:45 -08003685 @Override
3686 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3687 INumberVerificationCallback callback, String callingPackage) {
3688 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3689 != PERMISSION_GRANTED) {
3690 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3691 }
3692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3693
3694 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3695 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003696 throw new SecurityException("Calling package must be configured in the device config: "
3697 + "calling package: " + callingPackage
3698 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003699 }
3700
3701 if (range == null) {
3702 throw new NullPointerException("Range must be non-null");
3703 }
3704
3705 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003706 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003707
3708 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3709 }
3710
Junda Liuca05d5d2014-08-14 22:36:34 -07003711 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003712 * Returns true if CDMA provisioning needs to run.
3713 */
3714 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715 final long identity = Binder.clearCallingIdentity();
3716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 }
3722
3723 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003724 * Sets the voice mail number of a given subId.
3725 */
3726 @Override
3727 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003728 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3729 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730
3731 final long identity = Binder.clearCallingIdentity();
3732 try {
3733 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3734 new Pair<String, String>(alphaTag, number), new Integer(subId));
3735 return success;
3736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003739 }
3740
Ta-wei Yen87c49842016-05-13 21:19:52 -07003741 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003742 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3743 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003744 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3745 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003746 if (!TextUtils.equals(callingPackage, systemDialer)) {
3747 throw new SecurityException("caller must be system dialer");
3748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749
3750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3753 if (phoneAccountHandle == null) {
3754 return null;
3755 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003756 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003759 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003760 }
3761
3762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3764 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003765 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003766 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003767 mApp, subId, callingPackage, callingFeatureId,
3768 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003769 return null;
3770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003772 final long identity = Binder.clearCallingIdentity();
3773 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003774 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003778 }
3779
3780 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003781 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3782 VisualVoicemailSmsFilterSettings settings) {
3783 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784
3785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003788 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003792 }
3793
3794 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003795 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003801 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003805 }
3806
3807 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003808 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3809 String callingPackage, int subId) {
3810 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811
3812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003815 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 } finally {
3817 Binder.restoreCallingIdentity(identity);
3818 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003819 }
3820
3821 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003822 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003823 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824
3825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003828 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003832 }
3833
3834 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003835 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3836 String callingAttributionTag, int subId, String number, int port, String text,
3837 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003839 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003840 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003841 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003842 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3843 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003844 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003845
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003846 /**
fionaxu0152e512016-11-14 13:36:14 -08003847 * Sets the voice activation state of a given subId.
3848 */
3849 @Override
3850 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3852 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853
3854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 final Phone phone = getPhone(subId);
3857 if (phone != null) {
3858 phone.setVoiceActivationState(activationState);
3859 } else {
3860 loge("setVoiceActivationState fails with invalid subId: " + subId);
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003864 }
3865 }
3866
3867 /**
3868 * Sets the data activation state of a given subId.
3869 */
3870 @Override
3871 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3873 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874
3875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 final Phone phone = getPhone(subId);
3878 if (phone != null) {
3879 phone.setDataActivationState(activationState);
3880 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003881 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 }
3883 } finally {
3884 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003885 }
3886 }
3887
3888 /**
3889 * Returns the voice activation state of a given subId.
3890 */
3891 @Override
3892 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894
fionaxu0152e512016-11-14 13:36:14 -08003895 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 if (phone != null) {
3899 return phone.getVoiceActivationState();
3900 } else {
3901 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3902 }
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003905 }
3906 }
3907
3908 /**
3909 * Returns the data activation state of a given subId.
3910 */
3911 @Override
3912 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914
fionaxu0152e512016-11-14 13:36:14 -08003915 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 if (phone != null) {
3919 return phone.getDataActivationState();
3920 } else {
3921 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3922 }
3923 } finally {
3924 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003925 }
3926 }
3927
3928 /**
Wink Saville36469e72014-06-11 15:17:00 -07003929 * Returns the unread count of voicemails for a subId
3930 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003931 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003932 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3933 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003935 mApp, subId, callingPackage, callingFeatureId,
3936 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003937 return 0;
3938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 final Phone phone = getPhone(subId);
3942 if (phone != null) {
3943 return phone.getVoiceMessageCount();
3944 } else {
3945 return 0;
3946 }
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003950 }
3951
3952 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003953 * returns true, if the device is in a state where both voice and data
3954 * are supported simultaneously. This can change based on location or network condition.
3955 */
3956 @Override
3957 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 final Phone phone = getPhone(subId);
3961 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003965 }
3966
3967 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003968 * Send the dialer code if called from the current default dialer or the caller has
3969 * carrier privilege.
3970 * @param inputCode The dialer code to send
3971 */
3972 @Override
3973 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003974 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003976 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3977 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003978 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003979 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003980 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982
3983 final long identity = Binder.clearCallingIdentity();
3984 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003985 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
fionaxu235cc5e2017-03-06 22:25:57 -08003989 }
3990
Pengquan Menga1bb6272018-09-06 09:59:22 -07003991 @Override
3992 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003993 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003994 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003995 mApp, subId, "getNetworkSelectionMode");
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 if (!isActiveSubscription(subId)) {
3999 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4000 }
4001 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4002 } finally {
4003 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004004 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004005 }
4006
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004008 public boolean isInEmergencySmsMode() {
4009 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 for (Phone phone : PhoneFactory.getPhones()) {
4013 if (phone.isInEmergencySmsMode()) {
4014 return true;
4015 }
4016 }
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
4020 return false;
4021 }
4022
shilu366312e2019-12-17 09:28:10 -08004023 /**
4024 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4025 * @param subId The subscription to use to check the configuration.
4026 * @param c The callback that will be used to send the result.
4027 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004028 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004029 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4030 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004031 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004032 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004033
4034 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4035 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4036 "IMS not available on device.");
4037 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 final long token = Binder.clearCallingIdentity();
4039 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004040 int slotId = getSlotIndexOrException(subId);
4041 verifyImsMmTelConfiguredOrThrow(slotId);
4042 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004043 } catch (ImsException e) {
4044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 } finally {
4046 Binder.restoreCallingIdentity(token);
4047 }
4048 }
4049
shilu366312e2019-12-17 09:28:10 -08004050 /**
4051 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4052 * @param subId The subscription to use to check the configuration.
4053 * @param c The callback that will be used to send the result.
4054 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004056 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004057 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004058 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004059 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4060 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4061 }
Meng Wangafbc5852019-09-19 17:37:13 -07004062 final long token = Binder.clearCallingIdentity();
4063 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004064 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4065 .removeRegistrationCallbackForSubscription(c, subId);
4066 } catch (ImsException e) {
4067 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4068 + "is inactive, ignoring unregister.");
4069 // If the subscription is no longer active, just return, since the callback
4070 // will already have been removed internally.
4071 } finally {
4072 Binder.restoreCallingIdentity(token);
4073 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 }
4075
Brad Ebingera34a6c22019-10-22 17:36:18 -07004076 /**
4077 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4078 */
4079 @Override
4080 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4081 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4082 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4083 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4084 "IMS not available on device.");
4085 }
4086 final long token = Binder.clearCallingIdentity();
4087 try {
4088 Phone phone = getPhone(subId);
4089 if (phone == null) {
4090 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4091 + subId + "'");
4092 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4093 }
4094 phone.getImsRegistrationState(regState -> {
4095 try {
4096 consumer.accept((regState == null)
4097 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4098 } catch (RemoteException e) {
4099 // Ignore if the remote process is no longer available to call back.
4100 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4101 }
4102 });
4103 } finally {
4104 Binder.restoreCallingIdentity(token);
4105 }
4106 }
4107
4108 /**
4109 * Get the transport type for the IMS service registration state.
4110 */
4111 @Override
4112 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004113 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004114 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004115 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4116 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4117 "IMS not available on device.");
4118 }
4119 final long token = Binder.clearCallingIdentity();
4120 try {
4121 Phone phone = getPhone(subId);
4122 if (phone == null) {
4123 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4124 + subId + "'");
4125 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4126 }
4127 phone.getImsRegistrationTech(regTech -> {
4128 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4129 int regTechConverted = (regTech == null)
4130 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4131 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4132 regTechConverted);
4133 try {
4134 consumer.accept(regTechConverted);
4135 } catch (RemoteException e) {
4136 // Ignore if the remote process is no longer available to call back.
4137 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4138 }
4139 });
4140 } finally {
4141 Binder.restoreCallingIdentity(token);
4142 }
4143 }
4144
shilu366312e2019-12-17 09:28:10 -08004145 /**
4146 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4147 * @param subId The subscription to use to check the configuration.
4148 * @param c The callback that will be used to send the result.
4149 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004151 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4152 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004153 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004154 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004155 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4156 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4157 "IMS not available on device.");
4158 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 final long token = Binder.clearCallingIdentity();
4160 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004161 int slotId = getSlotIndexOrException(subId);
4162 verifyImsMmTelConfiguredOrThrow(slotId);
4163 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004164 } catch (ImsException e) {
4165 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 } finally {
4167 Binder.restoreCallingIdentity(token);
4168 }
4169 }
4170
shilu366312e2019-12-17 09:28:10 -08004171 /**
4172 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4173 * @param subId The subscription to use to check the configuration.
4174 * @param c The callback that will be used to send the result.
4175 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004177 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004178 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004179 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004180 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4181 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4182 }
Meng Wangafbc5852019-09-19 17:37:13 -07004183
4184 final long token = Binder.clearCallingIdentity();
4185 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004186 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004187 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004188 } catch (ImsException e) {
4189 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4190 + "is inactive, ignoring unregister.");
4191 // If the subscription is no longer active, just return, since the callback
4192 // will already have been removed internally.
4193 } finally {
4194 Binder.restoreCallingIdentity(token);
4195 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 }
4197
4198 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004199 public boolean isCapable(int subId, int capability, int regTech) {
4200 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 final long token = Binder.clearCallingIdentity();
4202 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004203 int slotId = getSlotIndexOrException(subId);
4204 verifyImsMmTelConfiguredOrThrow(slotId);
4205 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4206 } catch (com.android.ims.ImsException e) {
4207 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4208 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004210 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4211 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 } finally {
4213 Binder.restoreCallingIdentity(token);
4214 }
4215 }
4216
4217 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004218 public boolean isAvailable(int subId, int capability, int regTech) {
4219 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 final long token = Binder.clearCallingIdentity();
4221 try {
4222 Phone phone = getPhone(subId);
4223 if (phone == null) return false;
4224 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004225 } catch (com.android.ims.ImsException e) {
4226 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4227 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 } finally {
4229 Binder.restoreCallingIdentity(token);
4230 }
4231 }
4232
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004233 /**
4234 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4235 * subscription.
4236 * @param subId The subscription to use to check the configuration.
4237 * @param callback The callback that will be used to send the result.
4238 * @param capability The MmTelFeature capability that will be used to send the result.
4239 * @param transportType The transport type of the MmTelFeature capability.
4240 */
4241 @Override
4242 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4243 int transportType) {
4244 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004245 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4247 "IMS not available on device.");
4248 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004249 final long token = Binder.clearCallingIdentity();
4250 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004251 int slotId = getSlotIndex(subId);
4252 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4253 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4254 + subId + "'");
4255 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4256 }
4257 verifyImsMmTelConfiguredOrThrow(slotId);
4258 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4259 transportType, aBoolean -> {
4260 try {
4261 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4262 } catch (RemoteException e) {
4263 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4264 + "running. Ignore");
4265 }
4266 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004267 } catch (ImsException e) {
4268 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004269 } finally {
4270 Binder.restoreCallingIdentity(token);
4271 }
4272 }
4273
shilu366312e2019-12-17 09:28:10 -08004274 /**
4275 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4276 * @param subId The subscription to use to check the configuration.
4277 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 @Override
4279 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004280 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004281 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004282
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 final long token = Binder.clearCallingIdentity();
4284 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004286 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004287 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004288 } catch (ImsException e) {
4289 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 } finally {
4291 Binder.restoreCallingIdentity(token);
4292 }
4293 }
4294
4295 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004296 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004298 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 final long identity = Binder.clearCallingIdentity();
4300 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004301 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004302 // This setting doesn't require an active ImsService connection, so do not verify. The
4303 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004304 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004305 } catch (ImsException e) {
4306 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
4310 }
4311
shilu366312e2019-12-17 09:28:10 -08004312 /**
4313 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4314 * @param subId The subscription to use to check the configuration.
4315 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004316 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004317 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004318 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004319 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 final long identity = Binder.clearCallingIdentity();
4321 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004323 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004324 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004325 } catch (ImsException e) {
4326 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
4330 }
4331
4332 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004333 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004335 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 final long identity = Binder.clearCallingIdentity();
4337 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004339 // This setting doesn't require an active ImsService connection, so do not verify. The
4340 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004341 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004342 } catch (ImsException e) {
4343 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
4347 }
4348
shilu366312e2019-12-17 09:28:10 -08004349 /**
4350 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4351 * @param subId The subscription to use to check the configuration.
4352 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 @Override
4354 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004355 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004356 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 final long identity = Binder.clearCallingIdentity();
4358 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004360 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004362 } catch (ImsException e) {
4363 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
4369 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004370 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004372 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 final long identity = Binder.clearCallingIdentity();
4374 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004376 // This setting doesn't require an active ImsService connection, so do not verify. The
4377 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004378 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004379 } catch (ImsException e) {
4380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
4384 }
4385
shilu366312e2019-12-17 09:28:10 -08004386 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004387 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4388 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4389 * @param subId The subscription to use to check the configuration.
4390 */
4391 @Override
4392 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004393 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004394 mApp, subId, "isCrossSimCallingEnabledByUser");
4395 final long identity = Binder.clearCallingIdentity();
4396 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004398 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004399 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004400 } catch (ImsException e) {
4401 throw new ServiceSpecificException(e.getCode());
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
4405 }
4406
4407 /**
4408 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4409 * Requires MODIFY_PHONE_STATE permission.
4410 * @param subId The subscription to use to check the configuration.
4411 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4412 * false otherwise
4413 */
4414 @Override
4415 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4417 "setCrossSimCallingEnabled");
4418 final long identity = Binder.clearCallingIdentity();
4419 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004420 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004421 // This setting doesn't require an active ImsService connection, so do not verify. The
4422 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004423 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004424 } catch (ImsException e) {
4425 throw new ServiceSpecificException(e.getCode());
4426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
4429 }
4430
4431 /**
shilu366312e2019-12-17 09:28:10 -08004432 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4433 * @param subId The subscription to use to check the configuration.
4434 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004436
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004438 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004439 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 final long identity = Binder.clearCallingIdentity();
4441 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004443 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004445 } catch (ImsException e) {
4446 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
4450 }
4451
4452 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004453 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004455 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 final long identity = Binder.clearCallingIdentity();
4457 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004459 // This setting doesn't require an active ImsService connection, so do not verify. The
4460 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4472 "setVoWiFiNonPersistent");
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004476 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004478 } catch (ImsException e) {
4479 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484
shilu366312e2019-12-17 09:28:10 -08004485 /**
4486 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4487 * @param subId The subscription to use to check the configuration.
4488 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 @Override
4490 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004491 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004492 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004496 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004498 } catch (ImsException e) {
4499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
4503 }
4504
4505 @Override
4506 public void setVoWiFiModeSetting(int subId, int mode) {
4507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4508 "setVoWiFiModeSetting");
4509 final long identity = Binder.clearCallingIdentity();
4510 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004511 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004512 // This setting doesn't require an active ImsService connection, so do not verify. The
4513 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004514 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004515 } catch (ImsException e) {
4516 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
4520 }
4521
4522 @Override
4523 public int getVoWiFiRoamingModeSetting(int subId) {
4524 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4525 final long identity = Binder.clearCallingIdentity();
4526 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004528 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004529 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004530 } catch (ImsException e) {
4531 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 } finally {
4533 Binder.restoreCallingIdentity(identity);
4534 }
4535 }
4536
4537 @Override
4538 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4540 "setVoWiFiRoamingModeSetting");
4541 final long identity = Binder.clearCallingIdentity();
4542 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004543 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004544 // This setting doesn't require an active ImsService connection, so do not verify. The
4545 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004546 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004547 } catch (ImsException e) {
4548 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
4552 }
4553
4554 @Override
4555 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4557 "setRttCapabilityEnabled");
4558 final long identity = Binder.clearCallingIdentity();
4559 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004560 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004561 // This setting doesn't require an active ImsService connection, so do not verify. The
4562 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004563 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004564 } catch (ImsException e) {
4565 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004566 } finally {
4567 Binder.restoreCallingIdentity(identity);
4568 }
4569 }
4570
shilu366312e2019-12-17 09:28:10 -08004571 /**
4572 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4573 * @param subId The subscription to use to check the configuration.
4574 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004575 @Override
4576 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004577 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004578 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004579 final long identity = Binder.clearCallingIdentity();
4580 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004581 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004582 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004583 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004584 } catch (ImsException e) {
4585 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 } finally {
4587 Binder.restoreCallingIdentity(identity);
4588 }
4589 }
4590
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004591 @Override
4592 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4593 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004594
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004595 final long identity = Binder.clearCallingIdentity();
4596 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004597 if (!isImsAvailableOnDevice()) {
4598 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4599 "IMS not available on device.");
4600 }
4601 int slotId = getSlotIndexOrException(subId);
4602 verifyImsMmTelConfiguredOrThrow(slotId);
4603 ImsManager.getInstance(mApp, slotId)
4604 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004605 } catch (ImsException e) {
4606 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004607 } finally {
4608 Binder.restoreCallingIdentity(identity);
4609 }
4610 }
4611
4612 @Override
4613 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4614 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004615
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004617 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4618 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4619 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004620 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004621 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004622 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004623 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004624 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4625 + "is inactive, ignoring unregister.");
4626 // If the subscription is no longer active, just return, since the callback will already
4627 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
4631 }
4632
joonhunshincffb7fc2021-11-28 07:32:01 +00004633 @Override
4634 public void registerFeatureProvisioningChangedCallback(int subId,
4635 IFeatureProvisioningCallback callback) {
4636 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4637 mApp, subId, "registerFeatureProvisioningChangedCallback");
4638
4639 final long identity = Binder.clearCallingIdentity();
4640 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4641 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4642 }
4643
4644 ImsProvisioningController.getInstance()
4645 .addFeatureProvisioningChangedCallback(subId, callback);
4646
4647 Binder.restoreCallingIdentity(identity);
4648 }
4649
4650 @Override
4651 public void unregisterFeatureProvisioningChangedCallback(int subId,
4652 IFeatureProvisioningCallback callback) {
4653 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4654 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4655
4656 final long identity = Binder.clearCallingIdentity();
4657 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4658 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4659 }
4660
4661 ImsProvisioningController.getInstance()
4662 .removeFeatureProvisioningChangedCallback(subId, callback);
4663
4664 Binder.restoreCallingIdentity(identity);
4665 }
allenwtsu99c623b2020-01-03 18:24:23 +08004666
4667 private void checkModifyPhoneStatePermission(int subId, String message) {
4668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4669 message);
4670 }
4671
4672 private boolean isImsProvisioningRequired(int subId, int capability,
4673 boolean isMmtelCapability) {
4674 Phone phone = getPhone(subId);
4675 if (phone == null) {
4676 loge("phone instance null for subid " + subId);
4677 return false;
4678 }
4679 if (isMmtelCapability) {
4680 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4681 return false;
4682 }
4683 } else {
4684 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4685 return false;
4686 }
4687 }
4688 return true;
4689 }
4690
4691 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004692 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004693 boolean isProvisioned) {
4694 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4695
4696 final long identity = Binder.clearCallingIdentity();
4697 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004698 ImsProvisioningController.getInstance()
4699 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4700 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
allenwtsu99c623b2020-01-03 18:24:23 +08004704 }
4705
4706
4707 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004708 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4709 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4710 mApp, subId, "getRcsProvisioningStatusForCapability");
4711
allenwtsu99c623b2020-01-03 18:24:23 +08004712 final long identity = Binder.clearCallingIdentity();
4713 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004714 return ImsProvisioningController.getInstance()
4715 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
4719 }
4720
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004721 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4723 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004724 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004725
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 final long identity = Binder.clearCallingIdentity();
4727 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004728 ImsProvisioningController.getInstance()
4729 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
4733 }
4734
4735 @Override
4736 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004737 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4738 mApp, subId, "getProvisioningStatusForCapability");
4739
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004742 return ImsProvisioningController.getInstance()
4743 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
4748 }
4749
4750 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004751 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4752 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4753 mApp, subId, "isProvisioningRequiredForCapability");
4754
4755 final long identity = Binder.clearCallingIdentity();
4756 try {
4757 return ImsProvisioningController.getInstance()
4758 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004761 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004762 }
4763
4764 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004765 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4766 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4767 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004768
joonhunshincffb7fc2021-11-28 07:32:01 +00004769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 return ImsProvisioningController.getInstance()
4772 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004776 }
4777
4778 private static String getMmTelProvisioningKey(int subId, int tech) {
4779 // resulting key is provision_ims_mmtel_{subId}_{tech}
4780 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4781 }
4782
4783 /**
4784 * Query CarrierConfig to see if the specified capability requires provisioning for the
4785 * carrier associated with the subscription id.
4786 */
4787 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4788 int capability) {
4789 CarrierConfigManager configManager = new CarrierConfigManager(context);
4790 PersistableBundle c = configManager.getConfigForSubId(subId);
4791 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004792 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004793 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4794 false);
4795 boolean requireVoiceVtProvisioning = c.getBoolean(
4796 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4797
4798 // First check to make sure that the capability requires provisioning.
4799 switch (capability) {
4800 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4801 // intentional fallthrough
4802 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4803 if (requireVoiceVtProvisioning) {
4804 // Voice and Video requires provisioning
4805 return true;
4806 }
4807 break;
4808 }
4809 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4810 if (requireUtProvisioning) {
4811 // UT requires provisioning
4812 return true;
4813 }
4814 break;
4815 }
4816 }
4817 return false;
4818 }
4819
allenwtsu99c623b2020-01-03 18:24:23 +08004820 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4821 int capability) {
4822 CarrierConfigManager configManager = new CarrierConfigManager(context);
4823 PersistableBundle c = configManager.getConfigForSubId(subId);
4824
4825 boolean requireRcsProvisioning = c.getBoolean(
4826 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4827
4828 // First check to make sure that the capability requires provisioning.
4829 switch (capability) {
4830 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4831 // intentional fallthrough
4832 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4833 if (requireRcsProvisioning) {
4834 // OPTION or PRESENCE requires provisioning
4835 return true;
4836 }
4837 break;
4838 }
4839 }
4840 return false;
4841 }
4842
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004843 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004844 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004845 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4846 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4847 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004848 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4849 mApp, subId, "getImsProvisioningInt");
4850
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004854 int slotId = getSlotIndex(subId);
4855 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4856 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4857 + subId + "' for key:" + key);
4858 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4859 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004860
4861 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4862 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4863 return retVal;
4864 }
4865
calvinpanb5a34062021-02-08 19:59:36 +08004866 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004867 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004868 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4869 + subId + "' for key:" + key);
4870 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
4874 }
4875
4876 @Override
4877 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004878 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4879 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4880 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004881 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4882 mApp, subId, "getImsProvisioningString");
4883
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004884 final long identity = Binder.clearCallingIdentity();
4885 try {
4886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004887 int slotId = getSlotIndex(subId);
4888 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4889 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4890 + subId + "' for key:" + key);
4891 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4892 }
calvinpanb5a34062021-02-08 19:59:36 +08004893 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004894 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004895 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4896 + subId + "' for key:" + key);
4897 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
4901 }
4902
4903 @Override
4904 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4906 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4907 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4909 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004910
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004911 final long identity = Binder.clearCallingIdentity();
4912 try {
4913 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004914 int slotId = getSlotIndex(subId);
4915 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4916 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4917 + subId + "' for key:" + key);
4918 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4919 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004920
4921 int retVal = ImsProvisioningController.getInstance()
4922 .setProvisioningValue(subId, key, value);
4923 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4924 return retVal;
4925 }
4926
calvinpanb5a34062021-02-08 19:59:36 +08004927 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4928 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004930 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
4937 @Override
4938 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4940 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4941 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4943 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 int slotId = getSlotIndex(subId);
4948 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4949 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4950 + subId + "' for key:" + key);
4951 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4952 }
calvinpanb5a34062021-02-08 19:59:36 +08004953 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4954 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004956 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
4961 }
4962
Brad Ebinger919631e2021-06-02 17:46:35 -07004963 /**
4964 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4965 * for the given slot ID or no ImsResolver instance has been created.
4966 * @param slotId The slot ID that the IMS service is created for.
4967 * @throws ImsException If there is no ImsService configured for this slot.
4968 */
4969 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4970 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4971 ImsFeature.FEATURE_MMTEL)) {
4972 throw new ImsException("This subscription does not support MMTEL over IMS",
4973 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4974 }
4975 }
4976
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004977 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004978 int slotId = SubscriptionManager.getSlotIndex(subId);
4979 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004980 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4981 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004982 }
4983 return slotId;
4984 }
4985
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004986 private int getSlotIndex(int subId) {
4987 int slotId = SubscriptionManager.getSlotIndex(subId);
4988 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4989 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4990 }
4991 return slotId;
4992 }
4993
Wink Saville36469e72014-06-11 15:17:00 -07004994 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004995 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004996 */
4997 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004998 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4999 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005000 try {
5001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5002 } catch (SecurityException se) {
5003 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5004 throw new SecurityException("Package " + callingPackage + " does not belong to "
5005 + Binder.getCallingUid());
5006 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005007 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005008 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005009 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005010 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005011 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005012 mApp, subId, callingPackage, callingFeatureId,
5013 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005014 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5015 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 final Phone phone = getPhone(subId);
5020 if (phone != null) {
5021 return phone.getServiceState().getDataNetworkType();
5022 } else {
5023 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5024 }
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005028 }
5029
5030 /**
5031 * Returns the data network type
5032 */
5033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005034 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005035 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5036 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005037 }
5038
5039 /**
5040 * Returns the data network type for a subId
5041 */
5042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005043 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5044 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005045 String functionName = "getDataNetworkTypeForSubscriber";
5046 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5047 mApp, functionName)) {
5048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5049 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5050 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5051 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005052 }
5053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 final Phone phone = getPhone(subId);
5057 if (phone != null) {
5058 return phone.getServiceState().getDataNetworkType();
5059 } else {
5060 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5061 }
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005065 }
5066
5067 /**
Wink Saville36469e72014-06-11 15:17:00 -07005068 * Returns the Voice network type for a subId
5069 */
5070 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005071 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5072 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005073 String functionName = "getVoiceNetworkTypeForSubscriber";
5074 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5075 mApp, functionName)) {
5076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5077 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5078 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5079 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005080 }
5081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 final Phone phone = getPhone(subId);
5085 if (phone != null) {
5086 return phone.getServiceState().getVoiceNetworkType();
5087 } else {
5088 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5089 }
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005093 }
5094
5095 /**
5096 * @return true if a ICC card is present
5097 */
5098 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005099 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005100 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5101 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005102 }
5103
5104 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005105 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005106 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005107 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005108 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 final Phone phone = PhoneFactory.getPhone(slotIndex);
5112 if (phone != null) {
5113 return phone.getIccCard().hasIccCard();
5114 } else {
5115 return false;
5116 }
5117 } finally {
5118 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005120 }
5121
5122 /**
5123 * Return if the current radio is LTE on CDMA. This
5124 * is a tri-state return value as for a period of time
5125 * the mode may be unknown.
5126 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005127 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005128 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005129 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005130 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005131 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005132 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5133 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5134 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005135 }
5136
Sanket Padawe356d7632015-06-22 14:03:32 -07005137 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005138 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5139 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005140 try {
5141 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5142 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005143 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5144 }
5145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 final long identity = Binder.clearCallingIdentity();
5147 try {
5148 final Phone phone = getPhone(subId);
5149 if (phone == null) {
5150 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5151 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005152 return TelephonyProperties.lte_on_cdma_device()
5153 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 }
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005157 }
Wink Saville36469e72014-06-11 15:17:00 -07005158 }
5159
Wink Saville36469e72014-06-11 15:17:00 -07005160 /**
5161 * {@hide}
5162 * Returns Default subId, 0 in the case of single standby.
5163 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005164 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005165 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005166 }
5167
Shishir Agrawala9f32182016-04-12 12:00:16 -07005168 private int getSlotForDefaultSubscription() {
5169 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5170 }
5171
Wink Savilleb564aae2014-10-23 10:18:09 -07005172 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005173 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005174 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005175
Pengquan Menge92a50d2018-09-21 15:54:48 -07005176 private boolean isActiveSubscription(int subId) {
5177 return mSubscriptionController.isActiveSubId(subId);
5178 }
5179
Ihab Awadf2177b72013-11-25 13:33:23 -08005180 /**
5181 * @see android.telephony.TelephonyManager.WifiCallingChoices
5182 */
5183 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 final long identity = Binder.clearCallingIdentity();
5185 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005186 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5188 getWhenToMakeWifiCallsDefaultPreference());
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005192 }
5193
5194 /**
5195 * @see android.telephony.TelephonyManager.WifiCallingChoices
5196 */
5197 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 final long identity = Binder.clearCallingIdentity();
5199 try {
5200 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005201 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005206 }
5207
Sailesh Nepald1e68152013-12-12 19:08:02 -08005208 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005209 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005210 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005211 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005212
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005213 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5214 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5215 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005216 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005217 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5218 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005219 }
5220 return PhoneFactory.getPhone(phoneId);
5221 }
5222
Shishir Agrawal566b7612013-10-28 14:41:00 -07005223 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005224 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005225 @NonNull IccLogicalChannelRequest request) {
5226 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5227 /*message=*/ "iccOpenLogicalChannel");
5228
5229 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5230 // Verify that the callingPackage in the request belongs to the calling UID
5231 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5232
5233 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005234 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005235
Rambo Wanga1782702021-11-10 20:15:19 -08005236 private Phone getPhoneFromValidIccLogicalChannelRequest(
5237 @NonNull IccLogicalChannelRequest request, String message) {
5238 Phone phone;
5239 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5241 mApp, request.subId, message);
5242 phone = getPhoneFromSubId(request.subId);
5243 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5244 enforceModifyPermission();
5245 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5246 } else {
5247 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005248 }
Rambo Wanga1782702021-11-10 20:15:19 -08005249 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005250 }
5251
5252 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005253 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 final long identity = Binder.clearCallingIdentity();
5255 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005256 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005258 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5259 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005260 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5261 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 loge("The calling package is not allowed to access ISD-R.");
5263 throw new SecurityException(
5264 "The calling package is not allowed to access ISD-R.");
5265 }
Derek Tan740e1672017-06-27 14:56:27 -07005266 }
Derek Tan740e1672017-06-27 14:56:27 -07005267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005269 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5270 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 return response;
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
5274 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005275 }
5276
5277 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005278 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5279 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5280 /*message=*/"iccCloseLogicalChannel");
5281
5282 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5283
5284 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005285 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005286
Rambo Wanga1782702021-11-10 20:15:19 -08005287 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5288 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005289 // before this feature is enabled, this API should only return false if
5290 // the operation fails instead of throwing runtime exception for
5291 // backward-compatibility.
5292 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5293 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 final long identity = Binder.clearCallingIdentity();
5295 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005296 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005297 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 }
Chen Xue9d737e2022-01-01 23:41:31 -08005299 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005300 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005301 Boolean success = false;
5302 if (result instanceof RuntimeException) {
5303 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005304 if (shouldThrowExceptionOnFailure) {
5305 throw (RuntimeException) result;
5306 } else {
5307 return false;
5308 }
Chen Xue9d737e2022-01-01 23:41:31 -08005309 } else if (result instanceof Boolean) {
5310 success = (Boolean) result;
5311 } else {
5312 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5313 }
Rambo Wanga1782702021-11-10 20:15:19 -08005314 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 return success;
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005318 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005319 }
5320
5321 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005322 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005323 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5325 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005326 if (DBG) {
5327 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5328 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5329 + p3 + " data=" + data);
5330 }
5331 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5332 command, p1, p2, p3, data);
5333 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005334
Jordan Liu4c733742019-02-28 12:03:40 -08005335 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005336 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5337 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005338 enforceModifyPermission();
5339 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005340 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5341 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5342 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005343 }
5344 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005345 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5346 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005347 }
5348
5349 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5350 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 final long identity = Binder.clearCallingIdentity();
5352 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005353 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 return "";
5355 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005358 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5359 null /* workSource */);
5360 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 // Append the returned status code to the end of the response payload.
5363 String s = Integer.toHexString(
5364 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5365 if (response.payload != null) {
5366 s = IccUtils.bytesToHexString(response.payload) + s;
5367 }
5368 return s;
5369 } finally {
5370 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005371 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005372 }
Jake Hambye994d462014-02-03 13:10:13 -08005373
Evan Charltonc66da362014-05-16 14:06:40 -07005374 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005375 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5376 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5378 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005380 if (DBG) {
5381 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5382 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5383 }
5384 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5385 cla, command, p1, p2, p3, data);
5386 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005387
Jordan Liu4c733742019-02-28 12:03:40 -08005388 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005389 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5390 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005391 enforceModifyPermission();
5392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5393 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005394 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5395 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5396 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005397 }
5398
5399 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005400 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5401 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005402 }
5403
5404 // open APDU basic channel assuming the caller has sufficient permissions
5405 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5406 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 final long identity = Binder.clearCallingIdentity();
5408 try {
5409 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5410 && TextUtils.equals(ISDR_AID, data)) {
5411 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005412 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5413 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 if (bestComponent == null
5415 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5416 loge("The calling package is not allowed to select ISD-R.");
5417 throw new SecurityException(
5418 "The calling package is not allowed to select ISD-R.");
5419 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005420 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005423 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5424 null /* workSource */);
5425 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 // Append the returned status code to the end of the response payload.
5428 String s = Integer.toHexString(
5429 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5430 if (response.payload != null) {
5431 s = IccUtils.bytesToHexString(response.payload) + s;
5432 }
5433 return s;
5434 } finally {
5435 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005436 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005437 }
5438
5439 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005440 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005441 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5443 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 final long identity = Binder.clearCallingIdentity();
5446 try {
5447 if (DBG) {
5448 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5449 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5450 }
5451
5452 IccIoResult response =
5453 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5454 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5455 subId);
5456
5457 if (DBG) {
5458 log("Exchange SIM_IO [R]" + response);
5459 }
5460
5461 byte[] result = null;
5462 int length = 2;
5463 if (response.payload != null) {
5464 length = 2 + response.payload.length;
5465 result = new byte[length];
5466 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5467 } else {
5468 result = new byte[length];
5469 }
5470
5471 result[length - 1] = (byte) response.sw2;
5472 result[length - 2] = (byte) response.sw1;
5473 return result;
5474 } finally {
5475 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005476 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005477 }
5478
Nathan Haroldb3014052017-01-25 15:57:32 -08005479 /**
5480 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5481 * on a particular subscription
5482 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005483 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5484 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005486 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005487 return null;
5488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 if (appType != TelephonyManager.APPTYPE_USIM
5493 && appType != TelephonyManager.APPTYPE_SIM) {
5494 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5495 return null;
5496 }
5497 Object response = sendRequest(
5498 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5499 if (response instanceof String[]) {
5500 return (String[]) response;
5501 }
yincheng zhao2737e882019-09-06 17:06:54 -07005502 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005504 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 } finally {
5506 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005507 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005508 }
5509
yincheng zhao2737e882019-09-06 17:06:54 -07005510 /**
5511 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5512 * subscription.
5513 *
5514 * @param subId the id of the subscription.
5515 * @param appType the uicc app type, must be USIM or SIM.
5516 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5517 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005518 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005519 * @return number of fplmns that is successfully written to the SIM.
5520 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005521 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5522 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5524 mApp, subId, "setForbiddenPlmns");
5525
yincheng zhao2737e882019-09-06 17:06:54 -07005526 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5527 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5528 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5529 }
5530 if (fplmns == null) {
5531 throw new IllegalArgumentException("Fplmn List provided is null");
5532 }
5533 for (String fplmn : fplmns) {
5534 if (!CellIdentity.isValidPlmn(fplmn)) {
5535 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5536 }
5537 }
5538 final long identity = Binder.clearCallingIdentity();
5539 try {
5540 Object response = sendRequest(
5541 CMD_SET_FORBIDDEN_PLMNS,
5542 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5543 subId);
5544 return (int) response;
5545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
5548 }
5549
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005550 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005551 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5558 if (response.payload == null) {
5559 return "";
5560 }
Evan Charltonc66da362014-05-16 14:06:40 -07005561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 // Append the returned status code to the end of the response payload.
5563 String s = Integer.toHexString(
5564 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5565 s = IccUtils.bytesToHexString(response.payload) + s;
5566 return s;
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
Evan Charltonc66da362014-05-16 14:06:40 -07005570 }
5571
Jake Hambye994d462014-02-03 13:10:13 -08005572 /**
5573 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5574 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5575 *
5576 * @param itemID the ID of the item to read
5577 * @return the NV item as a String, or null on error.
5578 */
5579 @Override
5580 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005581 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5583 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584
5585 final long identity = Binder.clearCallingIdentity();
5586 try {
5587 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005588 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5590 return value;
5591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Jake Hambye994d462014-02-03 13:10:13 -08005594 }
5595
5596 /**
5597 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5598 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5599 *
5600 * @param itemID the ID of the item to read
5601 * @param itemValue the value to write, as a String
5602 * @return true on success; false on any failure
5603 */
5604 @Override
5605 public boolean nvWriteItem(int itemID, String itemValue) {
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(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609
5610 final long identity = Binder.clearCallingIdentity();
5611 try {
5612 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5613 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005614 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5616 return success;
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Jake Hambye994d462014-02-03 13:10:13 -08005620 }
5621
5622 /**
5623 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5624 * Used for device configuration by some CDMA operators.
5625 *
5626 * @param preferredRoamingList byte array containing the new PRL
5627 * @return true on success; false on any failure
5628 */
5629 @Override
5630 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5632 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5637 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5638 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5639 return success;
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Jake Hambye994d462014-02-03 13:10:13 -08005643 }
5644
5645 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005646 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005647 * Used for device configuration by some CDMA operators.
5648 *
chen xu6dac5ab2018-10-26 17:39:23 -07005649 * @param slotIndex - device slot.
5650 *
Jake Hambye994d462014-02-03 13:10:13 -08005651 * @return true on success; false on any failure
5652 */
5653 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005654 public boolean resetModemConfig(int slotIndex) {
5655 Phone phone = PhoneFactory.getPhone(slotIndex);
5656 if (phone != null) {
5657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
chen xu6dac5ab2018-10-26 17:39:23 -07005660 final long identity = Binder.clearCallingIdentity();
5661 try {
5662 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5663 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5664 return success;
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 }
chen xu6dac5ab2018-10-26 17:39:23 -07005669 return false;
5670 }
5671
5672 /**
5673 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5674 *
5675 * @param slotIndex - device slot.
5676 *
5677 * @return true on success; false on any failure
5678 */
5679 @Override
5680 public boolean rebootModem(int slotIndex) {
5681 Phone phone = PhoneFactory.getPhone(slotIndex);
5682 if (phone != null) {
5683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5684 mApp, phone.getSubId(), "rebootModem");
5685
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5689 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5690 return success;
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
5694 }
5695 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005696 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005697
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005698 public String[] getPcscfAddress(String apnType, String callingPackage,
5699 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005700 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5702 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005703 return new String[0];
5704 }
5705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 final long identity = Binder.clearCallingIdentity();
5707 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005708 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Wink Saville36469e72014-06-11 15:17:00 -07005712 }
5713
Brad Ebinger51f743a2017-01-23 13:50:20 -08005714 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005715 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5716 * {@link #disableIms(int)}.
5717 * @param slotIndex device slot.
5718 */
5719 public void resetIms(int slotIndex) {
5720 enforceModifyPermission();
5721
5722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 if (mImsResolver == null) {
5725 // may happen if the does not support IMS.
5726 return;
5727 }
5728 mImsResolver.disableIms(slotIndex);
5729 mImsResolver.enableIms(slotIndex);
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
5733 }
5734
5735 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005736 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5737 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005738 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005744 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005745 // may happen if the device does not support IMS.
5746 return;
5747 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005748 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005752 }
5753
5754 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005755 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5756 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005757 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005758 public void disableIms(int slotId) {
5759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760
5761 final long identity = Binder.clearCallingIdentity();
5762 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005763 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005764 // may happen if the device does not support IMS.
5765 return;
5766 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005767 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005771 }
5772
5773 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005774 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5775 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005776 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005777 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005778 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005783 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005784 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5785 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005786 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005787 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005791 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005792 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005793 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5794 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005795 @Override
5796 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005797 enforceModifyPermission();
5798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005802 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005803 } finally {
5804 Binder.restoreCallingIdentity(identity);
5805 }
5806 }
5807
5808 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005809 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005810 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005811 */
5812 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005818 // may happen if the device does not support IMS.
5819 return null;
5820 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 } finally {
5823 Binder.restoreCallingIdentity(identity);
5824 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005825 }
5826
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005827 /**
5828 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005829 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005830 */
5831 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005836 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005837 // may happen if the device does not support IMS.
5838 return null;
5839 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005844 }
5845
Brad Ebinger884c07b2018-02-15 16:17:40 -08005846 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005847 * Sets the ImsService Package Name that Telephony will bind to.
5848 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005849 * @param slotIndex the slot ID that the ImsService should bind for.
5850 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005851 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 * @param featureTypes An integer array of feature types associated with a packageName.
5853 * @param packageName The name of the package that the current configuration will be replaced
5854 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005855 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005856 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5858 int[] featureTypes, String packageName) {
5859 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5860 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5862 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 final long identity = Binder.clearCallingIdentity();
5866 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005868 // may happen if the device does not support IMS.
5869 return false;
5870 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 Map<Integer, String> featureConfig = new HashMap<>();
5872 for (int featureType : featureTypes) {
5873 featureConfig.put(featureType, packageName);
5874 }
5875 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5876 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005880 }
5881
5882 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005883 * Clears any carrier ImsService overrides for the slot index specified that were previously
5884 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5885 *
5886 * This should only be used for testing.
5887 *
5888 * @param slotIndex the slot ID that the ImsService should bind for.
5889 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5890 */
5891 @Override
5892 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5893 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5895 "clearCarrierImsServiceOverride");
5896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5897 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5898 "clearCarrierImsServiceOverride");
5899
5900 final long identity = Binder.clearCallingIdentity();
5901 try {
5902 if (mImsResolver == null) {
5903 // may happen if the device does not support IMS.
5904 return false;
5905 }
5906 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
5910 }
5911
5912 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005913 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005914 *
5915 * @param slotId The slot that the ImsService is associated with.
5916 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5917 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005918 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005919 * @return the package name of the ImsService configuration.
5920 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005921 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5922 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005923 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005925 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005926 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5927 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 final long identity = Binder.clearCallingIdentity();
5930 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005932 // may happen if the device does not support IMS.
5933 return "";
5934 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005935 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5937 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 } finally {
5939 Binder.restoreCallingIdentity(identity);
5940 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005941 }
5942
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005943 /**
5944 * Get the MmTelFeature state associated with the requested subscription id.
5945 * @param subId The subscription that the MmTelFeature is associated with.
5946 * @param callback A callback with an integer containing the
5947 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5948 */
5949 @Override
5950 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5951 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005952 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5953 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5954 "IMS not available on device.");
5955 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005956 final long token = Binder.clearCallingIdentity();
5957 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005958 int slotId = getSlotIndex(subId);
5959 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5960 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5961 + subId + "'");
5962 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5963 }
5964 verifyImsMmTelConfiguredOrThrow(slotId);
5965 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5966 try {
5967 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5968 } catch (RemoteException e) {
5969 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5970 + "Ignore");
5971 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005972 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005973 } catch (ImsException e) {
5974 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005975 } finally {
5976 Binder.restoreCallingIdentity(token);
5977 }
5978 }
5979
Daniel Brightbb5840b2021-01-12 15:48:18 -08005980 /**
5981 * Sets the ims registration state on all valid {@link Phone}s.
5982 */
5983 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985
5986 final long identity = Binder.clearCallingIdentity();
5987 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005988 // NOTE: Before S, this method only set the default phone.
5989 for (final Phone phone : PhoneFactory.getPhones()) {
5990 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5991 phone.setImsRegistrationState(registered);
5992 }
5993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Wink Saville36469e72014-06-11 15:17:00 -07005997 }
5998
5999 /**
Stuart Scott54788802015-03-30 13:18:01 -07006000 * Set the network selection mode to automatic.
6001 *
6002 */
6003 @Override
6004 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6006 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007
6008 final long identity = Binder.clearCallingIdentity();
6009 try {
shilufc958392020-01-20 11:36:01 -08006010 if (!isActiveSubscription(subId)) {
6011 return;
6012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006014 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6015 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
Stuart Scott54788802015-03-30 13:18:01 -07006019 }
6020
Jack Yud10cdd42020-09-28 20:28:01 -07006021 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006022 * Ask the radio to connect to the input network and change selection mode to manual.
6023 *
6024 * @param subId the id of the subscription.
6025 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6026 * the operator to attach to.
6027 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6028 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6029 * normal network selection next time.
6030 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006031 */
6032 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006033 public boolean setNetworkSelectionModeManual(
6034 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6036 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006037
6038 if (!isActiveSubscription(subId)) {
6039 return false;
6040 }
6041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 final long identity = Binder.clearCallingIdentity();
6043 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006044 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006046 if (DBG) {
6047 log("setNetworkSelectionModeManual: subId: " + subId
6048 + " operator: " + operatorInfo);
6049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6051 } finally {
6052 Binder.restoreCallingIdentity(identity);
6053 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006054 }
shilu84f6e8b2019-12-19 13:58:01 -08006055 /**
6056 * Get the manual network selection
6057 *
6058 * @param subId the id of the subscription.
6059 *
6060 * @return the previously saved user selected PLMN
6061 */
6062 @Override
6063 public String getManualNetworkSelectionPlmn(int subId) {
6064 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006065 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006066 mApp, subId, "getManualNetworkSelectionPlmn");
6067
6068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006071 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006072 }
6073
6074 final Phone phone = getPhone(subId);
6075 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006076 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006077 }
6078 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6079 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6080 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
6084 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006085
6086 /**
6087 * Scans for available networks.
6088 */
6089 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006090 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6091 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6093 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006094 LocationAccessPolicy.LocationPermissionResult locationResult =
6095 LocationAccessPolicy.checkLocationPermission(mApp,
6096 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6097 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006098 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006099 .setCallingPid(Binder.getCallingPid())
6100 .setCallingUid(Binder.getCallingUid())
6101 .setMethod("getCellNetworkScanResults")
6102 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006103 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6104 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006105 .build());
6106 switch (locationResult) {
6107 case DENIED_HARD:
6108 throw new SecurityException("Not allowed to access scan results -- location");
6109 case DENIED_SOFT:
6110 return null;
6111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112
Pengquan Menga1bb6272018-09-06 09:59:22 -07006113 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 try {
6115 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006116 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006121 }
6122
6123 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006124 * Get the call forwarding info, given the call forwarding reason.
6125 */
6126 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006127 public void getCallForwarding(int subId, int callForwardingReason,
6128 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006129 enforceReadPrivilegedPermission("getCallForwarding");
6130 long identity = Binder.clearCallingIdentity();
6131 try {
6132 if (DBG) {
6133 log("getCallForwarding: subId " + subId
6134 + " callForwardingReason" + callForwardingReason);
6135 }
Hall Liu27d24262020-09-18 19:04:59 -07006136
6137 Phone phone = getPhone(subId);
6138 if (phone == null) {
6139 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006140 callback.onError(
6141 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006142 } catch (RemoteException e) {
6143 // ignore
6144 }
6145 return;
6146 }
6147
6148 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6149 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6150 @Override
6151 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6152 try {
6153 callback.onCallForwardingInfoAvailable(info);
6154 } catch (RemoteException e) {
6155 // ignore
6156 }
6157 }
6158
6159 @Override
6160 public void onError(int error) {
6161 try {
6162 callback.onError(error);
6163 } catch (RemoteException e) {
6164 // ignore
6165 }
6166 }
6167 });
6168 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
6172 }
6173
6174 /**
6175 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6176 * reason, the number to forward, and the timeout before the forwarding is attempted.
6177 */
6178 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006179 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6180 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006181 enforceModifyPermission();
6182 long identity = Binder.clearCallingIdentity();
6183 try {
6184 if (DBG) {
6185 log("setCallForwarding: subId " + subId
6186 + " callForwardingInfo" + callForwardingInfo);
6187 }
Hall Liu27d24262020-09-18 19:04:59 -07006188
6189 Phone phone = getPhone(subId);
6190 if (phone == null) {
6191 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006192 callback.accept(
6193 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006194 } catch (RemoteException e) {
6195 // ignore
6196 }
6197 return;
6198 }
6199
6200 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6201 FunctionalUtils.ignoreRemoteException(callback::accept));
6202
6203 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006204 } finally {
6205 Binder.restoreCallingIdentity(identity);
6206 }
6207 }
6208
6209 /**
Hall Liu27d24262020-09-18 19:04:59 -07006210 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006211 */
6212 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006213 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006214 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006215 long identity = Binder.clearCallingIdentity();
6216 try {
Hall Liu27d24262020-09-18 19:04:59 -07006217 Phone phone = getPhone(subId);
6218 if (phone == null) {
6219 try {
6220 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6221 } catch (RemoteException e) {
6222 // ignore
6223 }
6224 return;
6225 }
SongFerngWang0e767992021-03-31 22:08:45 +08006226 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6227 PersistableBundle c = configManager.getConfigForSubId(subId);
6228 boolean requireUssd = c.getBoolean(
6229 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006230
Shuo Qian4a594052020-01-23 11:59:30 -08006231 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006232 if (requireUssd) {
6233 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6234 getSubscriptionCarrierId(subId));
6235 String newUssdCommand = "";
6236 try {
6237 newUssdCommand = carrierXmlParser.getFeature(
6238 CarrierXmlParser.FEATURE_CALL_WAITING)
6239 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6240 } catch (NullPointerException e) {
6241 loge("Failed to generate USSD number" + e);
6242 }
6243 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6244 mMainThreadHandler, callback, carrierXmlParser,
6245 CarrierXmlParser.SsEntry.SSAction.QUERY);
6246 final String ussdCommand = newUssdCommand;
6247 Executors.newSingleThreadExecutor().execute(() -> {
6248 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6249 });
6250 } else {
6251 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6252 callback::accept);
6253 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6254 }
Shuo Qian4a594052020-01-23 11:59:30 -08006255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
6258 }
6259
6260 /**
Hall Liu27d24262020-09-18 19:04:59 -07006261 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006262 */
6263 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006264 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006265 enforceModifyPermission();
6266 long identity = Binder.clearCallingIdentity();
6267 try {
Hall Liu27d24262020-09-18 19:04:59 -07006268 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6269
6270 Phone phone = getPhone(subId);
6271 if (phone == null) {
6272 try {
6273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6274 } catch (RemoteException e) {
6275 // ignore
6276 }
6277 return;
6278 }
6279
SongFerngWang0e767992021-03-31 22:08:45 +08006280 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6281 PersistableBundle c = configManager.getConfigForSubId(subId);
6282 boolean requireUssd = c.getBoolean(
6283 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006284
SongFerngWang0e767992021-03-31 22:08:45 +08006285 if (DBG) log("getCallWaitingStatus: subId " + subId);
6286 if (requireUssd) {
6287 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6288 getSubscriptionCarrierId(subId));
6289 CarrierXmlParser.SsEntry.SSAction ssAction =
6290 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6291 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6292 String newUssdCommand = "";
6293 try {
6294 newUssdCommand = carrierXmlParser.getFeature(
6295 CarrierXmlParser.FEATURE_CALL_WAITING)
6296 .makeCommand(ssAction, null);
6297 } catch (NullPointerException e) {
6298 loge("Failed to generate USSD number" + e);
6299 }
6300 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6301 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6302 final String ussdCommand = newUssdCommand;
6303 Executors.newSingleThreadExecutor().execute(() -> {
6304 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6305 });
6306 } else {
6307 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6308 FunctionalUtils.ignoreRemoteException(callback::accept));
6309
6310 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6311 }
Shuo Qian4a594052020-01-23 11:59:30 -08006312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
6315 }
6316
6317 /**
yinxub1bed742017-04-17 11:45:04 -07006318 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006319 *
yinxub1bed742017-04-17 11:45:04 -07006320 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006321 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6322 * location related information which will be sent if the caller already possess
6323 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006324 * @param request contains the radio access networks with bands/channels to scan
6325 * @param messenger callback messenger for scan results or errors
6326 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006327 * @return the id of the requested scan which can be used to stop the scan.
6328 */
6329 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006330 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6331 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006332 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6334 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006335 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006336 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6337 if (!renounceFineLocationAccess) {
6338 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6339 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6340 .setCallingPackage(callingPackage)
6341 .setCallingFeatureId(callingFeatureId)
6342 .setCallingPid(Binder.getCallingPid())
6343 .setCallingUid(Binder.getCallingUid())
6344 .setMethod("requestNetworkScan")
6345 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6346 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6347 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6348 .build());
6349 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006350 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006351 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6352 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 if (e != null) {
6354 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6355 throw e;
6356 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006357 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006358 return TelephonyScanManager.INVALID_SCAN_ID;
6359 }
6360 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361 }
Hall Liu912dfd32019-04-25 14:02:26 -07006362 int callingUid = Binder.getCallingUid();
6363 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006367 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006368 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
yinxu504e1392017-04-12 16:03:22 -07006372 }
6373
Hall Liub2ac8ef2019-02-28 15:56:23 -08006374 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006375 NetworkScanRequest request, int subId, String callingPackage) {
6376 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006377 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6378 boolean hasNetworkScanPermission =
6379 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6380 == PERMISSION_GRANTED;
6381
6382 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6383 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6384 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006385 }
6386
6387 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6388 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006389 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6390 return new SecurityException("Specific channels must not be"
6391 + " scanned without location access.");
6392 }
6393 }
6394 }
6395
Hall Liub2ac8ef2019-02-28 15:56:23 -08006396 return null;
6397 }
6398
yinxu504e1392017-04-12 16:03:22 -07006399 /**
6400 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006401 *
6402 * @param subId id of the subscription
6403 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006404 */
6405 @Override
6406 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6408 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
Hall Liu912dfd32019-04-25 14:02:26 -07006410 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 final long identity = Binder.clearCallingIdentity();
6412 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006413 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
yinxu504e1392017-04-12 16:03:22 -07006417 }
6418
6419 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006420 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006421 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006422 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006423 */
6424 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006425 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006426 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006427 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006432 if (DBG) log("getAllowedNetworkTypesBitmask");
6433 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6434 int networkTypesBitmask = (result != null ? result[0] : -1);
6435 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6436 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006440 }
6441
6442 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006443 * Get the allowed network types for certain reason.
6444 *
6445 * @param subId the id of the subscription.
6446 * @param reason the reason the allowed network type change is taking place
6447 * @return the allowed network types.
6448 */
6449 @Override
6450 public long getAllowedNetworkTypesForReason(int subId,
6451 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006452 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006453 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
6460 }
6461
6462 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006463 * Enable/Disable E-UTRA-NR Dual Connectivity
6464 * @param subId subscription id of the sim card
6465 * @param nrDualConnectivityState expected NR dual connectivity state
6466 * This can be passed following states
6467 * <ol>
6468 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6469 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6470 * <li>Disable NR dual connectivity and force secondary cell to be released
6471 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6472 * </ol>
6473 * @return operation result.
6474 */
6475 @Override
6476 public int setNrDualConnectivityState(int subId,
6477 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6479 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006480 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006481 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6482 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6483 }
6484
Sooraj Sasindran37444802020-08-11 10:40:43 -07006485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6486 final long identity = Binder.clearCallingIdentity();
6487 try {
6488 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6489 nrDualConnectivityState, subId,
6490 workSource);
6491 if (DBG) log("enableNRDualConnectivity result: " + result);
6492 return result;
6493 } finally {
6494 Binder.restoreCallingIdentity(identity);
6495 }
6496 }
6497
6498 /**
6499 * Is E-UTRA-NR Dual Connectivity enabled
6500 * @return true if dual connectivity is enabled else false
6501 */
6502 @Override
6503 public boolean isNrDualConnectivityEnabled(int subId) {
6504 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006505 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006506 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006507 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006508 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6509 return false;
6510 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6512 final long identity = Binder.clearCallingIdentity();
6513 try {
6514 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6515 null, subId, workSource);
6516 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6517 return isEnabled;
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
6520 }
6521 }
6522
6523 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006524 * Set the allowed network types of the device and
6525 * provide the reason triggering the allowed network change.
6526 *
6527 * @param subId the id of the subscription.
6528 * @param reason the reason the allowed network type change is taking place
6529 * @param allowedNetworkTypes the allowed network types.
6530 * @return true on success; false on any failure.
6531 */
6532 @Override
6533 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006534 @TelephonyManager.AllowedNetworkTypesReason int reason,
6535 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6537 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006538 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006539 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6540 return false;
6541 }
6542 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6543 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006544 return false;
6545 }
6546
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006547 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6548 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6549
6550
6551 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6552 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6553 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006555
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006556 final long identity = Binder.clearCallingIdentity();
6557 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006558 Boolean success = (Boolean) sendRequest(
6559 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6560 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6561
6562 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6563 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
6567 }
6568
6569 /**
Miaoa84611c2019-03-15 09:21:10 +08006570 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006571 *
Miaoa84611c2019-03-15 09:21:10 +08006572 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006573 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006574 * @hide
6575 */
6576 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006577 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006580 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 try {
Miaoa84611c2019-03-15 09:21:10 +08006582 if (phone != null) {
6583 return phone.hasMatchedTetherApnSetting();
6584 } else {
6585 return false;
6586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 } finally {
6588 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006589 }
Junda Liu475951f2014-11-07 16:45:03 -08006590 }
6591
6592 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006593 * Get the user enabled state of Mobile Data.
6594 *
6595 * TODO: remove and use isUserDataEnabled.
6596 * This can't be removed now because some vendor codes
6597 * calls through ITelephony directly while they should
6598 * use TelephonyManager.
6599 *
6600 * @return true on enabled
6601 */
6602 @Override
6603 public boolean getDataEnabled(int subId) {
6604 return isUserDataEnabled(subId);
6605 }
6606
6607 /**
6608 * Get whether mobile data is enabled per user setting.
6609 *
6610 * There are other factors deciding whether mobile data is actually enabled, but they are
6611 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006612 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006613 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6614 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006615 *
6616 * @return {@code true} if data is enabled else {@code false}
6617 */
6618 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006619 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006620 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006621 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006622 try {
6623 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6624 functionName);
6625 } catch (Exception e) {
6626 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6627 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006628 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006630 mApp, subId, functionName);
6631
Robert Greenwalt646120a2014-05-23 11:54:03 -07006632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 int phoneId = mSubscriptionController.getPhoneId(subId);
6637 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6638 Phone phone = PhoneFactory.getPhone(phoneId);
6639 if (phone != null) {
6640 boolean retVal = phone.isUserDataEnabled();
6641 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6642 return retVal;
6643 } else {
6644 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6645 return false;
6646 }
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006649 }
6650 }
6651
6652 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006653 * Checks if the device is capable of mobile data by considering whether whether the
6654 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6655 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006656 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006657 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006658 */
6659 @Override
6660 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006661 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006662 try {
6663 try {
6664 mApp.enforceCallingOrSelfPermission(
6665 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006666 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006667 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006668 try {
6669 mApp.enforceCallingOrSelfPermission(
6670 android.Manifest.permission.READ_PHONE_STATE,
6671 functionName);
6672 } catch (Exception e2) {
6673 mApp.enforceCallingOrSelfPermission(
6674 permission.READ_BASIC_PHONE_STATE, functionName);
6675 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006676 }
6677 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006678 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680
6681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 Phone phone = PhoneFactory.getPhone(phoneId);
6685 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006686 boolean retVal;
6687 if (phone.isUsingNewDataStack()) {
Sarah Chin2c094c52022-03-09 13:57:52 -08006688 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006689 } else {
6690 retVal = phone.getDataEnabledSettings().isDataEnabled();
6691 }
6692 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 return retVal;
6694 } else {
6695 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6696 return false;
6697 }
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006700 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006701 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006702
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006703 /**
6704 * Check if data is enabled for a specific reason
6705 * @param subId Subscription index
6706 * @param reason the reason the data enable change is taking place
6707 * @return {@code true} if the overall data is enabled; {@code false} if not.
6708 */
6709 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006710 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006711 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006712 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006713 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006714 try {
6715 mApp.enforceCallingOrSelfPermission(
6716 android.Manifest.permission.ACCESS_NETWORK_STATE,
6717 functionName);
6718 } catch (Exception e) {
6719 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6720 functionName);
6721 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006722 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006723 try {
6724 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006725 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006726 } catch (Exception e2) {
6727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006728 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006729 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 }
6731
6732
6733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 int phoneId = mSubscriptionController.getPhoneId(subId);
6736 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006737 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 + " reason=" + reason);
6739 }
6740 Phone phone = PhoneFactory.getPhone(phoneId);
6741 if (phone != null) {
6742 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006743 if (phone.isUsingNewDataStack()) {
6744 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006745 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006746 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6747 retVal = phone.isUserDataEnabled();
6748 } else {
6749 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6750 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006751 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006752 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006753 return retVal;
6754 } else {
6755 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006756 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006757 + subId + " retVal=false");
6758 }
6759 return false;
6760 }
6761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
6764 }
6765
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006766 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006767 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006768 if (uid == Process.PHONE_UID) {
6769 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6770 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6772 }
6773
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006774 //load access rules from carrier configs, and check those as well: b/139133814
6775 SubscriptionController subController = SubscriptionController.getInstance();
6776 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6777 || subController == null) return privilegeFromSim;
6778
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006779 PackageManager pkgMgr = phone.getContext().getPackageManager();
6780 String[] packages = pkgMgr.getPackagesForUid(uid);
6781
6782 final long identity = Binder.clearCallingIdentity();
6783 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006784 int subId = phone.getSubId();
6785 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6786 // A test override is in place for the privileges for this subId, so don't try to
6787 // read the subscription privileges.
6788 return privilegeFromSim;
6789 }
6790 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006791 SubscriptionManager subManager = (SubscriptionManager)
6792 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6793 for (String pkg : packages) {
6794 if (subManager.canManageSubscription(subInfo, pkg)) {
6795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6796 }
6797 }
6798 return privilegeFromSim;
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
6802 }
6803
6804 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6805 String pkgName) {
6806 //load access rules from carrier configs, and check those as well: b/139133814
6807 SubscriptionController subController = SubscriptionController.getInstance();
6808 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6809 || subController == null) return privilegeFromSim;
6810
6811 final long identity = Binder.clearCallingIdentity();
6812 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006813 int subId = phone.getSubId();
6814 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6815 // A test override is in place for the privileges for this subId, so don't try to
6816 // read the subscription privileges.
6817 return privilegeFromSim;
6818 }
6819 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006820 SubscriptionManager subManager = (SubscriptionManager)
6821 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6822 return subManager.canManageSubscription(subInfo, pkgName)
6823 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
6826 }
6827 }
6828
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006829 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006830 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006831 // No permission needed; this only lets the caller inspect their own status.
6832 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006833 }
Junda Liu29340342014-07-10 15:23:27 -07006834
6835 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006836 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006837 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006838 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6839 }
6840
6841 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6842 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006843 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006844 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6846 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006847 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6848 if (cpt == null) {
6849 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6851 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006852 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006853 }
6854
6855 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006856 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006857 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006858 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006859 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006860 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006861 Phone phone = getPhone(subId);
6862 if (phone == null) {
6863 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6865 }
6866 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6867 if (cpt == null) {
6868 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6870 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006871 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006872 }
6873
6874 @Override
6875 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006876 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006877 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6878 }
6879
6880 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006881 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006882 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006883 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006884 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006885 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6886 Phone phone = PhoneFactory.getPhone(phoneId);
6887 if (phone == null) {
6888 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006889 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006890 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6891 if (cpt == null) {
6892 continue;
6893 }
6894 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006895 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6896 break;
6897 }
6898 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006899 return result;
Junda Liu29340342014-07-10 15:23:27 -07006900 }
Derek Tan89e89d42014-07-08 17:00:10 -07006901
6902 @Override
Junda Liue64de782015-04-16 17:19:16 -07006903 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006904 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006905 Phone phone = PhoneFactory.getPhone(phoneId);
6906 if (phone == null) {
6907 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006908 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006909 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6910 if (cpt == null) {
6911 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006912 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006913 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006914 }
6915
Amith Yamasani6e118872016-02-19 12:53:51 -08006916 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006917 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006918 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006919 Phone phone = PhoneFactory.getPhone(phoneId);
6920 if (phone == null) {
6921 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006922 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006923 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6924 if (cpt == null) {
6925 return Collections.emptyList();
6926 }
6927 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006928 }
6929
chen xuf7e9fe82019-05-09 19:31:02 -07006930 @Override
6931 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006932 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006933 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006934 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006935 try {
6936 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6937 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6938 }
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006941 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006942 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006943 }
6944
Wink Savilleb564aae2014-10-23 10:18:09 -07006945 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006946 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006947 UiccPort port = phone == null ? null : phone.getUiccPort();
6948 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006949 return null;
6950 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006951 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006952 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006953 return null;
6954 }
6955 return iccId;
6956 }
6957
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006958 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006959 public void setCallComposerStatus(int subId, int status) {
6960 enforceModifyPermission();
6961
6962 final long identity = Binder.clearCallingIdentity();
6963 try {
6964 Phone phone = getPhone(subId);
6965 if (phone != null) {
6966 Phone defaultPhone = phone.getImsPhone();
6967 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6968 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6969 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006970 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6971 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006972 }
6973 }
Shuo Qian284ae752020-12-22 19:10:14 -08006974 } catch (ImsException e) {
6975 throw new ServiceSpecificException(e.getCode());
6976 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006977 Binder.restoreCallingIdentity(identity);
6978 }
6979 }
6980
6981 @Override
6982 public int getCallComposerStatus(int subId) {
6983 enforceReadPrivilegedPermission("getCallComposerStatus");
6984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 Phone phone = getPhone(subId);
6988 if (phone != null) {
6989 Phone defaultPhone = phone.getImsPhone();
6990 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6991 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6992 return imsPhone.getCallComposerStatus();
6993 }
6994 }
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
6997 }
6998 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6999 }
7000
7001 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007002 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7003 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007004 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007005 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 final long identity = Binder.clearCallingIdentity();
7008 try {
7009 final String iccId = getIccId(subId);
7010 final Phone phone = getPhone(subId);
7011 if (phone == null) {
7012 return false;
7013 }
7014 final String subscriberId = phone.getSubscriberId();
7015
7016 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007017 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 + subscriberId + " to " + number);
7019 }
7020
7021 if (TextUtils.isEmpty(iccId)) {
7022 return false;
7023 }
7024
7025 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7026
7027 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7028 if (alphaTag == null) {
7029 editor.remove(alphaTagPrefKey);
7030 } else {
7031 editor.putString(alphaTagPrefKey, alphaTag);
7032 }
7033
7034 // Record both the line number and IMSI for this ICCID, since we need to
7035 // track all merged IMSIs based on line number
7036 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7037 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7038 if (number == null) {
7039 editor.remove(numberPrefKey);
7040 editor.remove(subscriberPrefKey);
7041 } else {
7042 editor.putString(numberPrefKey, number);
7043 editor.putString(subscriberPrefKey, subscriberId);
7044 }
7045
7046 editor.commit();
7047 return true;
7048 } finally {
7049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007050 }
Derek Tan7226c842014-07-02 17:42:23 -07007051 }
7052
7053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007054 public String getLine1NumberForDisplay(int subId, String callingPackage,
7055 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007056 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007058 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007059 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007060 return null;
7061 }
Derek Tan97ebb422014-09-05 16:55:38 -07007062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 String iccId = getIccId(subId);
7066 if (iccId != null) {
7067 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7068 if (DBG_MERGE) {
7069 log("getLine1NumberForDisplay returning "
7070 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7071 }
7072 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7075 return null;
7076 } finally {
7077 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007078 }
Derek Tan7226c842014-07-02 17:42:23 -07007079 }
7080
7081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007082 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7083 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007085 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007086 return null;
7087 }
Derek Tan97ebb422014-09-05 16:55:38 -07007088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 String iccId = getIccId(subId);
7092 if (iccId != null) {
7093 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7094 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7095 }
7096 return null;
7097 } finally {
7098 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007099 }
Derek Tan7226c842014-07-02 17:42:23 -07007100 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007101
7102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007103 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7104 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007105 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7106 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007108 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007109 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007110 return null;
7111 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007112
Jordan Liub49b04b2019-05-06 14:45:15 -07007113 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7114 // the process, where TelephonyManager was instantiated.
7115 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007116 final long identity = Binder.clearCallingIdentity();
7117 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007118 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 final TelephonyManager tele = TelephonyManager.from(context);
7120 final SubscriptionManager sub = SubscriptionManager.from(context);
7121
7122 // Figure out what subscribers are currently active
7123 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124
Jordan Liub49b04b2019-05-06 14:45:15 -07007125 // Only consider subs which match the current subId
7126 // This logic can be simplified. See b/131189269 for progress.
7127 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007128 activeSubscriberIds.add(tele.getSubscriberId(subId));
7129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130
7131 // First pass, find a number override for an active subscriber
7132 String mergeNumber = null;
7133 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7134 for (String key : prefs.keySet()) {
7135 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7136 final String subscriberId = (String) prefs.get(key);
7137 if (activeSubscriberIds.contains(subscriberId)) {
7138 final String iccId = key.substring(
7139 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7140 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7141 mergeNumber = (String) prefs.get(numberKey);
7142 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007143 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 + " for active subscriber " + subscriberId);
7145 }
7146 if (!TextUtils.isEmpty(mergeNumber)) {
7147 break;
7148 }
7149 }
7150 }
7151 }
7152
7153 // Shortcut when no active merged subscribers
7154 if (TextUtils.isEmpty(mergeNumber)) {
7155 return null;
7156 }
7157
7158 // Second pass, find all subscribers under that line override
7159 final ArraySet<String> result = new ArraySet<>();
7160 for (String key : prefs.keySet()) {
7161 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7162 final String number = (String) prefs.get(key);
7163 if (mergeNumber.equals(number)) {
7164 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7165 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7166 final String subscriberId = (String) prefs.get(subscriberKey);
7167 if (!TextUtils.isEmpty(subscriberId)) {
7168 result.add(subscriberId);
7169 }
7170 }
7171 }
7172 }
7173
7174 final String[] resultArray = result.toArray(new String[result.size()]);
7175 Arrays.sort(resultArray);
7176 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007177 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7179 }
7180 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007181 } finally {
7182 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007183 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007184 }
7185
7186 @Override
zoey chen38003472019-12-13 17:16:31 +08007187 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7188 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007189
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 final TelephonyManager telephonyManager = mApp.getSystemService(
7193 TelephonyManager.class);
7194 String subscriberId = telephonyManager.getSubscriberId(subId);
7195 if (subscriberId == null) {
7196 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007197 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007198 + subId);
7199 }
7200 return null;
7201 }
7202
7203 final SubscriptionInfo info = SubscriptionController.getInstance()
7204 .getSubscriptionInfo(subId);
7205 final ParcelUuid groupUuid = info.getGroupUuid();
7206 // If it doesn't belong to any group, return just subscriberId of itself.
7207 if (groupUuid == null) {
7208 return new String[]{subscriberId};
7209 }
7210
7211 // Get all subscriberIds from the group.
7212 final List<String> mergedSubscriberIds = new ArrayList<>();
7213 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007214 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007215 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007216 for (SubscriptionInfo subInfo : groupInfos) {
7217 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7218 if (subscriberId != null) {
7219 mergedSubscriberIds.add(subscriberId);
7220 }
7221 }
7222
7223 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226
7227 }
7228 }
7229
7230 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007231 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007232 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007233 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234
7235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 final Phone phone = getPhone(subId);
7238 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007242 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007243
7244 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007245 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007246 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7247 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007248 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7249 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250
7251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 final Phone phone = getPhone(subId);
7254 if (phone == null) {
7255 return false;
7256 }
7257 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7258 cdmaNonRoamingList);
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007261 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007262 }
7263
7264 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007265 @Deprecated
7266 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7267 enforceModifyPermission();
7268
7269 int returnValue = 0;
7270 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007271 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007272 if(result.exception == null) {
7273 if (result.result != null) {
7274 byte[] responseData = (byte[])(result.result);
7275 if(responseData.length > oemResp.length) {
7276 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7277 responseData.length + "bytes. Buffer Size is " +
7278 oemResp.length + "bytes.");
7279 }
7280 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7281 returnValue = responseData.length;
7282 }
7283 } else {
7284 CommandException ex = (CommandException) result.exception;
7285 returnValue = ex.getCommandError().ordinal();
7286 if(returnValue > 0) returnValue *= -1;
7287 }
7288 } catch (RuntimeException e) {
7289 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7290 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7291 if(returnValue > 0) returnValue *= -1;
7292 }
7293
7294 return returnValue;
7295 }
7296
7297 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007298 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007299 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007300 try {
7301 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007302 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007303 mApp, phone.getSubId(), "getRadioAccessFamily");
7304 } catch (SecurityException e) {
7305 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7306 throw e;
7307 }
chen xub97461a2018-10-26 14:17:57 -07007308 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007309 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007310 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 final long identity = Binder.clearCallingIdentity();
7313 try {
chen xub97461a2018-10-26 14:17:57 -07007314 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007315 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007316 mApp, phone.getSubId(), "getRadioAccessFamily");
7317 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 } finally {
7319 Binder.restoreCallingIdentity(identity);
7320 }
chen xub97461a2018-10-26 14:17:57 -07007321 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007322 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007323
7324 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007325 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007326 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007327 try {
7328 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7329 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007330 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007331 }
7332 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007333 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007334 }
7335 RoleManager rm = mApp.getSystemService(RoleManager.class);
7336 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7337 if (!dialerRoleHolders.contains(callingPackage)) {
7338 throw new SecurityException("App must be the dialer role holder to"
7339 + " upload a call composer pic");
7340 }
7341
7342 Executors.newSingleThreadExecutor().execute(() -> {
7343 ByteArrayOutputStream output = new ByteArrayOutputStream(
7344 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7345 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7346 boolean readUntilEnd = false;
7347 int totalBytesRead = 0;
7348 byte[] buffer = new byte[16 * 1024];
7349 while (true) {
7350 int numRead;
7351 try {
7352 numRead = input.read(buffer);
7353 } catch (IOException e) {
7354 try {
7355 fd.checkError();
7356 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7357 null);
7358 } catch (IOException e1) {
7359 // This means that the other side closed explicitly with an error. If this
7360 // happens, log and ignore.
7361 loge("Remote end of call composer picture pipe closed: " + e1);
7362 }
7363 break;
7364 }
7365 if (numRead == -1) {
7366 readUntilEnd = true;
7367 break;
7368 }
7369 totalBytesRead += numRead;
7370 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7371 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7372 try {
7373 input.close();
7374 } catch (IOException e) {
7375 // ignore
7376 }
7377 break;
7378 }
7379 output.write(buffer, 0, numRead);
7380 }
7381 // Generally, the remote end will close the file descriptors. The only case where we
7382 // close is above, where the picture size is too big.
7383
7384 try {
7385 fd.checkError();
7386 } catch (IOException e) {
7387 loge("Remote end for call composer closed with an error: " + e);
7388 return;
7389 }
7390
Hall Liuaa4211e2021-01-20 15:43:39 -08007391 if (!readUntilEnd) {
7392 loge("Did not finish reading entire image; aborting");
7393 return;
7394 }
Hall Liu82694d52020-12-11 18:22:04 -08007395
Hall Liuaa4211e2021-01-20 15:43:39 -08007396 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7397 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7398 new CallComposerPictureTransfer.Factory() {},
7399 imageData,
7400 (result) -> {
7401 if (result.first != null) {
7402 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7403 Bundle outputResult = new Bundle();
7404 outputResult.putParcelable(
7405 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7406 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7407 outputResult);
7408 } else {
7409 callback.send(result.second, null);
7410 }
7411 }
7412 );
Hall Liu82694d52020-12-11 18:22:04 -08007413 });
7414 }
7415
7416 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007417 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007418 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007419 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420
7421 final long identity = Binder.clearCallingIdentity();
7422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007423 ImsManager.getInstance(defaultPhone.getContext(),
7424 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 } finally {
7426 Binder.restoreCallingIdentity(identity);
7427 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007428 }
7429
7430 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007431 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007432 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7434 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007435 return false;
7436 }
Svet Ganovb320e182015-04-16 12:30:10 -07007437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final long identity = Binder.clearCallingIdentity();
7439 try {
7440 // Check the user preference and the system-level IMS setting. Even if the user has
7441 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7442 // In the long run, we may instead need to check if there exists a connection service
7443 // which can support video calling.
7444 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 return imsManager.isVtEnabledByPlatform()
7447 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7448 && imsManager.isVtEnabledByUser();
7449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007452 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007453
Andrew Leea1239f22015-03-02 17:44:07 -08007454 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007455 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7456 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007458 mApp, subId, callingPackage, callingFeatureId,
7459 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 return false;
7461 }
7462
7463 final long identity = Binder.clearCallingIdentity();
7464 try {
7465 CarrierConfigManager configManager =
7466 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007467 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Andrew Leea1239f22015-03-02 17:44:07 -08007472 }
7473
7474 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007475 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007477 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 return false;
7479 }
7480
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 CarrierConfigManager configManager =
7484 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007485 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
Andrew Leea1239f22015-03-02 17:44:07 -08007490 }
7491
Andrew Lee9431b832015-03-09 18:46:45 -07007492 @Override
7493 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007494 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007495 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007496 }
7497
7498 @Override
7499 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 final long identity = Binder.clearCallingIdentity();
7501 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007502 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505 }
Andrew Lee9431b832015-03-09 18:46:45 -07007506 }
7507
Hall Liuf6668912018-10-31 17:05:23 -07007508 /**
7509 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7510 * support for the feature and device firmware support.
7511 *
7512 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7513 */
7514 @Override
7515 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 final Phone phone = getPhone(subscriptionId);
7518 if (phone == null) {
7519 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7520 return false;
7521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007523 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7525 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007526 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 return isCarrierSupported && isDeviceSupported;
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Hall Liu98187582018-01-22 19:15:32 -08007531 }
7532
Hall Liuf6668912018-10-31 17:05:23 -07007533 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007534 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7535 * RTT setting, will return true if the device and carrier both support RTT.
7536 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007537 */
7538 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 final long identity = Binder.clearCallingIdentity();
7540 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007541 boolean isRttSupported = isRttSupported(subscriptionId);
7542 boolean isUserRttSettingOn = Settings.Secure.getInt(
7543 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7544 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7545 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7546 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007550 }
7551
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007552 @Deprecated
7553 @Override
7554 public String getDeviceId(String callingPackage) {
7555 return getDeviceIdWithFeature(callingPackage, null);
7556 }
7557
Sanket Padawe7310cc72015-01-14 09:53:20 -08007558 /**
7559 * Returns the unique device ID of phone, for example, the IMEI for
7560 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7561 *
7562 * <p>Requires Permission:
7563 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7564 */
7565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007566 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007567 try {
7568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7569 } catch (SecurityException se) {
7570 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7571 throw new SecurityException("Package " + callingPackage + " does not belong to "
7572 + Binder.getCallingUid());
7573 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007574 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007575 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007576 return null;
7577 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007578 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007579 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007580 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007581 return null;
7582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 return phone.getDeviceId();
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007590 }
7591
Ping Sunc67b7c22016-03-02 19:16:45 +08007592 /**
7593 * {@hide}
7594 * Returns the IMS Registration Status on a particular subid
7595 *
7596 * @param subId
7597 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007598 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007599 Phone phone = getPhone(subId);
7600 if (phone != null) {
7601 return phone.isImsRegistered();
7602 } else {
7603 return false;
7604 }
7605 }
7606
Santos Cordon7a1885b2015-02-03 11:15:19 -08007607 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007608 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007609 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007611 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007612 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7613 }
7614 final long identity = Binder.clearCallingIdentity();
7615 try {
7616 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
7621
7622 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007623 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007624 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007625 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007626 mApp,
7627 subscriptionId,
7628 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 Phone phone = getPhone(subscriptionId);
7632 if (phone == null) {
7633 return null;
7634 }
7635 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7636 } finally {
7637 Binder.restoreCallingIdentity(identity);
7638 }
7639 }
7640
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007641 /**
7642 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007643 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007644 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 Phone phone = getPhone(subId);
7648 if (phone != null) {
7649 return phone.isWifiCallingEnabled();
7650 } else {
7651 return false;
7652 }
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007655 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007656 }
7657
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007658 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007659 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007660 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007661 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 Phone phone = getPhone(subId);
7665 if (phone != null) {
7666 return phone.isVideoEnabled();
7667 } else {
7668 return false;
7669 }
7670 } finally {
7671 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007672 }
7673 }
7674
7675 /**
7676 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7677 * defined in {@link ImsRegistrationImplBase}.
7678 */
7679 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 Phone phone = getPhone(subId);
7683 if (phone != null) {
7684 return phone.getImsRegistrationTech();
7685 } else {
7686 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7687 }
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007690 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007691 }
7692
Stuart Scott8eef64f2015-04-08 15:13:54 -07007693 @Override
7694 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007695 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007696 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7697 return;
7698 }
Kai Shif70f46f2021-03-03 13:59:46 -08007699 Phone defaultPhone = getDefaultPhone();
7700 if (defaultPhone != null) {
7701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7702 mApp, getDefaultPhone().getSubId(), "factoryReset");
7703 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007704 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007705
Svet Ganovcc087f82015-05-12 20:35:54 -07007706 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007707 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7708 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007709 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007710 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007711 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007712 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007713 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007714 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007715 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007716 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007717 // There has been issues when Sms raw table somehow stores orphan
7718 // fragments. They lead to garbled message when new fragments come
7719 // in and combined with those stale ones. In case this happens again,
7720 // user can reset all network settings which will clean up this table.
7721 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007722 // Clean up IMS settings as well here.
7723 int slotId = getSlotIndex(subId);
7724 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7725 ImsManager.getInstance(mApp, slotId).factoryReset();
7726 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007727
Kai Shif70f46f2021-03-03 13:59:46 -08007728 if (defaultPhone == null) {
7729 return;
7730 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007731 // Erase modem config if erase modem on network setting is enabled.
7732 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7733 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7734 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007735 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007736 }
Kai Shif70f46f2021-03-03 13:59:46 -08007737
7738 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007739 } finally {
7740 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007741 }
7742 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007743
SongFerngWangfd89b102021-05-27 22:44:54 +08007744 @VisibleForTesting
7745 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7746 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7747 return;
7748 }
7749 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7750 RILConstants.PREFERRED_NETWORK_MODE);
7751 SubscriptionManager.setSubscriptionProperty(subId,
7752 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7753 "user=" + defaultNetworkType);
7754 phone.loadAllowedNetworksFromSubscriptionDatabase();
7755 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7756 defaultNetworkType, null);
7757 }
7758
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007759 private void cleanUpSmsRawTable(Context context) {
7760 ContentResolver resolver = context.getContentResolver();
7761 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7762 resolver.delete(uri, null, null);
7763 }
7764
Narayan Kamath1c496c22015-04-16 14:40:19 +01007765 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007766 public String getSimLocaleForSubscriber(int subId) {
7767 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7768 final Phone phone = getPhone(subId);
7769 if (phone == null) {
7770 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007771 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773 final long identity = Binder.clearCallingIdentity();
7774 try {
chen xu5d3637b2019-01-21 23:31:38 -08007775 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007776 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007777 if (info == null) {
7778 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7779 return null;
7780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 // Try and fetch the locale from the carrier properties or from the SIM language
7782 // preferences (EF-PL and EF-LI)...
7783 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007785 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7786 if (localeFromDefaultSim != null) {
7787 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7788 if (DBG) log("Using locale from subId: " + subId + " locale: "
7789 + localeFromDefaultSim);
7790 return localeFromDefaultSim.toLanguageTag();
7791 } else {
7792 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 }
7794 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 // The SIM language preferences only store a language (e.g. fr = French), not an
7797 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7798 // the SIM and carrier preferences does not include a country we add the country
7799 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007800 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007802 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 return mccLocale.toLanguageTag();
7804 }
7805
7806 if (DBG) log("No locale found - returning null");
7807 return null;
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
7810 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007811 }
7812
7813 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007814 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007815 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007816 }
7817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 /**
7819 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7820 */
7821 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007822 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007823 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007824 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007825
Gary Jian3aa9a762022-01-24 16:41:19 +08007826 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7827 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007828
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007829 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007830 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7831 * representing the state of the modem.
7832 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007833 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7834 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007835 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007836 */
7837 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007838 public void requestModemActivityInfo(ResultReceiver result) {
7839 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841
7842 final long identity = Binder.clearCallingIdentity();
7843 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007844 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 } finally {
7846 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007848 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007849
Siddharth Rayb8114062018-06-17 15:02:38 -07007850 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7851 // less than total activity duration.
7852 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7853 if (info == null) {
7854 return false;
7855 }
7856 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007857 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7858 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7859
Siddharth Rayb8114062018-06-17 15:02:38 -07007860 return (info.isValid()
7861 && (info.getSleepTimeMillis() <= activityDurationMs)
7862 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007863 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007864 && (totalTxTimeMs <= activityDurationMs));
7865 }
7866
Gary Jian3aa9a762022-01-24 16:41:19 +08007867 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7868 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7869 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7870 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7871
7872 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7873 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7874 }
7875
7876 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7877 mLastModemActivityInfo.setReceiveTimeMillis(
7878 rat,
7879 freq,
7880 info.getReceiveTimeMillis(rat, freq)
7881 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7882 }
7883
7884 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7885 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7886 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7887 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7888
7889 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7890 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7891 }
7892 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7893 mLastModemActivityInfo.setReceiveTimeMillis(
7894 rat,
7895 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7896 }
7897
7898 /**
7899 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7900 * @param info recent ModemActivityInfo
7901 */
7902 private void mergeModemActivityInfo(ModemActivityInfo info) {
7903 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7904 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7905 boolean matched;
7906 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7907 matched = false;
7908 int rat = info.getSpecificInfoRat(i);
7909 int freq = info.getSpecificInfoFrequencyRange(i);
7910 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7911 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7912 //if it already exists
7913 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7914 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7915 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7916 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7917 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7918 updateLastModemActivityInfo(info, rat, freq);
7919 matched = true;
7920 }
7921 } else {
7922 updateLastModemActivityInfo(info, rat);
7923 matched = true;
7924 }
7925 }
7926 }
7927
7928 if (!matched) {
7929 mDeltaSpecificInfo =
7930 new ActivityStatsTechSpecificInfo(
7931 rat,
7932 freq,
7933 info.getTransmitTimeMillis(rat, freq),
7934 (int) info.getReceiveTimeMillis(rat, freq));
7935 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7936 }
7937 }
7938 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7939 mLastModemActivitySpecificInfo =
7940 new ActivityStatsTechSpecificInfo[merged.size()];
7941 merged.toArray(mLastModemActivitySpecificInfo);
7942
7943 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7944 mLastModemActivityInfo.setSleepTimeMillis(
7945 info.getSleepTimeMillis()
7946 + mLastModemActivityInfo.getSleepTimeMillis());
7947 mLastModemActivityInfo.setIdleTimeMillis(
7948 info.getIdleTimeMillis()
7949 + mLastModemActivityInfo.getIdleTimeMillis());
7950 }
7951
Jack Yu85bd38a2015-11-09 11:34:32 -08007952 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007953 * Returns the service state information on specified subscription.
7954 */
7955 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007956 public ServiceState getServiceStateForSubscriber(int subId,
7957 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7958 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007960 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007961 return null;
7962 }
7963
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007964 boolean hasFinePermission = false;
7965 boolean hasCoarsePermission = false;
7966 if (!renounceFineLocationAccess) {
7967 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7968 LocationAccessPolicy.checkLocationPermission(mApp,
7969 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7970 .setCallingPackage(callingPackage)
7971 .setCallingFeatureId(callingFeatureId)
7972 .setCallingPid(Binder.getCallingPid())
7973 .setCallingUid(Binder.getCallingUid())
7974 .setMethod("getServiceStateForSubscriber")
7975 .setLogAsInfo(true)
7976 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7977 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7978 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7979 .build());
7980 hasFinePermission =
7981 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7982 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007983
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007984 if (!renounceCoarseLocationAccess) {
7985 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7986 LocationAccessPolicy.checkLocationPermission(mApp,
7987 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7988 .setCallingPackage(callingPackage)
7989 .setCallingFeatureId(callingFeatureId)
7990 .setCallingPid(Binder.getCallingPid())
7991 .setCallingUid(Binder.getCallingUid())
7992 .setMethod("getServiceStateForSubscriber")
7993 .setLogAsInfo(true)
7994 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7995 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7996 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7997 .build());
7998 hasCoarsePermission =
7999 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8000 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008001
Jack Yu479f40e2020-10-27 21:29:25 -07008002 final Phone phone = getPhone(subId);
8003 if (phone == null) {
8004 return null;
8005 }
8006
Jordan Liu0f2bc442020-11-18 16:47:37 -08008007 final long identity = Binder.clearCallingIdentity();
8008
Jack Yu479f40e2020-10-27 21:29:25 -07008009 boolean isCallingPackageDataService = phone.getDataServicePackages()
8010 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008012 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8013 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8014 Rlog.d(LOG_TAG,
8015 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8016 return null;
8017 }
8018
Hall Liuf19c44f2018-11-27 14:38:17 -08008019 ServiceState ss = phone.getServiceState();
8020
8021 // Scrub out the location info in ServiceState depending on what level of access
8022 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008023 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008024 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8025 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 } finally {
8027 Binder.restoreCallingIdentity(identity);
8028 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008029 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008030
8031 /**
8032 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8033 *
8034 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8035 * voicemail ringtone.
8036 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8037 * PhoneAccount.
8038 */
8039 @Override
8040 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8044 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008045 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8049 } finally {
8050 Binder.restoreCallingIdentity(identity);
8051 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008052 }
8053
8054 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008055 * Sets the per-account voicemail ringtone.
8056 *
8057 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8058 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8059 *
8060 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8061 * voicemail ringtone.
8062 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8063 * PhoneAccount.
8064 */
8065 @Override
8066 public void setVoicemailRingtoneUri(String callingPackage,
8067 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008068 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008070 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8071 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8073 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8074 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076
8077 final long identity = Binder.clearCallingIdentity();
8078 try {
8079 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8080 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008081 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008082 }
8083 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8084 } finally {
8085 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008086 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008087 }
8088
8089 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008090 * Returns whether vibration is set for voicemail notification in Phone settings.
8091 *
8092 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8093 * voicemail vibration setting.
8094 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8095 */
8096 @Override
8097 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8101 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008102 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008103 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
8108 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008109 }
8110
Youhan Wange64578a2016-05-02 15:32:42 -07008111 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008112 * Sets the per-account voicemail vibration.
8113 *
8114 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8115 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8116 *
8117 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8118 * voicemail vibration setting.
8119 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8120 * specific PhoneAccount.
8121 */
8122 @Override
8123 public void setVoicemailVibrationEnabled(String callingPackage,
8124 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008125 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008126 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008127 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8128 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8130 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8131 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008132 }
8133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134 final long identity = Binder.clearCallingIdentity();
8135 try {
8136 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8137 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008138 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 }
8140 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8141 } finally {
8142 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008143 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008144 }
8145
8146 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008147 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8148 *
8149 * @throws SecurityException if the caller does not have the required permission
8150 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008151 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008152 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008153 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008154 }
8155
8156 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008157 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8158 * permission.
8159 *
8160 * @throws SecurityException if the caller does not have the required permission
8161 */
8162 private void enforceSendSmsPermission() {
8163 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8164 }
8165
8166 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008167 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008168 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008169 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008170 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008171 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008172 final long identity = Binder.clearCallingIdentity();
8173 try {
8174 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008175 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008176 if (componentName == null) {
8177 throw new SecurityException(
8178 "Caller not current active visual voicemail package[null]");
8179 }
8180 String vvmPackage = componentName.getPackageName();
8181 if (!callingPackage.equals(vvmPackage)) {
8182 throw new SecurityException("Caller not current active visual voicemail package["
8183 + vvmPackage + "]");
8184 }
8185 } finally {
8186 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008187 }
8188 }
8189
8190 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008191 * Return the application ID for the app type.
8192 *
8193 * @param subId the subscription ID that this request applies to.
8194 * @param appType the uicc app type.
8195 * @return Application ID for specificied app type, or null if no uicc.
8196 */
8197 @Override
8198 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008199 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008200 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201
8202 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008203 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204 if (phone == null) {
8205 return null;
8206 }
8207 String aid = null;
8208 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008209 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 .getApplicationByType(appType).getAid();
8211 } catch (Exception e) {
8212 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8213 }
8214 return aid;
8215 } finally {
8216 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008217 }
Youhan Wange64578a2016-05-02 15:32:42 -07008218 }
8219
Youhan Wang4001d252016-05-11 10:29:41 -07008220 /**
8221 * Return the Electronic Serial Number.
8222 *
8223 * @param subId the subscription ID that this request applies to.
8224 * @return ESN or null if error.
8225 */
8226 @Override
8227 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008228 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008229 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230
8231 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008232 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 if (phone == null) {
8234 return null;
8235 }
8236 String esn = null;
8237 try {
8238 esn = phone.getEsn();
8239 } catch (Exception e) {
8240 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8241 }
8242 return esn;
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008245 }
Youhan Wang4001d252016-05-11 10:29:41 -07008246 }
8247
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008248 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008249 * Return the Preferred Roaming List Version.
8250 *
8251 * @param subId the subscription ID that this request applies to.
8252 * @return PRLVersion or null if error.
8253 */
8254 @Override
8255 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008256 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008257 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258
8259 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008260 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 if (phone == null) {
8262 return null;
8263 }
8264 String cdmaPrlVersion = null;
8265 try {
8266 cdmaPrlVersion = phone.getCdmaPrlVersion();
8267 } catch (Exception e) {
8268 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8269 }
8270 return cdmaPrlVersion;
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008273 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008274 }
8275
8276 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008277 * Get snapshot of Telephony histograms
8278 * @return List of Telephony histograms
8279 * @hide
8280 */
8281 @Override
8282 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8284 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285
8286 final long identity = Binder.clearCallingIdentity();
8287 try {
8288 return RIL.getTelephonyRILTimingHistograms();
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008292 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008293
8294 /**
8295 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008296 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8297 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008298 * Require system privileges. In the future we may add this to carrier APIs.
8299 *
Michele Berionne482f8202018-11-27 18:57:59 -08008300 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008301 */
8302 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008303 @TelephonyManager.SetCarrierRestrictionResult
8304 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008305 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008306 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008307
Michele Berionne482f8202018-11-27 18:57:59 -08008308 if (carrierRestrictionRules == null) {
8309 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008310 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 final long identity = Binder.clearCallingIdentity();
8313 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008314 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008315 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008319 }
8320
8321 /**
8322 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008323 * Get the allowed carrier list and the excluded carrier list, including the priority between
8324 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008325 * Require system privileges. In the future we may add this to carrier APIs.
8326 *
Michele Berionne482f8202018-11-27 18:57:59 -08008327 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008328 */
8329 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008330 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008331 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008332 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008336 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8337 if (response instanceof CarrierRestrictionRules) {
8338 return (CarrierRestrictionRules) response;
8339 }
8340 // Response is an Exception of some kind,
8341 // which is signalled to the user as a NULL retval
8342 return null;
8343 } catch (Exception e) {
8344 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8345 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008346 } finally {
8347 Binder.restoreCallingIdentity(identity);
8348 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008349 }
8350
fionaxu59545b42016-05-25 15:53:37 -07008351 /**
fionaxu59545b42016-05-25 15:53:37 -07008352 * Action set from carrier signalling broadcast receivers to enable/disable radio
8353 * @param subId the subscription ID that this action applies to.
8354 * @param enabled control enable or disable radio.
8355 * {@hide}
8356 */
8357 @Override
8358 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8359 enforceModifyPermission();
8360 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361
8362 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008363 if (phone == null) {
8364 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8365 return;
8366 }
8367 try {
8368 phone.carrierActionSetRadioEnabled(enabled);
8369 } catch (Exception e) {
8370 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 } finally {
8372 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008373 }
8374 }
8375
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008376 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008377 * Enable or disable Voice over NR (VoNR)
8378 * @param subId the subscription ID that this action applies to.
8379 * @param enabled enable or disable VoNR.
8380 * @return operation result.
8381 */
8382 @Override
8383 public int setVoNrEnabled(int subId, boolean enabled) {
8384 enforceModifyPermission();
8385 final Phone phone = getPhone(subId);
8386
8387 final long identity = Binder.clearCallingIdentity();
8388 if (phone == null) {
8389 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8390 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8391 }
8392
8393 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8394 try {
8395 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8396 workSource);
8397 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008398
8399 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8400 if (DBG) {
8401 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8402 }
8403 SubscriptionManager.setSubscriptionProperty(
8404 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8405 (enabled ? "1" : "0"));
8406 }
8407
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008408 return result;
8409 } finally {
8410 Binder.restoreCallingIdentity(identity);
8411 }
8412 }
8413
8414 /**
8415 * Is voice over NR enabled
8416 * @return true if VoNR is enabled else false
8417 */
8418 @Override
8419 public boolean isVoNrEnabled(int subId) {
8420 enforceReadPrivilegedPermission("isVoNrEnabled");
8421 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8422 final long identity = Binder.clearCallingIdentity();
8423 try {
8424 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8425 null, subId, workSource);
8426 if (DBG) log("isVoNrEnabled: " + isEnabled);
8427 return isEnabled;
8428 } finally {
8429 Binder.restoreCallingIdentity(identity);
8430 }
8431 }
8432
8433 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008434 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8435 * network status based on which carrier apps could apply actions accordingly,
8436 * enable/disable default url handler for example.
8437 *
8438 * @param subId the subscription ID that this action applies to.
8439 * @param report control start/stop reporting the default network status.
8440 * {@hide}
8441 */
8442 @Override
8443 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8444 enforceModifyPermission();
8445 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446
8447 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008448 if (phone == null) {
8449 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8450 return;
8451 }
8452 try {
8453 phone.carrierActionReportDefaultNetworkStatus(report);
8454 } catch (Exception e) {
8455 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456 } finally {
8457 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008458 }
8459 }
8460
8461 /**
fionaxud9622282017-07-17 17:51:30 -07008462 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8463 * @param subId the subscription ID that this action applies to.
8464 * {@hide}
8465 */
8466 @Override
8467 public void carrierActionResetAll(int subId) {
8468 enforceModifyPermission();
8469 final Phone phone = getPhone(subId);
8470 if (phone == null) {
8471 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8472 return;
8473 }
8474 try {
8475 phone.carrierActionResetAll();
8476 } catch (Exception e) {
8477 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8478 }
8479 }
8480
8481 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008482 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8483 * bug report is being generated.
8484 */
8485 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008486 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008487 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8488 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008489 writer.println("Permission Denial: can't dump Phone from pid="
8490 + Binder.getCallingPid()
8491 + ", uid=" + Binder.getCallingUid()
8492 + "without permission "
8493 + android.Manifest.permission.DUMP);
8494 return;
8495 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008496 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008497 }
Jack Yueb89b242016-06-22 13:27:47 -07008498
Brad Ebingerdac2f002018-04-03 15:17:52 -07008499 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008500 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8501 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8502 @NonNull String[] args) {
8503 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8504 this, in.getFileDescriptor(), out.getFileDescriptor(),
8505 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008506 }
8507
Jack Yueb89b242016-06-22 13:27:47 -07008508 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008509 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008510 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008511 * @param reason the reason the data enable change is taking place
8512 * @param enabled True if enabling the data, otherwise disabling.
8513 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008514 */
8515 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008516 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008517 boolean enabled) {
8518 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8519 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8520 try {
8521 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008522 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008523 } catch (SecurityException se) {
8524 enforceModifyPermission();
8525 }
8526 } else {
8527 enforceModifyPermission();
8528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529
8530 final long identity = Binder.clearCallingIdentity();
8531 try {
8532 Phone phone = getPhone(subId);
8533 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008534 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8535 phone.carrierActionSetMeteredApnsEnabled(enabled);
8536 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008537 if (phone.isUsingNewDataStack()) {
8538 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8539 } else {
8540 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8541 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543 }
8544 } finally {
8545 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008546 }
8547 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008548
8549 /**
8550 * Get Client request stats
8551 * @return List of Client Request Stats
8552 * @hide
8553 */
8554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008555 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8556 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008558 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008559 return null;
8560 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008561 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563 final long identity = Binder.clearCallingIdentity();
8564 try {
8565 if (phone != null) {
8566 return phone.getClientRequestStats();
8567 }
8568
8569 return null;
8570 } finally {
8571 Binder.restoreCallingIdentity(identity);
8572 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008573 }
8574
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008575 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008576 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008577 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008578 }
Jack Yueb4124c2017-02-16 15:32:43 -08008579
8580 /**
Grace Chen70990072017-03-24 17:21:30 -07008581 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008582 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008583 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008584 * @param state State of SIM (power down, power up, pass through)
8585 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8586 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8587 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008588 *
8589 **/
8590 @Override
Grace Chen70990072017-03-24 17:21:30 -07008591 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008592 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008593 Phone phone = PhoneFactory.getPhone(slotIndex);
8594
vagdeviaf9a5b92018-08-15 16:01:53 -07008595 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 final long identity = Binder.clearCallingIdentity();
8598 try {
8599 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008600 phone.setSimPowerState(state, null, workSource);
8601 }
8602 } finally {
8603 Binder.restoreCallingIdentity(identity);
8604 }
8605 }
8606
8607 /**
8608 * Set SIM card power state.
8609 *
8610 * @param slotIndex SIM slot id.
8611 * @param state State of SIM (power down, power up, pass through)
8612 * @param callback callback to trigger after success or failure
8613 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8614 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8615 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8616 *
8617 **/
8618 @Override
8619 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8620 IIntegerConsumer callback) {
8621 enforceModifyPermission();
8622 Phone phone = PhoneFactory.getPhone(slotIndex);
8623
8624 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8625
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 if (phone != null) {
8629 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8630 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008631 }
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008634 }
8635 }
Shuo Qiandd210312017-04-12 22:11:33 +00008636
Tyler Gunn65d45c22017-06-05 11:22:26 -07008637 private boolean isUssdApiAllowed(int subId) {
8638 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008639 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008640 if (configManager == null) {
8641 return false;
8642 }
8643 PersistableBundle pb = configManager.getConfigForSubId(subId);
8644 if (pb == null) {
8645 return false;
8646 }
8647 return pb.getBoolean(
8648 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8649 }
8650
Shuo Qiandd210312017-04-12 22:11:33 +00008651 /**
8652 * Check if phone is in emergency callback mode
8653 * @return true if phone is in emergency callback mode
8654 * @param subId sub id
8655 */
goneil9c5f4872017-12-05 14:07:56 -08008656 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008657 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008658 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008659 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008660
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
8663 if (phone != null) {
8664 return phone.isInEcm();
8665 } else {
8666 return false;
8667 }
8668 } finally {
8669 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008670 }
8671 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008672
8673 /**
8674 * Get the current signal strength information for the given subscription.
8675 * Because this information is not updated when the device is in a low power state
8676 * it should not be relied-upon to be current.
8677 * @param subId Subscription index
8678 * @return the most recent cached signal strength info from the modem
8679 */
8680 @Override
8681 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008682 final long identity = Binder.clearCallingIdentity();
8683 try {
8684 Phone p = getPhone(subId);
8685 if (p == null) {
8686 return null;
8687 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008689 return p.getSignalStrength();
8690 } finally {
8691 Binder.restoreCallingIdentity(identity);
8692 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008693 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008694
Pengquan Meng77b7f132018-08-22 14:49:57 -07008695 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008696 * Get the current modem radio state for the given slot.
8697 * @param slotIndex slot index.
8698 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008699 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008700 * @return the current radio power state from the modem
8701 */
8702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008703 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008704 Phone phone = PhoneFactory.getPhone(slotIndex);
8705 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8707 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008708 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8709 }
8710
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
8713 return phone.getRadioPowerState();
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 }
8718 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8719 }
8720
8721 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008722 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8723 *
8724 * <p>Requires one of the following permissions:
8725 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008726 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008727 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8728 * privileges.
8729 *
8730 * @param subId subscription id
8731 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8732 * {@code false}.
8733 */
8734 @Override
8735 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008736 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008737 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008738 try {
8739 mApp.enforceCallingOrSelfPermission(
8740 android.Manifest.permission.ACCESS_NETWORK_STATE,
8741 functionName);
8742 } catch (Exception e) {
8743 mApp.enforceCallingOrSelfPermission(
8744 permission.READ_BASIC_PHONE_STATE, functionName);
8745 }
Shuo Qian093013d2020-08-13 15:42:55 -07008746 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008747 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008748 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008749 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008750
Pengquan Menga1bb6272018-09-06 09:59:22 -07008751 boolean isEnabled = false;
8752 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008753 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008754 Phone phone = getPhone(subId);
8755 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008756 } finally {
8757 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008758 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008759 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008760 }
8761
8762
8763 /**
8764 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8765 *
8766 * <p> Requires permission:
8767 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8768 * privileges.
8769 *
8770 * @param subId subscription id
8771 * @param isEnabled {@code true} means enable, {@code false} means disable.
8772 */
8773 @Override
8774 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8776 mApp, subId, "setDataRoamingEnabled");
8777
Pengquan Menga1bb6272018-09-06 09:59:22 -07008778 final long identity = Binder.clearCallingIdentity();
8779 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008780 Phone phone = getPhone(subId);
8781 if (phone != null) {
8782 phone.setDataRoamingEnabled(isEnabled);
8783 }
8784 } finally {
8785 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008786 }
8787 }
8788
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008789 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008790 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008791 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008792 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008793 mApp, subId, "isManualNetworkSelectionAllowed");
8794
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008795 boolean isAllowed = true;
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008798 Phone phone = getPhone(subId);
8799 if (phone != null) {
8800 isAllowed = phone.isCspPlmnEnabled();
8801 }
8802 } finally {
8803 Binder.restoreCallingIdentity(identity);
8804 }
8805 return isAllowed;
8806 }
8807
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008808 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8809 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008810 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008811 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008812 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008813 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8814 if (phone == null) {
8815 return false;
8816 }
8817 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8818 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8819 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008820 }
8821
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008822 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008823 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008824 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008825 mApp.getSystemService(AppOpsManager.class)
8826 .checkPackage(Binder.getCallingUid(), callingPackage);
8827
Jordan Liu1e142fc2019-04-22 15:10:43 -07008828 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008829 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008830 try {
8831 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008832 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008833 } catch (SecurityException e) {
8834 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8835 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008836 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008837 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008838 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008839 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008840 }
sandeepjsb6c87872021-09-27 15:34:44 +00008841 // checking compatibility, if calling app's target SDK is T and beyond.
8842 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8843 Binder.getCallingUid())) {
8844 isIccIdAccessRestricted = true;
8845 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008846 final long identity = Binder.clearCallingIdentity();
8847 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008848 UiccController uiccController = UiccController.getInstance();
8849 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008850 if (hasReadPermission) {
8851 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008852 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008853
8854 // Remove private info if the caller doesn't have access
8855 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8856 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008857 //setting the value after compatibility check
8858 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008859 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8860 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008861 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008862 if (card == null) {
8863 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008864 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008865 continue;
8866 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008867 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8868 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008869 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008870 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008871 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008872 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8873 for (UiccPortInfo portInfo : portInfos) {
8874 UiccPort port = uiccController.getUiccPortForSlot(
8875 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8876 if (port == null) {
8877 // assume no access if port is null
8878 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8879 continue;
8880 }
8881 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8882 uiccPortInfos.add(portInfo);
8883 } else {
8884 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8885 }
8886 }
8887 filteredInfos.add(new UiccCardInfo(
8888 cardInfo.isEuicc(),
8889 cardInfo.getCardId(),
8890 null,
8891 cardInfo.getPhysicalSlotIndex(),
8892 cardInfo.isRemovable(),
8893 cardInfo.isMultipleEnabledProfilesSupported(),
8894 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008895 }
8896 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008897 } finally {
8898 Binder.restoreCallingIdentity(identity);
8899 }
8900 }
8901
sandeepjsb6c87872021-09-27 15:34:44 +00008902 /**
8903 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8904 * generally private and require carrier privileges to view.
8905 *
8906 * @hide
8907 */
8908 @NonNull
8909 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8910 List<UiccPortInfo> portinfo = new ArrayList<>();
8911 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8912 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8913 }
8914 return new UiccCardInfo(
8915 cardInfo.isEuicc(),
8916 cardInfo.getCardId(),
8917 null,
8918 cardInfo.getPhysicalSlotIndex(),
8919 cardInfo.isRemovable(),
8920 cardInfo.isMultipleEnabledProfilesSupported(),
8921 portinfo
8922 );
8923 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008924
sandeepjsb6c87872021-09-27 15:34:44 +00008925 /**
8926 * @hide
8927 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8928 * These values are generally private and require carrier privileges to view.
8929 */
8930 @NonNull
8931 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8932 return new UiccPortInfo(
8933 UiccPortInfo.ICCID_REDACTED,
8934 portInfo.getPortIndex(),
8935 portInfo.getLogicalSlotIndex(),
8936 portInfo.isActive()
8937 );
8938 }
8939 @Override
8940 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008941 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008942 mApp.getSystemService(AppOpsManager.class)
8943 .checkPackage(Binder.getCallingUid(), callingPackage);
8944
8945 boolean hasReadPermission = false;
8946 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008947
8948 try {
8949 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8950 hasReadPermission = true;
8951 } catch (SecurityException e) {
8952 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8953 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008954 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
sandeepjsb6c87872021-09-27 15:34:44 +00008955 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8956 hasReadPermission = true;
8957 }
8958 }
8959
8960 // checking compatibility, if calling app's target SDK is T and beyond.
8961 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8962 Binder.getCallingUid())) {
8963 isLogicalSlotAccessRestricted = true;
8964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008965 final long identity = Binder.clearCallingIdentity();
8966 try {
8967 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008968 if (slots == null || slots.length == 0) {
8969 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008970 return null;
8971 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8973 for (int i = 0; i < slots.length; i++) {
8974 UiccSlot slot = slots[i];
8975 if (slot == null) {
8976 continue;
8977 }
8978
Jordan Liu7be7e652019-05-06 18:55:02 +00008979 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 UiccCard card = slot.getUiccCard();
8981 if (card != null) {
8982 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008983 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008984 cardId = slot.getEid();
8985 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008986 // If cardId is null, use iccId of default port as cardId. Check if has
8987 // read permission otherwise set to null.(card is null which means no
8988 // carrier permission)
8989 cardId = hasReadPermission ? slot.getIccId(
8990 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008992 }
8993
Jordan Liu857451f2019-05-09 16:35:35 -07008994 if (cardId != null) {
8995 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8996 // if cardId is an EID, it's all digits so this is fine
8997 cardId = IccUtils.stripTrailingFs(cardId);
8998 }
8999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009000 int cardState = 0;
9001 switch (slot.getCardState()) {
9002 case CARDSTATE_ABSENT:
9003 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9004 break;
9005 case CARDSTATE_PRESENT:
9006 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9007 break;
9008 case CARDSTATE_ERROR:
9009 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9010 break;
9011 case CARDSTATE_RESTRICTED:
9012 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9013 break;
9014 default:
9015 break;
9016
9017 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009018 List<UiccPortInfo> portInfos = new ArrayList<>();
9019 int[] portIndexes = slot.getPortList();
9020 for (int portIdx : portIndexes) {
9021 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9022 callingPackage, hasReadPermission));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009023 portInfos.add(new UiccPortInfo(iccId, portIdx,
9024 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009026 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009027 slot.isEuicc(),
9028 cardId,
9029 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009030 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009031 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009032 //setting the value after compatibility check
9033 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009034 }
9035 return infos;
9036 } finally {
9037 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009038 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009039 }
9040
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009041 /* Returns null if doesn't have read permission or carrier privilege access. */
9042 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9043 boolean hasReadPermission) {
9044 String iccId = slot.getIccId(portIndex);
9045 if (hasReadPermission) { // if has read permission
9046 return iccId;
9047 } else {
9048 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9049 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9050 // if no read permission, checking carrier privilege access
9051 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9052 return iccId;
9053 }
9054 }
9055 }
9056 // No read permission or carrier privilege access.
9057 return UiccPortInfo.ICCID_REDACTED;
9058 }
9059
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009060 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009061 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009062 public boolean switchSlots(int[] physicalSlots) {
9063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009064
9065 final long identity = Binder.clearCallingIdentity();
9066 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009067 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9068 for (int i = 0; i < physicalSlots.length; i++) {
9069 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9070 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9071 physicalSlots[i], i));
9072 }
9073 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074 } finally {
9075 Binder.restoreCallingIdentity(identity);
9076 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009077 }
Jack Yu4c988042018-02-27 15:30:01 -08009078
9079 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009080 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9081 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9082 enforceModifyPermission();
9083
9084 final long identity = Binder.clearCallingIdentity();
9085 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009086 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009087 } finally {
9088 Binder.restoreCallingIdentity(identity);
9089 }
9090 }
9091
9092 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009093 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009094 final long identity = Binder.clearCallingIdentity();
9095 try {
9096 return UiccController.getInstance().getCardIdForDefaultEuicc();
9097 } finally {
9098 Binder.restoreCallingIdentity(identity);
9099 }
9100 }
9101
Pengquan Meng85728fb2018-03-12 16:31:21 -07009102 /**
goneil47ffb6e2018-04-06 15:40:58 -07009103 * A test API to reload the UICC profile.
9104 *
9105 * <p>Requires that the calling app has permission
9106 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9107 * @hide
9108 */
9109 @Override
9110 public void refreshUiccProfile(int subId) {
9111 enforceModifyPermission();
9112
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
9115 Phone phone = getPhone(subId);
9116 if (phone == null) {
9117 return;
9118 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009119 UiccPort uiccPort = phone.getUiccPort();
9120 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009121 return;
9122 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009123 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009124 if (uiccProfile == null) {
9125 return;
9126 }
9127 uiccProfile.refresh();
9128 } finally {
9129 Binder.restoreCallingIdentity(identity);
9130 }
9131 }
9132
9133 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009134 * Returns false if the mobile data is disabled by default, otherwise return true.
9135 */
9136 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009137 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009138 }
9139
9140 /**
9141 * Returns true if the data roaming is enabled by default, i.e the system property
9142 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9143 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9144 */
9145 private boolean getDefaultDataRoamingEnabled(int subId) {
9146 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009147 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009148 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009149 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9150 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9151 return isDataRoamingEnabled;
9152 }
9153
9154 /**
9155 * Returns the default network type for the given {@code subId}, if the default network type is
9156 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9157 */
9158 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009159 List<Integer> list = TelephonyProperties.default_network();
9160 int phoneId = mSubscriptionController.getPhoneId(subId);
9161 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9162 return list.get(phoneId);
9163 }
9164 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009165 }
fionaxua13278b2018-03-21 00:08:13 -07009166
9167 @Override
9168 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009169 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009171
9172 final long identity = Binder.clearCallingIdentity();
9173 try {
9174 final Phone phone = getPhone(subId);
9175 if (phone == null) {
9176 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9177 return;
9178 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009179 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9180 if (cpt != null) {
9181 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9182 }
9183 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009184 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9185 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009186 if (carrierPrivilegeRules == null) {
9187 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9188 } else {
9189 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009191 } finally {
9192 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009193 }
fionaxua13278b2018-03-21 00:08:13 -07009194 }
9195
9196 @Override
9197 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009198 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009199
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
9202 final Phone phone = getPhone(subId);
9203 if (phone == null) {
9204 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9205 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9206 }
9207 return phone.getCarrierIdListVersion();
9208 } finally {
9209 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009210 }
fionaxua13278b2018-03-21 00:08:13 -07009211 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009212
9213 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009214 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9215 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009217 mApp, subId, callingPackage, callingFeatureId,
9218 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009219 return -1;
9220 }
9221
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9225 } finally {
9226 Binder.restoreCallingIdentity(identity);
9227 }
9228 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009229
9230 @Override
9231 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009232 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009233 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009234 mApp, subId, "getCdmaRoamingMode");
9235
9236 final long identity = Binder.clearCallingIdentity();
9237 try {
9238 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 }
9243
9244 @Override
9245 public boolean setCdmaRoamingMode(int subId, int mode) {
9246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9247 mApp, subId, "setCdmaRoamingMode");
9248
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
9255 }
9256
9257 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009258 public int getCdmaSubscriptionMode(int subId) {
9259 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009260 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009261 mApp, subId, "getCdmaSubscriptionMode");
9262
9263 final long identity = Binder.clearCallingIdentity();
9264 try {
9265 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9266 } finally {
9267 Binder.restoreCallingIdentity(identity);
9268 }
9269 }
9270
9271 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009272 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9274 mApp, subId, "setCdmaSubscriptionMode");
9275
9276 final long identity = Binder.clearCallingIdentity();
9277 try {
9278 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009283
sqianc5eccab2018-10-19 18:46:41 -07009284 @Override
sqian8c685422019-02-22 15:55:18 -08009285 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009286 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009288 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9289 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009290 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9291 }
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
sqian854d44b2018-12-12 16:48:18 -08009294 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9295 for (Phone phone: PhoneFactory.getPhones()) {
9296 if (phone.getEmergencyNumberTracker() != null
9297 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9298 emergencyNumberListInternal.put(
9299 phone.getSubId(),
9300 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9301 }
sqian11b7a0e2018-12-05 18:48:28 -08009302 }
sqian854d44b2018-12-12 16:48:18 -08009303 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
sqianc5eccab2018-10-19 18:46:41 -07009307 }
9308
9309 @Override
sqian8c685422019-02-22 15:55:18 -08009310 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009311 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009312 if (!exactMatch) {
9313 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009314 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009315 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009316 }
9317 final long identity = Binder.clearCallingIdentity();
9318 try {
sqian854d44b2018-12-12 16:48:18 -08009319 for (Phone phone: PhoneFactory.getPhones()) {
9320 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009321 && phone.getEmergencyNumberTracker()
9322 .isEmergencyNumber(number, exactMatch)) {
9323 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009324 }
sqian11b7a0e2018-12-05 18:48:28 -08009325 }
9326 return false;
9327 } finally {
9328 Binder.restoreCallingIdentity(identity);
9329 }
9330 }
9331
sqianf4ca7ed2019-01-15 18:32:07 -08009332 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009333 * Start emergency callback mode for GsmCdmaPhone for testing.
9334 */
9335 @Override
9336 public void startEmergencyCallbackMode() {
9337 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9338 "startEmergencyCallbackMode");
9339 enforceModifyPermission();
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 for (Phone phone : PhoneFactory.getPhones()) {
9343 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9344 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9345 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9346 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9347 gsmCdmaPhone.obtainMessage(
9348 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9349 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9350 }
9351 }
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
9356
9357 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009358 * Update emergency number list for test mode.
9359 */
9360 @Override
9361 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9363 "updateEmergencyNumberListTestMode");
9364
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
9367 for (Phone phone: PhoneFactory.getPhones()) {
9368 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9369 if (tracker != null) {
9370 tracker.executeEmergencyNumberTestModeCommand(action, num);
9371 }
9372 }
9373 } finally {
9374 Binder.restoreCallingIdentity(identity);
9375 }
9376 }
9377
9378 /**
9379 * Get the full emergency number list for test mode.
9380 */
9381 @Override
9382 public List<String> getEmergencyNumberListTestMode() {
9383 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9384 "getEmergencyNumberListTestMode");
9385
9386 final long identity = Binder.clearCallingIdentity();
9387 try {
9388 Set<String> emergencyNumbers = new HashSet<>();
9389 for (Phone phone: PhoneFactory.getPhones()) {
9390 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9391 if (tracker != null) {
9392 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9393 emergencyNumbers.add(num.getNumber());
9394 }
9395 }
9396 }
9397 return new ArrayList<>(emergencyNumbers);
9398 } finally {
9399 Binder.restoreCallingIdentity(identity);
9400 }
9401 }
9402
chen xud6b45bd2018-10-30 22:27:10 -07009403 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009404 public int getEmergencyNumberDbVersion(int subId) {
9405 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9406
9407 final long identity = Binder.clearCallingIdentity();
9408 try {
9409 final Phone phone = getPhone(subId);
9410 if (phone == null) {
9411 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9412 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9413 }
9414 return phone.getEmergencyNumberDbVersion();
9415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 }
9419
9420 @Override
9421 public void notifyOtaEmergencyNumberDbInstalled() {
9422 enforceModifyPermission();
9423
9424 final long identity = Binder.clearCallingIdentity();
9425 try {
9426 for (Phone phone: PhoneFactory.getPhones()) {
9427 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9428 if (tracker != null) {
9429 tracker.updateOtaEmergencyNumberDatabase();
9430 }
9431 }
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
9437 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009438 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009439 enforceActiveEmergencySessionPermission();
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 for (Phone phone: PhoneFactory.getPhones()) {
9444 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9445 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009446 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9447 }
9448 }
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
9453
9454 @Override
9455 public void resetOtaEmergencyNumberDbFilePath() {
9456 enforceActiveEmergencySessionPermission();
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 for (Phone phone: PhoneFactory.getPhones()) {
9461 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9462 if (tracker != null) {
9463 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009464 }
9465 }
9466 } finally {
9467 Binder.restoreCallingIdentity(identity);
9468 }
9469 }
9470
9471 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009472 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9473 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9474 Phone phone = getPhone(subId);
9475 if (phone == null) {
9476 return null;
9477 }
9478 final long identity = Binder.clearCallingIdentity();
9479 try {
9480 UiccProfile profile = UiccController.getInstance()
9481 .getUiccProfileForPhone(phone.getPhoneId());
9482 if (profile != null) {
9483 return profile.getCertsFromCarrierPrivilegeAccessRules();
9484 }
9485 } finally {
9486 Binder.restoreCallingIdentity(identity);
9487 }
9488 return null;
9489 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009490
9491 /**
9492 * Enable or disable a modem stack.
9493 */
9494 @Override
9495 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9496 enforceModifyPermission();
9497
9498 final long identity = Binder.clearCallingIdentity();
9499 try {
9500 Phone phone = PhoneFactory.getPhone(slotIndex);
9501 if (phone == null) {
9502 return false;
9503 } else {
9504 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9505 }
9506 } finally {
9507 Binder.restoreCallingIdentity(identity);
9508 }
9509 }
Michelecea4cf22018-12-21 15:00:11 -08009510
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009511 /**
9512 * Whether a modem stack is enabled or not.
9513 */
9514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009515 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9516 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009517 Phone phone = PhoneFactory.getPhone(slotIndex);
9518 if (phone == null) return false;
9519
9520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009521 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9522 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009523 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9524 }
9525
9526 final long identity = Binder.clearCallingIdentity();
9527 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009528 try {
9529 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9530 } catch (NoSuchElementException ex) {
9531 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9532 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
Michelecea4cf22018-12-21 15:00:11 -08009538 @Override
Michele0ea7d782019-03-19 14:58:42 -07009539 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009540 enforceModifyPermission();
9541
9542 final long identity = Binder.clearCallingIdentity();
9543 try {
9544 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009545 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009546 .commit();
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
9551
9552 @Override
Michele0ea7d782019-03-19 14:58:42 -07009553 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009554 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009556 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9557 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009558 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009559 }
Michelecea4cf22018-12-21 15:00:11 -08009560
9561 final long identity = Binder.clearCallingIdentity();
9562 try {
Michele0ea7d782019-03-19 14:58:42 -07009563 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009568
Michele0ea7d782019-03-19 14:58:42 -07009569 @TelephonyManager.IsMultiSimSupportedResult
9570 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009571 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9572 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9573 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009574 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9575 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009576 }
9577 // Check if the hardware supports multisim functionality. If usage of multisim is not
9578 // supported by the modem, indicate that it is restricted.
9579 PhoneCapability staticCapability =
9580 mPhoneConfigurationManager.getStaticPhoneCapability();
9581 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009582 loge("isMultiSimSupportedInternal: no static configuration available");
9583 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009584 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009585 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009586 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9587 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009588 }
9589 // Check if support of multiple SIMs is restricted by carrier
9590 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009591 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009592 }
9593
Michele0ea7d782019-03-19 14:58:42 -07009594 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009595 }
9596
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009597 /**
9598 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009599 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9600 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9601 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009602 * @param numOfSims number of active sims we want to switch to
9603 */
9604 @Override
9605 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009606 if (numOfSims == 1) {
9607 enforceModifyPermission();
9608 } else {
9609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9610 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9611 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009612 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009613
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009614 try {
Michele30b57b22019-03-01 12:01:14 -08009615 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009616 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009617 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9618 return;
9619 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009620 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
9625
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009626 @Override
9627 public boolean isApplicationOnUicc(int subId, int appType) {
9628 enforceReadPrivilegedPermission("isApplicationOnUicc");
9629 Phone phone = getPhone(subId);
9630 if (phone == null) {
9631 return false;
9632 }
9633 final long identity = Binder.clearCallingIdentity();
9634 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009635 UiccPort uiccPort = phone.getUiccPort();
9636 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009637 return false;
9638 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009639 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009640 if (uiccProfile == null) {
9641 return false;
9642 }
9643 if (TelephonyManager.APPTYPE_SIM <= appType
9644 && appType <= TelephonyManager.APPTYPE_ISIM) {
9645 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9646 }
9647 return false;
9648 } finally {
9649 Binder.restoreCallingIdentity(identity);
9650 }
9651 }
9652
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009653 /**
chen xub4baa772019-04-03 10:23:41 -07009654 * Get whether making changes to modem configurations will trigger reboot.
9655 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009656 */
9657 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009658 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9659 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009661 mApp, subId, callingPackage, callingFeatureId,
9662 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009663 return false;
9664 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009665 final long identity = Binder.clearCallingIdentity();
9666 try {
9667 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
9672
Nathan Harold29f5f052019-02-15 13:41:57 -08009673 private void updateModemStateMetrics() {
9674 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9675 // TODO: check the state for each modem if the api is ready.
9676 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9677 }
9678
Pengquan Meng3889a572019-01-23 11:16:29 -08009679 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009680 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009681 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009682 // Verify that the callingPackage belongs to the calling UID
9683 mApp.getSystemService(AppOpsManager.class)
9684 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009685 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009686 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009687 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009688 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9689 if (slotInfos != null) {
9690 for (int i = 0; i < slotInfos.length; i++) {
9691 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9692 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9693 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9694 portInfo.getLogicalSlotIndex()));
9695 }
9696 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009697 }
9698 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009699 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009700 } finally {
9701 Binder.restoreCallingIdentity(identity);
9702 }
9703 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009704
9705 /**
9706 * Get the IRadio HAL Version
9707 */
9708 @Override
9709 public int getRadioHalVersion() {
9710 Phone phone = getDefaultPhone();
9711 if (phone == null) return -1;
9712 HalVersion hv = phone.getHalVersion();
9713 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9714 return hv.major * 100 + hv.minor;
9715 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009716
9717 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009718 * Get the current calling package name.
9719 * @return the current calling package name
9720 */
9721 @Override
9722 public String getCurrentPackageName() {
9723 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9724 }
9725
9726 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009727 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9728 * corresponding network requests on a subId.
9729 *
9730 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009731 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009732 * 2) APN is un-metered for this subscription, or
9733 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009734 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009735 *
9736 * @return whether data is allowed for a apn type.
9737 *
9738 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009739 */
9740 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009741 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009742 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9743 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009744
9745 // Now that all security checks passes, perform the operation as ourselves.
9746 final long identity = Binder.clearCallingIdentity();
9747 try {
9748 Phone phone = getPhone(subId);
9749 if (phone == null) return false;
9750
Jack Yu41407ee2019-05-13 16:54:09 -07009751 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009752 boolean isDataEnabled;
9753 if (phone.isUsingNewDataStack()) {
9754 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9755 } else {
9756 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9757 }
9758 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009759 } finally {
9760 Binder.restoreCallingIdentity(identity);
9761 }
9762 }
9763
9764 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009765 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009766 enforceReadPrivilegedPermission("isApnMetered");
9767
9768 // Now that all security checks passes, perform the operation as ourselves.
9769 final long identity = Binder.clearCallingIdentity();
9770 try {
9771 Phone phone = getPhone(subId);
9772 if (phone == null) return true; // By default return true.
9773
Jack Yu41407ee2019-05-13 16:54:09 -07009774 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009779
9780 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009781 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9782 int subscriptionId, IBooleanConsumer resultCallback) {
9783 enforceModifyPermission();
9784 long token = Binder.clearCallingIdentity();
9785 try {
9786 Phone phone = getPhone(subscriptionId);
9787 if (phone == null) {
9788 try {
9789 if (resultCallback != null) {
9790 resultCallback.accept(false);
9791 }
9792 } catch (RemoteException e) {
9793 // ignore
9794 }
9795 return;
9796 }
9797 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9798 Pair.create(specifiers, (x) -> {
9799 try {
9800 if (resultCallback != null) {
9801 resultCallback.accept(x);
9802 }
9803 } catch (RemoteException e) {
9804 // ignore
9805 }
9806 });
9807 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9808 } finally {
9809 Binder.restoreCallingIdentity(token);
9810 }
9811 }
9812
9813 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009814 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9815 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009816 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009817 mApp, subId, "getSystemSelectionChannels");
9818 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9819 final long identity = Binder.clearCallingIdentity();
9820 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009821 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9822 if (result instanceof IllegalStateException) {
9823 throw (IllegalStateException) result;
9824 }
9825 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009826 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9827 return specifiers;
9828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
9833 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009834 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009835 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009836 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9837 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9838 if (iccRecords == null) {
9839 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9840 return false;
9841 }
9842 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9843 }
9844
9845 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009846 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9847 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009848 if (callingPackage == null) {
9849 callingPackage = getCurrentPackageName();
9850 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009851 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9852 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009853 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9854 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009855 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9856 }
9857 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9858 Intent intent = new Intent();
9859 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9860 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9861 // Bring up choose default SMS subscription dialog right now
9862 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9863 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9864 mApp.startActivity(intent);
9865 }
chen xud5ca2d52019-05-28 15:20:57 -07009866
9867 @Override
9868 public String getMmsUAProfUrl(int subId) {
9869 //TODO investigate if this API should require proper permission check in R b/133791609
9870 final long identity = Binder.clearCallingIdentity();
9871 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009872 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9873 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9874 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9875 return carrierUAProfUrl;
9876 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009877 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9878 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009879 } finally {
9880 Binder.restoreCallingIdentity(identity);
9881 }
9882 }
9883
9884 @Override
9885 public String getMmsUserAgent(int subId) {
9886 //TODO investigate if this API should require proper permission check in R b/133791609
9887 final long identity = Binder.clearCallingIdentity();
9888 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009889 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9890 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9891 if (!TextUtils.isEmpty(carrierUserAgent)) {
9892 return carrierUserAgent;
9893 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009894 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9895 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009896 } finally {
9897 Binder.restoreCallingIdentity(identity);
9898 }
9899 }
Jack Yub07d4972019-05-28 16:12:25 -07009900
9901 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009902 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9903 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009904
Jack Yub07d4972019-05-28 16:12:25 -07009905 final long identity = Binder.clearCallingIdentity();
9906 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009907 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009908 if (phone == null) return false;
9909
Hall Liua62f5da2020-09-25 10:42:19 -07009910 switch (policy) {
9911 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009912 if (phone.isUsingNewDataStack()) {
9913 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9914 } else {
9915 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9916 }
Hall Liua62f5da2020-09-25 10:42:19 -07009917 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009918 if (phone.isUsingNewDataStack()) {
9919 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9920 } else {
9921 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9922 }
Hall Liua62f5da2020-09-25 10:42:19 -07009923 default:
9924 throw new IllegalArgumentException(policy + " is not a valid policy");
9925 }
Jack Yub07d4972019-05-28 16:12:25 -07009926 } finally {
9927 Binder.restoreCallingIdentity(identity);
9928 }
9929 }
9930
9931 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009932 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009933 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009934 enforceModifyPermission();
9935
changbettyd5c246e2019-12-24 15:40:37 +08009936 final long identity = Binder.clearCallingIdentity();
9937 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009938 Phone phone = getPhone(subscriptionId);
9939 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009940
Hall Liua62f5da2020-09-25 10:42:19 -07009941 switch (policy) {
9942 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009943 if (phone.isUsingNewDataStack()) {
9944 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9945 } else {
9946 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9947 }
Hall Liua62f5da2020-09-25 10:42:19 -07009948 break;
9949 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009950 if (phone.isUsingNewDataStack()) {
9951 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9952 } else {
9953 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9954 }
Hall Liua62f5da2020-09-25 10:42:19 -07009955 break;
9956 default:
9957 throw new IllegalArgumentException(policy + " is not a valid policy");
9958 }
changbettyd5c246e2019-12-24 15:40:37 +08009959 } finally {
9960 Binder.restoreCallingIdentity(identity);
9961 }
9962 }
9963
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009964 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009965 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009966 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9967 * otherwise.
9968 */
9969 @Override
9970 public void setCepEnabled(boolean isCepEnabled) {
9971 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9972
9973 final long identity = Binder.clearCallingIdentity();
9974 try {
9975 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9976 for (Phone phone : PhoneFactory.getPhones()) {
9977 Phone defaultPhone = phone.getImsPhone();
9978 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9979 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9980 ImsPhoneCallTracker imsPhoneCallTracker =
9981 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9982 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9983 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9984 + imsPhone.getMsisdn());
9985 }
9986 }
9987 } finally {
9988 Binder.restoreCallingIdentity(identity);
9989 }
9990 }
allenwtsu46dcc572020-01-08 18:24:03 +08009991
9992 /**
9993 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9994 *
9995 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9996 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9997 * before being read.
9998 */
9999 @Override
10000 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10001 isCompressed) {
10002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10003 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010004 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10005 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10006 }
10007 if (!isImsAvailableOnDevice()) {
10008 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10009 "IMS not available on device.");
10010 }
10011
10012 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010013 try {
Hui Wang761a6682020-10-31 05:12:53 +000010014 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10015 } finally {
10016 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010017 }
10018 }
zoey chene02881a2019-12-30 16:11:23 +080010019
10020 @Override
10021 public boolean isIccLockEnabled(int subId) {
10022 enforceReadPrivilegedPermission("isIccLockEnabled");
10023
10024 // Now that all security checks passes, perform the operation as ourselves.
10025 final long identity = Binder.clearCallingIdentity();
10026 try {
10027 Phone phone = getPhone(subId);
10028 if (phone != null && phone.getIccCard() != null) {
10029 return phone.getIccCard().getIccLockEnabled();
10030 } else {
10031 return false;
10032 }
10033 } finally {
10034 Binder.restoreCallingIdentity(identity);
10035 }
10036 }
10037
10038 /**
10039 * Set the ICC pin lock enabled or disabled.
10040 *
10041 * @return an integer representing the status of IccLock enabled or disabled in the following
10042 * three cases:
10043 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10044 * successfully.
10045 * - Positive number and zero for remaining password attempts.
10046 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10047 *
10048 */
10049 @Override
10050 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10051 enforceModifyPermission();
10052
10053 Phone phone = getPhone(subId);
10054 if (phone == null) {
10055 return 0;
10056 }
10057 // Now that all security checks passes, perform the operation as ourselves.
10058 final long identity = Binder.clearCallingIdentity();
10059 try {
10060 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10061 new Pair<Boolean, String>(enabled, password), phone, null);
10062 return attemptsRemaining;
10063
10064 } catch (Exception e) {
10065 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10066 } finally {
10067 Binder.restoreCallingIdentity(identity);
10068 }
10069 return 0;
10070 }
10071
10072 /**
10073 * Change the ICC password used in ICC pin lock.
10074 *
10075 * @return an integer representing the status of IccLock changed in the following three cases:
10076 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10077 * - Positive number and zero for remaining password attempts.
10078 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10079 *
10080 */
10081 @Override
10082 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10083 enforceModifyPermission();
10084
10085 Phone phone = getPhone(subId);
10086 if (phone == null) {
10087 return 0;
10088 }
10089 // Now that all security checks passes, perform the operation as ourselves.
10090 final long identity = Binder.clearCallingIdentity();
10091 try {
10092 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10093 new Pair<String, String>(oldPassword, newPassword), phone, null);
10094 return attemptsRemaining;
10095
10096 } catch (Exception e) {
10097 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 return 0;
10102 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010103
10104 /**
10105 * Request for receiving user activity notification
10106 */
10107 @Override
10108 public void requestUserActivityNotification() {
10109 if (!mNotifyUserActivity.get()
10110 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10111 mNotifyUserActivity.set(true);
10112 }
10113 }
10114
10115 /**
10116 * Called when userActivity is signalled in the power manager.
10117 * This is safe to call from any thread, with any window manager locks held or not.
10118 */
10119 @Override
10120 public void userActivity() {
10121 // ***************************************
10122 // * Inherited from PhoneWindowManager *
10123 // ***************************************
10124 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10125 // WITH ITS LOCKS HELD.
10126 //
10127 // This code must be VERY careful about the locks
10128 // it acquires.
10129 // In fact, the current code acquires way too many,
10130 // and probably has lurking deadlocks.
10131
10132 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10133 throw new SecurityException("Only the OS may call notifyUserActivity()");
10134 }
10135
10136 if (mNotifyUserActivity.getAndSet(false)) {
10137 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10138 USER_ACTIVITY_NOTIFICATION_DELAY);
10139 }
10140 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010141
10142 @Override
10143 public boolean canConnectTo5GInDsdsMode() {
10144 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10145 }
Jack Yud10cdd42020-09-28 20:28:01 -070010146
10147 @Override
10148 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10149 String callingFeatureId) {
10150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10151 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10152 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10153 }
10154
10155 Phone phone = getPhone(subId);
10156 if (phone == null) {
10157 throw new RuntimeException("phone is not available");
10158 }
10159 // Now that all security checks passes, perform the operation as ourselves.
10160 final long identity = Binder.clearCallingIdentity();
10161 try {
10162 return phone.getEquivalentHomePlmns();
10163 } finally {
10164 Binder.restoreCallingIdentity(identity);
10165 }
10166 }
Daniel Bright59e67312020-11-13 11:49:37 -080010167
10168 @Override
10169 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010170 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10171 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010172 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010173 if (radioInterfaceCapabilities == null) {
10174 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010175 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010176 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010177 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010178
Hui Wang641e81c2020-10-12 12:14:23 -070010179 @Override
10180 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10181 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010182 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10183 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10184 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10185 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10186 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010187 if (DBG) {
10188 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10189 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10190 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10191 }
10192
10193 if (!SubscriptionManager.isValidSubscriptionId(subId)
10194 || appType < TelephonyManager.APPTYPE_UNKNOWN
10195 || appType > TelephonyManager.APPTYPE_ISIM
10196 || nafUrl == null || securityProtocol == null || callback == null) {
10197 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10198 if (callback != null) {
10199 try {
10200 callback.onAuthenticationFailure(
10201 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10202 } catch (RemoteException exception) {
10203 log("Fail to notify onAuthenticationFailure due to " + exception);
10204 }
10205 return;
10206 }
10207 }
10208
10209 final long token = Binder.clearCallingIdentity();
10210 try {
10211 getGbaManager(subId).bootstrapAuthenticationRequest(
10212 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10213 forceBootStrapping, callback));
10214 } finally {
10215 Binder.restoreCallingIdentity(token);
10216 }
10217 }
10218
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010219 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010220 * Attempts to set the radio power state for all phones for thermal reason.
10221 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010222 * requested radio power state will actually be set. See {@link
10223 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10224 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010225 * @param enable {@code true} if trying to turn radio on.
10226 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10227 * false}.
10228 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010229 private boolean setRadioPowerForThermal(boolean enable) {
10230 boolean isPhoneAvailable = false;
10231 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10232 Phone phone = PhoneFactory.getPhone(i);
10233 if (phone != null) {
10234 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10235 isPhoneAvailable = true;
10236 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010237 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010238
10239 // return true if successfully informed the phone object about the thermal radio power
10240 // request.
10241 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010242 }
10243
10244 private int handleDataThrottlingRequest(int subId,
10245 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010246 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10247 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10248 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10249 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10250 throw new IllegalArgumentException("modem does not support data throttling");
10251 }
10252
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010253 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10254 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010255 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010256 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10257 }
10258
10259 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10260
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010261 if (isDataThrottlingSupported) {
10262 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010263 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010264 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10265 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10266 } else if (thermalMitigationResult
10267 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010268 log("Modem likely does not support data throttling on secondary carrier. Data " +
10269 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10270 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010271 }
10272 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010273 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010274
10275 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010276 }
10277
Jack Nudelman644b91a2021-03-12 14:09:48 -080010278 private static List<String> getThermalMitigationAllowlist(Context context) {
10279 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10280 for (String pckg : context.getResources()
10281 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10282 sThermalMitigationAllowlistedPackages.add(pckg);
10283 }
10284 }
10285
10286 return sThermalMitigationAllowlistedPackages;
10287 }
10288
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010289 private boolean isAnyPhoneInEmergencyState() {
10290 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10291 if (tm.isInEmergencyCall()) {
10292 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10293 return true;
10294 }
10295 for (Phone phone : PhoneFactory.getPhones()) {
10296 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10297 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10298 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10299 + phone.isInEcm());
10300 return true;
10301 }
10302 }
10303
10304 return false;
10305 }
10306
Jack Nudelman644b91a2021-03-12 14:09:48 -080010307 /**
10308 * Used by shell commands to add an authorized package name for thermal mitigation.
10309 * @param packageName name of package to be allowlisted
10310 * @param context
10311 */
10312 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10313 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10314 sThermalMitigationAllowlistedPackages.add(packageName);
10315 }
10316
10317 /**
10318 * Used by shell commands to remove an authorized package name for thermal mitigation.
10319 * @param packageName name of package to remove from allowlist
10320 * @param context
10321 */
10322 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10323 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10324 sThermalMitigationAllowlistedPackages.remove(packageName);
10325 }
10326
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010327 /**
10328 * Thermal mitigation request to control functionalities at modem.
10329 *
10330 * @param subId the id of the subscription.
10331 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010332 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010333 *
10334 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10335 */
10336 @Override
10337 @ThermalMitigationResult
10338 public int sendThermalMitigationRequest(
10339 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010340 ThermalMitigationRequest thermalMitigationRequest,
10341 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010342 enforceModifyPermission();
10343
Jack Nudelman644b91a2021-03-12 14:09:48 -080010344 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10345 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10346 .contains(callingPackage)) {
10347 throw new SecurityException("Calling package must be configured in the device config. "
10348 + "calling package: " + callingPackage);
10349 }
10350
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10352 final long identity = Binder.clearCallingIdentity();
10353
10354 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10355 try {
10356 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10357 switch (thermalMitigationAction) {
10358 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10359 thermalMitigationResult =
10360 handleDataThrottlingRequest(subId,
10361 thermalMitigationRequest.getDataThrottlingRequest());
10362 break;
10363 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10364 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10365 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10366 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10367 }
10368
10369 // Ensure that radio is on. If not able to power on due to phone being
10370 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010371 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010372 thermalMitigationResult =
10373 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10374 break;
10375 }
10376
10377 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10378 false);
10379 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10380 break;
10381 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10382 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10383 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10384 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10385 }
10386
10387 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10388 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010389 Phone phone = getPhone(subId);
10390 if (phone == null) {
10391 thermalMitigationResult =
10392 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10393 break;
10394 }
10395
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010396 TelephonyConnectionService service =
10397 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010398 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010399 Log.e(LOG_TAG, "An emergency call is pending");
10400 thermalMitigationResult =
10401 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10402 break;
10403 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010404 thermalMitigationResult =
10405 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10406 break;
10407 }
10408 } else {
10409 thermalMitigationResult =
10410 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10411 break;
10412 }
10413
10414 // Turn radio off. If not able to power off due to phone being unavailable,
10415 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010416 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010417 thermalMitigationResult =
10418 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10419 break;
10420 }
10421 thermalMitigationResult =
10422 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10423 break;
10424 default:
10425 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10426 + "not exist. Requested action: " + thermalMitigationAction);
10427 }
10428 } catch (IllegalArgumentException e) {
10429 throw e;
10430 } catch (Exception e) {
10431 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10432 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436
10437 if (DBG) {
10438 log("thermalMitigationRequest returning with thermalMitigationResult: "
10439 + thermalMitigationResult);
10440 }
10441
10442 return thermalMitigationResult;
10443 }
Hui Wang641e81c2020-10-12 12:14:23 -070010444
10445 /**
10446 * Set the GbaService Package Name that Telephony will bind to.
10447 *
10448 * @param subId The sim that the GbaService is associated with.
10449 * @param packageName The name of the package to be replaced with.
10450 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10451 */
10452 @Override
10453 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10454 enforceModifyPermission();
10455
10456 final long identity = Binder.clearCallingIdentity();
10457 try {
10458 return getGbaManager(subId).overrideServicePackage(packageName);
10459 } finally {
10460 Binder.restoreCallingIdentity(identity);
10461 }
10462 }
10463
10464 /**
10465 * Return the package name of the currently bound GbaService.
10466 *
10467 * @param subId The sim that the GbaService is associated with.
10468 * @return the package name of the GbaService configuration, null if GBA is not supported.
10469 */
10470 @Override
10471 public String getBoundGbaService(int subId) {
10472 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10473
10474 final long identity = Binder.clearCallingIdentity();
10475 try {
10476 return getGbaManager(subId).getServicePackage();
10477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
10481
10482 /**
10483 * Set the release time for telephony to unbind GbaService.
10484 *
10485 * @param subId The sim that the GbaService is associated with.
10486 * @param interval The release time to unbind GbaService by millisecond.
10487 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10488 */
10489 @Override
10490 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10491 enforceModifyPermission();
10492
10493 final long identity = Binder.clearCallingIdentity();
10494 try {
10495 return getGbaManager(subId).overrideReleaseTime(interval);
10496 } finally {
10497 Binder.restoreCallingIdentity(identity);
10498 }
10499 }
10500
10501 /**
10502 * Return the release time for telephony to unbind GbaService.
10503 *
10504 * @param subId The sim that the GbaService is associated with.
10505 * @return The release time to unbind GbaService by millisecond.
10506 */
10507 @Override
10508 public int getGbaReleaseTime(int subId) {
10509 enforceReadPrivilegedPermission("getGbaReleaseTime");
10510
10511 final long identity = Binder.clearCallingIdentity();
10512 try {
10513 return getGbaManager(subId).getReleaseTime();
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
10519 private GbaManager getGbaManager(int subId) {
10520 GbaManager instance = GbaManager.getInstance(subId);
10521 if (instance == null) {
10522 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10523 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10524 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10525 }
10526 return instance;
10527 }
Hui Wang761a6682020-10-31 05:12:53 +000010528
10529 /**
10530 * indicate whether the device and the carrier can support
10531 * RCS VoLTE single registration.
10532 */
10533 @Override
10534 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010535 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10536 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10537 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10538 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010539
10540 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10541 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10542 }
10543
10544 final long identity = Binder.clearCallingIdentity();
10545 try {
10546 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10547 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010548 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10549 if (isCapable != null) {
10550 return isCapable;
10551 }
Hui Wang761a6682020-10-31 05:12:53 +000010552 }
Hui Wang67af90e2021-06-04 16:57:15 -070010553 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10554 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010555 } finally {
10556 Binder.restoreCallingIdentity(identity);
10557 }
10558 }
10559
10560 /**
10561 * Register RCS provisioning callback.
10562 */
10563 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010564 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010565 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010566 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010567 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010568 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10569 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010570
10571 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10572 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10573 }
10574 if (!isImsAvailableOnDevice()) {
10575 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10576 "IMS not available on device.");
10577 }
10578
10579 final long identity = Binder.clearCallingIdentity();
10580 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010581 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010582 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010583 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10584 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010585 }
Hui Wang761a6682020-10-31 05:12:53 +000010586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
10590
10591 /**
10592 * Unregister RCS provisioning callback.
10593 */
10594 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010595 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010596 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010597 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010598 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010599 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10600 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010601
10602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10603 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10604 }
10605 if (!isImsAvailableOnDevice()) {
10606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10607 "IMS not available on device.");
10608 }
10609
10610 final long identity = Binder.clearCallingIdentity();
10611 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010612 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010613 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010614 } finally {
10615 Binder.restoreCallingIdentity(identity);
10616 }
10617 }
10618
10619 /**
10620 * trigger RCS reconfiguration.
10621 */
10622 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010623 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10624 "triggerRcsReconfiguration",
10625 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010626
10627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10628 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10629 }
10630 if (!isImsAvailableOnDevice()) {
10631 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10632 "IMS not available on device.");
10633 }
10634
10635 final long identity = Binder.clearCallingIdentity();
10636 try {
10637 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10638 } finally {
10639 Binder.restoreCallingIdentity(identity);
10640 }
10641 }
10642
10643 /**
10644 * Provide the client configuration parameters of the RCS application.
10645 */
10646 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010647 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10648 "setRcsClientConfiguration",
10649 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010650
10651 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10652 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10653 }
10654 if (!isImsAvailableOnDevice()) {
10655 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10656 "IMS not available on device.");
10657 }
10658
10659 final long identity = Binder.clearCallingIdentity();
10660
10661 try {
10662 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10663 if (configBinder == null) {
10664 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010665 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10666 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010667 } else {
10668 configBinder.setRcsClientConfiguration(rcc);
10669 }
joonhunshin3e154242021-09-17 06:33:39 +000010670
10671 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10672 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010673 } catch (RemoteException e) {
10674 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010675 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10676 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010677 } finally {
10678 Binder.restoreCallingIdentity(identity);
10679 }
10680 }
10681
10682 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010683 * Enables or disables the test mode for RCS VoLTE single registration.
10684 */
10685 @Override
10686 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10688 "setRcsSingleRegistrationTestModeEnabled");
10689
10690 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10691 }
10692
10693 /**
10694 * Gets the test mode for RCS VoLTE single registration.
10695 */
10696 @Override
10697 public boolean getRcsSingleRegistrationTestModeEnabled() {
10698 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10699 "getRcsSingleRegistrationTestModeEnabled");
10700
10701 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10702 }
10703
10704 /**
Hui Wang761a6682020-10-31 05:12:53 +000010705 * Overrides the config of RCS VoLTE single registration enabled for the device.
10706 */
10707 @Override
10708 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10709 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10710 "setDeviceSingleRegistrationEnabledOverride");
10711 enforceModifyPermission();
10712
10713 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10714 : Boolean.parseBoolean(enabledStr);
10715 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010716 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010717 }
10718
10719 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010720 * Sends a device to device communication message. Only usable via shell.
10721 * @param message message to send.
10722 * @param value message value.
10723 */
10724 @Override
10725 public void sendDeviceToDeviceMessage(int message, int value) {
10726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010727 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010728 enforceModifyPermission();
10729
10730 final long identity = Binder.clearCallingIdentity();
10731 try {
10732 TelephonyConnectionService service =
10733 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10734 if (service == null) {
10735 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10736 return;
10737 }
10738 service.sendTestDeviceToDeviceMessage(message, value);
10739 } finally {
10740 Binder.restoreCallingIdentity(identity);
10741 }
10742 }
10743
Tyler Gunnbabbda02021-02-10 11:05:02 -080010744 /**
10745 * Sets the specified device to device transport active.
10746 * @param transport The transport to set active.
10747 */
10748 @Override
10749 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10751 "setActiveDeviceToDeviceTransport");
10752 enforceModifyPermission();
10753
10754 final long identity = Binder.clearCallingIdentity();
10755 try {
10756 TelephonyConnectionService service =
10757 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10758 if (service == null) {
10759 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10760 return;
10761 }
10762 service.setActiveDeviceToDeviceTransport(transport);
10763 } finally {
10764 Binder.restoreCallingIdentity(identity);
10765 }
10766 }
Tyler Gunn92479152021-01-20 16:30:10 -080010767
Tyler Gunnd4339262021-05-03 14:46:49 -070010768 @Override
10769 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10771 "setDeviceToDeviceForceEnabled");
10772
10773 final long identity = Binder.clearCallingIdentity();
10774 try {
10775 Arrays.stream(PhoneFactory.getPhones()).forEach(
10776 p -> {
10777 Phone thePhone = p.getImsPhone();
10778 if (thePhone != null && thePhone instanceof ImsPhone) {
10779 ImsPhone imsPhone = (ImsPhone) thePhone;
10780 CallTracker tracker = imsPhone.getCallTracker();
10781 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10782 ImsPhoneCallTracker imsPhoneCallTracker =
10783 (ImsPhoneCallTracker) tracker;
10784 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10785 }
10786 }
10787 }
10788 );
10789 } finally {
10790 Binder.restoreCallingIdentity(identity);
10791 }
10792 }
10793
Tyler Gunn92479152021-01-20 16:30:10 -080010794 /**
Hui Wang761a6682020-10-31 05:12:53 +000010795 * Gets the config of RCS VoLTE single registration enabled for the device.
10796 */
10797 @Override
10798 public boolean getDeviceSingleRegistrationEnabled() {
10799 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10800 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10801 }
10802
10803 /**
10804 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10805 */
10806 @Override
10807 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10808 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10809 "setCarrierSingleRegistrationEnabledOverride");
10810 enforceModifyPermission();
10811
10812 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10813 : Boolean.parseBoolean(enabledStr);
10814 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10815 subId, enabled);
10816 }
10817
10818 /**
10819 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10820 */
10821 @Override
10822 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10823 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10824 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10825 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010826
10827 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010828 * Overrides the ims feature validation result
10829 */
10830 @Override
10831 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10833 "setImsFeatureValidationOverride");
10834
10835 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10836 : Boolean.parseBoolean(enabledStr);
10837 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10838 subId, enabled);
10839 }
10840
10841 /**
10842 * Gets the ims feature validation override value
10843 */
10844 @Override
10845 public boolean getImsFeatureValidationOverride(int subId) {
10846 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10847 "getImsFeatureValidationOverride");
10848 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10849 }
10850
10851 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010852 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10853 * their mobile plan.
10854 */
10855 @Override
10856 public String getMobileProvisioningUrl() {
10857 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10858 final long identity = Binder.clearCallingIdentity();
10859 try {
10860 return getDefaultPhone().getMobileProvisioningUrl();
10861 } finally {
10862 Binder.restoreCallingIdentity(identity);
10863 }
10864 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010865
James.cf Linbcdf8b32021-01-14 16:44:13 +080010866 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010867 * Get the EAB contact from the EAB database.
10868 */
10869 @Override
10870 public String getContactFromEab(String contact) {
10871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10872 enforceModifyPermission();
10873 final long identity = Binder.clearCallingIdentity();
10874 try {
10875 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10876 } finally {
10877 Binder.restoreCallingIdentity(identity);
10878 }
10879 }
10880
10881 /**
Calvin Pana1434322021-07-01 19:27:01 +080010882 * Get the EAB capability from the EAB database.
10883 */
10884 @Override
10885 public String getCapabilityFromEab(String contact) {
10886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10887 enforceModifyPermission();
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
10895
10896 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010897 * Remove the EAB contacts from the EAB database.
10898 */
10899 @Override
10900 public int removeContactFromEab(int subId, String contacts) {
10901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10902 enforceModifyPermission();
10903 final long identity = Binder.clearCallingIdentity();
10904 try {
10905 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10906 } finally {
10907 Binder.restoreCallingIdentity(identity);
10908 }
10909 }
10910
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010911 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010912 public boolean getDeviceUceEnabled() {
10913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10914 final long identity = Binder.clearCallingIdentity();
10915 try {
10916 return mApp.getDeviceUceEnabled();
10917 } finally {
10918 Binder.restoreCallingIdentity(identity);
10919 }
10920 }
10921
10922 @Override
10923 public void setDeviceUceEnabled(boolean isEnabled) {
10924 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10925 final long identity = Binder.clearCallingIdentity();
10926 try {
10927 mApp.setDeviceUceEnabled(isEnabled);
10928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
10932
Brad Ebinger14d467f2021-02-12 06:18:28 +000010933 /**
10934 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10935 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10936 */
10937 // Used for SHELL command only right now.
10938 @Override
10939 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10940 List<String> featureTags) {
10941 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10942 "addUceRegistrationOverrideShell");
10943 final long identity = Binder.clearCallingIdentity();
10944 try {
10945 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10946 new ArraySet<>(featureTags));
10947 } catch (ImsException e) {
10948 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10949 } finally {
10950 Binder.restoreCallingIdentity(identity);
10951 }
10952 }
10953
10954 /**
10955 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10956 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10957 */
10958 // Used for SHELL command only right now.
10959 @Override
10960 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10961 List<String> featureTags) {
10962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10963 "removeUceRegistrationOverrideShell");
10964 final long identity = Binder.clearCallingIdentity();
10965 try {
10966 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10967 new ArraySet<>(featureTags));
10968 } catch (ImsException e) {
10969 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10970 } finally {
10971 Binder.restoreCallingIdentity(identity);
10972 }
10973 }
10974
10975 /**
10976 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10977 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10978 */
10979 // Used for SHELL command only right now.
10980 @Override
10981 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10982 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10983 "clearUceRegistrationOverrideShell");
10984 final long identity = Binder.clearCallingIdentity();
10985 try {
10986 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10987 } catch (ImsException e) {
10988 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10989 } finally {
10990 Binder.restoreCallingIdentity(identity);
10991 }
10992 }
10993
10994 /**
10995 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10996 */
10997 // Used for SHELL command only right now.
10998 @Override
10999 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11001 "getLatestRcsContactUceCapabilityShell");
11002 final long identity = Binder.clearCallingIdentity();
11003 try {
11004 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11005 } catch (ImsException e) {
11006 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11007 } finally {
11008 Binder.restoreCallingIdentity(identity);
11009 }
11010 }
11011
11012 /**
11013 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11014 * device does not have an active PUBLISH.
11015 */
11016 // Used for SHELL command only right now.
11017 @Override
11018 public String getLastUcePidfXmlShell(int subId) {
11019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11020 final long identity = Binder.clearCallingIdentity();
11021 try {
11022 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11023 } catch (ImsException e) {
11024 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11025 } finally {
11026 Binder.restoreCallingIdentity(identity);
11027 }
11028 }
11029
James.cf Line8713a42021-04-29 16:04:26 +080011030 /**
11031 * Remove UCE requests cannot be sent to the network status.
11032 */
11033 // Used for SHELL command only right now.
11034 @Override
11035 public boolean removeUceRequestDisallowedStatus(int subId) {
11036 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11037 final long identity = Binder.clearCallingIdentity();
11038 try {
11039 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11040 } catch (ImsException e) {
11041 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11042 } finally {
11043 Binder.restoreCallingIdentity(identity);
11044 }
11045 }
11046
James.cf Lin18bb9002021-05-25 01:37:38 +080011047 /**
11048 * Remove UCE requests cannot be sent to the network status.
11049 */
11050 // Used for SHELL command only.
11051 @Override
11052 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11053 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11054 final long identity = Binder.clearCallingIdentity();
11055 try {
11056 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11057 } catch (ImsException e) {
11058 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11059 } finally {
11060 Binder.restoreCallingIdentity(identity);
11061 }
11062 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011063
James.cf Lin4b784aa2021-01-31 03:25:15 +080011064 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011065 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11066 String callingPackage) {
11067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11068 mApp, subId, "setSignalStrengthUpdateRequest");
11069
11070 final int callingUid = Binder.getCallingUid();
11071 // Verify that tha callingPackage belongs to the calling UID
11072 mApp.getSystemService(AppOpsManager.class)
11073 .checkPackage(callingUid, callingPackage);
11074
Rambo Wang3607f502021-02-01 21:51:40 -080011075 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011076
11077 final long identity = Binder.clearCallingIdentity();
11078 try {
11079 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11080 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11081
11082 if (result instanceof IllegalStateException) {
11083 throw (IllegalStateException) result;
11084 }
11085 } finally {
11086 Binder.restoreCallingIdentity(identity);
11087 }
11088 }
11089
11090 @Override
11091 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11092 String callingPackage) {
11093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11094 mApp, subId, "clearSignalStrengthUpdateRequest");
11095
11096 final int callingUid = Binder.getCallingUid();
11097 // Verify that tha callingPackage belongs to the calling UID
11098 mApp.getSystemService(AppOpsManager.class)
11099 .checkPackage(callingUid, callingPackage);
11100
11101 final long identity = Binder.clearCallingIdentity();
11102 try {
11103 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11104 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11105
11106 if (result instanceof IllegalStateException) {
11107 throw (IllegalStateException) result;
11108 }
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
11113
Rambo Wang3607f502021-02-01 21:51:40 -080011114 private static void validateSignalStrengthUpdateRequest(Context context,
11115 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011116 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11117 // phone/system process do not have further restriction on request
11118 return;
11119 }
11120
11121 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011122 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011123 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011124 context.enforceCallingOrSelfPermission(
11125 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11126 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011127 }
11128
11129 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11130 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11131 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11132 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11133 || info.isEnabled()) {
11134 throw new IllegalArgumentException(
11135 "Only system can set hide fields in SignalThresholdInfo");
11136 }
11137
11138 // Thresholds length for each RAN need in range. This has been validated in
11139 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11140 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11141 final int[] thresholds = info.getThresholds();
11142 Objects.requireNonNull(thresholds);
11143 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11144 || thresholds.length
11145 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11146 throw new IllegalArgumentException(
11147 "thresholds length is out of range: " + thresholds.length);
11148 }
11149 }
11150 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011151
11152 /**
11153 * Gets the current phone capability.
11154 *
11155 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11156 * @return the PhoneCapability which describes the data connection capability of modem.
11157 * It's used to evaluate possible phone config change, for example from single
11158 * SIM device to multi-SIM device.
11159 */
11160 @Override
11161 public PhoneCapability getPhoneCapability() {
11162 enforceReadPrivilegedPermission("getPhoneCapability");
11163 final long identity = Binder.clearCallingIdentity();
11164 try {
11165 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11166 } finally {
11167 Binder.restoreCallingIdentity(identity);
11168 }
11169 }
Michele Berionne5e411512020-11-13 02:36:59 +000011170
11171 /**
11172 * Prepare TelephonyManager for an unattended reboot. The reboot is
11173 * required to be done shortly after the API is invoked.
11174 */
11175 @Override
11176 @TelephonyManager.PrepareUnattendedRebootResult
11177 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011178 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011179 enforceRebootPermission();
11180
11181 final long identity = Binder.clearCallingIdentity();
11182 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011183 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011184 } finally {
11185 Binder.restoreCallingIdentity(identity);
11186 }
11187 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011188
11189 /**
11190 * Request to get the current slicing configuration including URSP rules and
11191 * NSSAIs (configured, allowed and rejected).
11192 *
11193 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11194 */
11195 @Override
11196 public void getSlicingConfig(ResultReceiver callback) {
11197 enforceReadPrivilegedPermission("getSlicingConfig");
11198
11199 final long identity = Binder.clearCallingIdentity();
11200 try {
11201 Phone phone = getDefaultPhone();
11202 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11203 } finally {
11204 Binder.restoreCallingIdentity(identity);
11205 }
11206 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011207
11208 /**
11209 * Register an IMS connection state callback
11210 */
11211 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011212 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11213 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011214 if (feature == ImsFeature.FEATURE_MMTEL) {
11215 // ImsMmTelManager
11216 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11217 TelephonyPermissions
11218 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11219 mApp, subId, "registerImsStateCallback");
11220 } else if (feature == ImsFeature.FEATURE_RCS) {
11221 // ImsRcsManager or SipDelegateManager
11222 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11223 Binder.getCallingUid(), "registerImsStateCallback",
11224 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11225 Manifest.permission.READ_PRECISE_PHONE_STATE,
11226 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11227 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11228 }
11229
11230 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11231 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11232 "IMS not available on device.");
11233 }
11234
11235 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11236 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11237 }
11238
11239 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11240 if (controller == null) {
11241 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11242 "IMS not available on device.");
11243 }
11244
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011245 if (callingPackage == null) {
11246 callingPackage = getCurrentPackageName();
11247 }
11248
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011249 final long token = Binder.clearCallingIdentity();
11250 try {
11251 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011252 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011253 } catch (ImsException e) {
11254 throw new ServiceSpecificException(e.getCode());
11255 } finally {
11256 Binder.restoreCallingIdentity(token);
11257 }
11258 }
11259
11260 /**
11261 * Unregister an IMS connection state callback
11262 */
11263 @Override
11264 public void unregisterImsStateCallback(IImsStateCallback cb) {
11265 final long token = Binder.clearCallingIdentity();
11266 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11267 if (controller == null) {
11268 return;
11269 }
11270 try {
11271 controller.unregisterImsStateCallback(cb);
11272 } finally {
11273 Binder.restoreCallingIdentity(token);
11274 }
11275 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011276
11277 /**
11278 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11279 *
11280 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11281 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11282 * SecurityException.
11283 * If there is current registered network this value will be same as the registered cell
11284 * identity. If the device goes out of service the previous cell identity is cached and
11285 * will be returned. If the cache age of the Cell identity is more than 24 hours
11286 * it will be cleared and null will be returned.
11287 *
11288 */
11289 @Override
11290 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11291 String callingFeatureId) {
11292 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11293 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11294 LocationAccessPolicy.checkLocationPermission(mApp,
11295 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11296 .setCallingPackage(callingPackage)
11297 .setCallingFeatureId(callingFeatureId)
11298 .setCallingPid(Binder.getCallingPid())
11299 .setCallingUid(Binder.getCallingUid())
11300 .setMethod("getLastKnownCellIdentity")
11301 .setLogAsInfo(true)
11302 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11303 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11304 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11305 .build());
11306
11307 boolean hasFinePermission =
11308 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11309 if (!hasFinePermission
11310 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11311 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11312 + "and BIND_CONNECTION_SERVICE permission.");
11313 }
11314
11315 final long identity = Binder.clearCallingIdentity();
11316 try {
11317 Phone phone = getPhone(subId);
11318 if (phone == null) return null;
11319 ServiceStateTracker sst = phone.getServiceStateTracker();
11320 if (sst == null) return null;
11321 return sst.getLastKnownCellIdentity();
11322 } finally {
11323 Binder.restoreCallingIdentity(identity);
11324 }
11325 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011326
11327 @Override
11328 public boolean isUsingNewDataStack() {
11329 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11330 return getDefaultPhone().isUsingNewDataStack();
11331 }
jimsun3b9ccac2021-10-26 15:01:23 +080011332
11333 /**
11334 * Sets the modem service class Name that Telephony will bind to.
11335 *
11336 * @param serviceName The class name of the modem service.
11337 * @return true if the operation is succeed, otherwise false.
11338 */
11339 public boolean setModemService(String serviceName) {
11340 Log.d(LOG_TAG, "setModemService - " + serviceName);
11341 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11343 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11344 "setModemService");
11345 return mPhoneConfigurationManager.setModemService(serviceName);
11346 }
11347
11348 /**
11349 * Return the class name of the currently bounded modem service.
11350 *
11351 * @return the class name of the modem service.
11352 */
11353 public String getModemService() {
11354 String result;
11355 Log.d(LOG_TAG, "getModemService");
11356 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11357 TelephonyPermissions
11358 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11359 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11360 "getModemService");
11361 result = mPhoneConfigurationManager.getModemService();
11362 Log.d(LOG_TAG, "result = " + result);
11363 return result;
11364 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011365
11366 @Override
11367 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11368 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11369 mApp.enforceCallingOrSelfPermission(
11370 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11372
11373 final long identity = Binder.clearCallingIdentity();
11374 try {
11375 Phone phone = getPhone(subId);
11376 if (phone == null) return;
11377 phone.setVoiceServiceStateOverride(hasService);
11378 } finally {
11379 Binder.restoreCallingIdentity(identity);
11380 }
11381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011382}