blob: 161690d8aecedfe87ac306079bed8d7aad06589f [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;
Amith Yamasani6e118872016-02-19 12:53:51 -080044import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070075import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080076import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080077import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070078import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080079import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070080import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080081import android.telephony.CellIdentityCdma;
82import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070084import android.telephony.CellInfoGsm;
85import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070086import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070088import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070089import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070090import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080091import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070094import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080095import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080096import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800100import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800101import android.telephony.SignalStrengthUpdateRequest;
102import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800103import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800105import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800110import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000113import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700114import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800116import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800117import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800118import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700119import android.telephony.gba.GbaAuthRequest;
120import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700121import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000124import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700125import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700126import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800127import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700128import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700132import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800134import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800136import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700139import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800141import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Andrew Lee312e8172014-10-23 17:01:36 -0700143import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800144import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800145import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800146import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700149import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700150import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800151import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700156import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800157import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800158import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800159import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700160import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000161import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800163import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800166import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700167import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700168import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700169import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700171import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800172import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700173import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700174import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700175import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700176import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800177import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800178import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700179import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700180import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700181import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800182import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800183import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700185import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700187import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800188import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700189import com.android.internal.telephony.imsphone.ImsPhone;
190import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000191import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800192import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700193import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800195import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700198import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000201import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800202import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000203import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800204import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700205import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700206import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800207import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800208import com.android.phone.callcomposer.CallComposerPictureManager;
209import com.android.phone.callcomposer.CallComposerPictureTransfer;
210import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700211import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700212import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800213import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700215import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800216import com.android.services.telephony.TelecomAccountRegistry;
217import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800218import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800219
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700221import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.IOException;
223import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800226import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000227import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800228import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800229import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800230import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100231import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700233import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800235import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800237import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800238import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240/**
241 * Implementation of the ITelephony interface.
242 */
Santos Cordon117fee72014-05-16 17:56:12 -0700243public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244 private static final String LOG_TAG = "PhoneInterfaceManager";
245 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
246 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800247 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
249 // Message codes used with mMainThreadHandler
250 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700251 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
252 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700253 private static final int CMD_OPEN_CHANNEL = 9;
254 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
255 private static final int CMD_CLOSE_CHANNEL = 11;
256 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800257 private static final int CMD_NV_READ_ITEM = 13;
258 private static final int EVENT_NV_READ_ITEM_DONE = 14;
259 private static final int CMD_NV_WRITE_ITEM = 15;
260 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
261 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
262 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_RESET_MODEM_CONFIG = 19;
264 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800265 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
266 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800267 private static final int CMD_SEND_ENVELOPE = 25;
268 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000269 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
270 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700271 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
272 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
273 private static final int CMD_EXCHANGE_SIM_IO = 31;
274 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800275 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
276 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700277 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
278 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700279 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
280 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700281 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
282 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
283 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
284 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700285 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
286 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
287 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
288 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700289 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800290 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
291 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000292 private static final int CMD_SWITCH_SLOTS = 50;
293 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700294 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
295 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
296 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
297 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
298 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
299 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
300 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
301 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700302 private static final int CMD_GET_ALL_CELL_INFO = 60;
303 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
304 private static final int CMD_GET_CELL_LOCATION = 62;
305 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700306 private static final int CMD_MODEM_REBOOT = 64;
307 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700308 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
309 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800310 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
311 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700312 private static final int CMD_GET_MODEM_STATUS = 70;
313 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700314 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
315 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700316 private static final int CMD_ERASE_MODEM_CONFIG = 74;
317 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800318 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
319 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
320 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
321 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800322 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
323 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800324 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800325 private static final int CMD_GET_CALL_FORWARDING = 83;
326 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
327 private static final int CMD_SET_CALL_FORWARDING = 85;
328 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
329 private static final int CMD_GET_CALL_WAITING = 87;
330 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
331 private static final int CMD_SET_CALL_WAITING = 89;
332 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700333 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
334 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
335 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
336 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700337 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
338 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800339 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
340 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800341 private static final int CMD_SET_DATA_THROTTLING = 99;
342 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800343 private static final int CMD_SET_SIM_POWER = 101;
344 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800345 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
346 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
347 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
348 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800349 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
350 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000351 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800352 private static final int CMD_GET_SLICING_CONFIG = 110;
353 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800354 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700355 private static final int CMD_ENABLE_VONR = 113;
356 private static final int EVENT_ENABLE_VONR_DONE = 114;
357 private static final int CMD_IS_VONR_ENABLED = 115;
358 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800360 // Parameters of select command.
361 private static final int SELECT_COMMAND = 0xA4;
362 private static final int SELECT_P1 = 0x04;
363 private static final int SELECT_P2 = 0;
364 private static final int SELECT_P3 = 0x10;
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 /** The singleton instance. */
367 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800368 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800372 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700373 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700375 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800377 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700379 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800380 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 /** User Activity */
383 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
385
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700386 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
387
Derek Tan97ebb422014-09-05 16:55:38 -0700388 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
389 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800390 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800391 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700392
Michelecea4cf22018-12-21 15:00:11 -0800393 // String to store multi SIM allowed
394 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
395
Derek Tan740e1672017-06-27 14:56:27 -0700396 // The AID of ISD-R.
397 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
398
yinxub1bed742017-04-17 11:45:04 -0700399 private NetworkScanRequestTracker mNetworkScanRequestTracker;
400
David Kelly5e06a7f2018-03-12 14:10:59 +0000401 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
402 private static final int MANUFACTURER_CODE_LENGTH = 8;
403
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800405 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406
Derek Tan89e89d42014-07-08 17:00:10 -0700407 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700408 * Experiment flag to enable erase modem config on reset network, default value is false
409 */
410 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
411 "reset_network_erase_modem_config_enabled";
412
Rambo Wang0f050d82021-02-12 11:43:36 -0800413 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjsb6c87872021-09-27 15:34:44 +0000414 /**
415 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
416 * one ICCID active at the same time.
417 * Apps should use below API signatures if targeting SDK is T and beyond.
418 *
419 * @hide
420 */
421 @ChangeId
422 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
423 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800424
Naina Nallurid63128d2019-09-17 14:10:30 -0700425 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class IccAPDUArgument {
429 public int channel, cla, command, p1, p2, p3;
430 public String data;
431
432 public IccAPDUArgument(int channel, int cla, int command,
433 int p1, int p2, int p3, String data) {
434 this.channel = channel;
435 this.cla = cla;
436 this.command = command;
437 this.p1 = p1;
438 this.p2 = p2;
439 this.p3 = p3;
440 this.data = data;
441 }
442 }
443
444 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class ManualNetworkSelectionArgument {
448 public OperatorInfo operatorInfo;
449 public boolean persistSelection;
450
451 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
452 this.operatorInfo = operatorInfo;
453 this.persistSelection = persistSelection;
454 }
455 }
456
457 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
459 * request after sending. The main thread will notify the request when it is complete.
460 */
461 private static final class MainThreadRequest {
462 /** The argument to use for the request */
463 public Object argument;
464 /** The result of the request that is run on the main thread */
465 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800466 // The subscriber id that this request applies to. Defaults to
467 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
468 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469
Nathan Harold92bed182018-10-12 18:16:49 -0700470 // In cases where subId is unavailable, the caller needs to specify the phone.
471 public Phone phone;
472
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 public WorkSource workSource;
474
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 public MainThreadRequest(Object argument) {
476 this.argument = argument;
477 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800478
Nathan Harold92bed182018-10-12 18:16:49 -0700479 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
480 this.argument = argument;
481 if (phone != null) {
482 this.phone = phone;
483 }
484 this.workSource = workSource;
485 }
486
vagdeviaf9a5b92018-08-15 16:01:53 -0700487 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800489 if (subId != null) {
490 this.subId = subId;
491 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700492 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 }
495
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800496 private static final class IncomingThirdPartyCallArgs {
497 public final ComponentName component;
498 public final String callId;
499 public final String callerDisplayName;
500
501 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
502 String callerDisplayName) {
503 this.component = component;
504 this.callId = callId;
505 this.callerDisplayName = callerDisplayName;
506 }
507 }
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 /**
510 * A handler that processes messages on the main thread in the phone process. Since many
511 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
512 * inbound binder threads to the main thread in the phone process. The Binder thread
513 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
514 * on, which will be notified when the operation completes and will contain the result of the
515 * request.
516 *
517 * <p>If a MainThreadRequest object is provided in the msg.obj field,
518 * note that request.result must be set to something non-null for the calling thread to
519 * unblock.
520 */
521 private final class MainThreadHandler extends Handler {
522 @Override
523 public void handleMessage(Message msg) {
524 MainThreadRequest request;
525 Message onCompleted;
526 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000527 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800529 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
531 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 case CMD_HANDLE_USSD_REQUEST: {
533 request = (MainThreadRequest) msg.obj;
534 final Phone phone = getPhoneFromRequest(request);
535 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
536 String ussdRequest = ussdObject.first;
537 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700538
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 if (!isUssdApiAllowed(request.subId)) {
540 // Carrier does not support use of this API, return failure.
541 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
542 UssdResponse response = new UssdResponse(ussdRequest, null);
543 Bundle returnData = new Bundle();
544 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
545 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700546
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 request.result = true;
548 notifyRequester(request);
549 return;
550 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700551
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 try {
553 request.result = phone != null
554 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
555 } catch (CallStateException cse) {
556 request.result = false;
557 }
558 // Wake up the requesting thread
559 notifyRequester(request);
560 break;
pkanwar32d516d2016-10-14 19:37:38 -0700561 }
562
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700565 final Phone phone = getPhoneFromRequest(request);
566 request.result = phone != null ?
567 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
568 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000577 uiccPort = getUiccPortFromRequest(request);
578 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 loge("iccTransmitApduLogicalChannel: No UICC");
580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
584 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000585 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument.channel, iccArgument.cla, iccArgument.command,
587 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
597 } else {
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800601 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800603 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
605 loge("iccTransmitApduLogicalChannel: Unknown exception");
606 }
607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
613 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000614 uiccPort = getUiccPortFromRequest(request);
615 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 loge("iccTransmitApduBasicChannel: No UICC");
617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 } else {
620 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
621 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000622 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
624 iccArgument.p3, iccArgument.data, onCompleted);
625 }
626 break;
627
628 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
633 } else {
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
635 if (ar.result == null) {
636 loge("iccTransmitApduBasicChannel: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("iccTransmitApduBasicChannel: CommandException: " +
639 ar.exception);
640 } else {
641 loge("iccTransmitApduBasicChannel: Unknown exception");
642 }
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 break;
646
647 case CMD_EXCHANGE_SIM_IO:
648 request = (MainThreadRequest) msg.obj;
649 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort = getUiccPortFromRequest(request);
651 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 loge("iccExchangeSimIO: No UICC");
653 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
657 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
660 iccArgument.data, onCompleted);
661 }
662 break;
663
664 case EVENT_EXCHANGE_SIM_IO_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
667 if (ar.exception == null && ar.result != null) {
668 request.result = ar.result;
669 } else {
670 request.result = new IccIoResult(0x6f, 0, (byte[])null);
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 break;
674
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 case CMD_SEND_ENVELOPE:
676 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000677 uiccPort = getUiccPortFromRequest(request);
678 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 loge("sendEnvelopeWithStatus: No UICC");
680 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
688 case EVENT_SEND_ENVELOPE_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800693 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700694 request.result = new IccIoResult(0x6F, 0, (byte[])null);
695 if (ar.result == null) {
696 loge("sendEnvelopeWithStatus: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("sendEnvelopeWithStatus: CommandException: " +
699 ar.exception);
700 } else {
701 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
702 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 break;
706
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 case CMD_OPEN_CHANNEL:
708 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800710 IccLogicalChannelRequest openChannelRequest =
711 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700713 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800714 request.result = new IccOpenLogicalChannelResponse(-1,
715 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700717 } else {
718 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800719 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
720 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 break;
723
724 case EVENT_OPEN_CHANNEL_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 int[] result = (int[]) ar.result;
730 int channelId = result[0];
731 byte[] selectResponse = null;
732 if (result.length > 1) {
733 selectResponse = new byte[result.length - 1];
734 for (int i = 1; i < result.length; ++i) {
735 selectResponse[i - 1] = (byte) result[i];
736 }
737 }
738 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700739 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 if (ar.result == null) {
742 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 if (ar.exception != null) {
745 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
746 }
747
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700748 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700749 if (ar.exception instanceof CommandException) {
750 CommandException.Error error =
751 ((CommandException) (ar.exception)).getCommandError();
752 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700753 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700754 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700755 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700756 }
757 }
758 openChannelResp = new IccOpenLogicalChannelResponse(
759 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700761 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 break;
764
765 case CMD_CLOSE_CHANNEL:
766 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000767 uiccPort = getUiccPortFromRequest(request);
768 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900770 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 } else {
773 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000774 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 break;
777
778 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800779 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
780 break;
781
782 case CMD_NV_READ_ITEM:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
786 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800787 break;
788
789 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800792 if (ar.exception == null && ar.result != null) {
793 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700794 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800795 request.result = "";
796 if (ar.result == null) {
797 loge("nvReadItem: Empty response");
798 } else if (ar.exception instanceof CommandException) {
799 loge("nvReadItem: CommandException: " +
800 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800802 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 }
804 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 break;
807
Jake Hambye994d462014-02-03 13:10:13 -0800808 case CMD_NV_WRITE_ITEM:
809 request = (MainThreadRequest) msg.obj;
810 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
811 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800812 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700813 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800814 break;
815
816 case EVENT_NV_WRITE_ITEM_DONE:
817 handleNullReturnEvent(msg, "nvWriteItem");
818 break;
819
820 case CMD_NV_WRITE_CDMA_PRL:
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800823 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800824 break;
825
826 case EVENT_NV_WRITE_CDMA_PRL_DONE:
827 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
828 break;
829
chen xu6dac5ab2018-10-26 17:39:23 -0700830 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800831 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700832 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800833 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
chen xu6dac5ab2018-10-26 17:39:23 -0700836 case EVENT_RESET_MODEM_CONFIG_DONE:
837 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800838 break;
839
Sooraj Sasindran37444802020-08-11 10:40:43 -0700840 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
843 request);
844 Phone phone = getPhoneFromRequest(request);
845 if (phone != null) {
846 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
847 } else {
848 loge("isNRDualConnectivityEnabled: No phone object");
849 request.result = false;
850 notifyRequester(request);
851 }
852 break;
853 }
854
855 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null && ar.result != null) {
859 request.result = ar.result;
860 } else {
861 // request.result must be set to something non-null
862 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700863 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700864 request.result = ar.result;
865 } else {
866 request.result = false;
867 }
868 if (ar.result == null) {
869 loge("isNRDualConnectivityEnabled: Empty response");
870 } else if (ar.exception instanceof CommandException) {
871 loge("isNRDualConnectivityEnabled: CommandException: "
872 + ar.exception);
873 } else {
874 loge("isNRDualConnectivityEnabled: Unknown exception");
875 }
876 }
877 notifyRequester(request);
878 break;
879
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700880 case CMD_IS_VONR_ENABLED: {
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
883 request);
884 Phone phone = getPhoneFromRequest(request);
885 if (phone != null) {
886 phone.isVoNrEnabled(onCompleted, request.workSource);
887 } else {
888 loge("isVoNrEnabled: No phone object");
889 request.result = false;
890 notifyRequester(request);
891 }
892 break;
893 }
894
895 case EVENT_IS_VONR_ENABLED_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result;
900 } else {
901 // request.result must be set to something non-null
902 // for the calling thread to unblock
903 if (ar.result != null) {
904 request.result = ar.result;
905 } else {
906 request.result = false;
907 }
908 if (ar.result == null) {
909 loge("isVoNrEnabled: Empty response");
910 } else if (ar.exception instanceof CommandException) {
911 loge("isVoNrEnabled: CommandException: "
912 + ar.exception);
913 } else {
914 loge("isVoNrEnabled: Unknown exception");
915 }
916 }
917 notifyRequester(request);
918 break;
919
Sooraj Sasindran37444802020-08-11 10:40:43 -0700920 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
921 request = (MainThreadRequest) msg.obj;
922 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
923 Phone phone = getPhoneFromRequest(request);
924 if (phone != null) {
925 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
926 request.workSource);
927 } else {
928 loge("enableNrDualConnectivity: No phone object");
929 request.result =
930 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
931 notifyRequester(request);
932 }
933 break;
934 }
935
936 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
937 ar = (AsyncResult) msg.obj;
938 request = (MainThreadRequest) ar.userObj;
939 if (ar.exception == null) {
940 request.result =
941 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
942 } else {
943 request.result =
944 TelephonyManager
945 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
946 if (ar.exception instanceof CommandException) {
947 CommandException.Error error =
948 ((CommandException) (ar.exception)).getCommandError();
949 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
950 request.result =
951 TelephonyManager
952 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000953 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
954 request.result =
955 TelephonyManager
956 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700957 }
958 loge("enableNrDualConnectivity" + ": CommandException: "
959 + ar.exception);
960 } else {
961 loge("enableNrDualConnectivity" + ": Unknown exception");
962 }
963 }
964 notifyRequester(request);
965 break;
966 }
967
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700968 case CMD_ENABLE_VONR: {
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
971 Phone phone = getPhoneFromRequest(request);
972 if (phone != null) {
973 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
974 request.workSource);
975 } else {
976 loge("setVoNrEnabled: No phone object");
977 request.result =
978 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_ENABLE_VONR_DONE: {
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null) {
988 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
989 } else {
990 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
991 if (ar.exception instanceof CommandException) {
992 CommandException.Error error =
993 ((CommandException) (ar.exception)).getCommandError();
994 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
995 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
996 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
997 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
998 } else {
999 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1000 }
1001 loge("setVoNrEnabled" + ": CommandException: "
1002 + ar.exception);
1003 } else {
1004 loge("setVoNrEnabled" + ": Unknown exception");
1005 }
1006 }
1007 notifyRequester(request);
1008 break;
1009 }
1010
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001013 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1014 request);
1015 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 break;
1017
SongFerngWang3ef3e072020-12-21 16:41:52 +08001018 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
1021 if (ar.exception == null && ar.result != null) {
1022 request.result = ar.result; // Integer
1023 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301024 // request.result must be set to something non-null
1025 // for the calling thread to unblock
1026 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001028 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 loge("getAllowedNetworkTypesBitmask: CommandException: "
1031 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001033 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 }
1035 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001036 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001037 break;
1038
SongFerngWang3ef3e072020-12-21 16:41:52 +08001039 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001040 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001041 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1042 request);
1043 Pair<Integer, Long> reasonWithNetworkTypes =
1044 (Pair<Integer, Long>) request.argument;
1045 getPhoneFromRequest(request).setAllowedNetworkTypes(
1046 reasonWithNetworkTypes.first,
1047 reasonWithNetworkTypes.second,
1048 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001049 break;
1050
SongFerngWang3ef3e072020-12-21 16:41:52 +08001051 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1052 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001053 break;
1054
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001055 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1056 request = (MainThreadRequest)msg.obj;
1057 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001058 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001059 break;
1060
1061 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1062 ar = (AsyncResult)msg.obj;
1063 request = (MainThreadRequest)ar.userObj;
1064 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001065 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001066 break;
1067
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001068 case CMD_SET_VOICEMAIL_NUMBER:
1069 request = (MainThreadRequest) msg.obj;
1070 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1071 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001072 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1073 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001074 break;
1075
1076 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1077 handleNullReturnEvent(msg, "setVoicemailNumber");
1078 break;
1079
Stuart Scott54788802015-03-30 13:18:01 -07001080 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1081 request = (MainThreadRequest) msg.obj;
1082 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1083 request);
1084 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1085 break;
1086
1087 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1088 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1089 break;
1090
Shishir Agrawal302c8692015-06-19 13:49:39 -07001091 case CMD_PERFORM_NETWORK_SCAN:
1092 request = (MainThreadRequest) msg.obj;
1093 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1094 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1095 break;
1096
Hall Liu27d24262020-09-18 19:04:59 -07001097 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001100 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1101 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1102 request.argument;
1103 int callForwardingReason = args.first;
1104 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001105 break;
Hall Liu27d24262020-09-18 19:04:59 -07001106 }
1107 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001110 TelephonyManager.CallForwardingInfoCallback callback =
1111 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1112 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001113 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001114 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001115 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1116 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1117 // Service Class is a bit mask per 3gpp 27.007. Search for
1118 // any service for voice call.
1119 if ((callForwardInfo.serviceClass
1120 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001121 callForwardingInfo = new CallForwardingInfo(
1122 callForwardInfo.status
1123 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001124 callForwardInfo.reason,
1125 callForwardInfo.number,
1126 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001127 break;
1128 }
1129 }
1130 // Didn't find a call forward info for voice call.
1131 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001132 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1133 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 }
Hall Liu27d24262020-09-18 19:04:59 -07001135 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 } else {
1137 if (ar.result == null) {
1138 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1139 }
1140 if (ar.exception != null) {
1141 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1142 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001143 int errorCode = TelephonyManager
1144 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001145 if (ar.exception instanceof CommandException) {
1146 CommandException.Error error =
1147 ((CommandException) (ar.exception)).getCommandError();
1148 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001149 errorCode = TelephonyManager
1150 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001152 errorCode = TelephonyManager
1153 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001154 }
1155 }
Hall Liu27d24262020-09-18 19:04:59 -07001156 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001157 }
Shuo Qian4a594052020-01-23 11:59:30 -08001158 break;
Hall Liu27d24262020-09-18 19:04:59 -07001159 }
Shuo Qian4a594052020-01-23 11:59:30 -08001160
Hall Liu27d24262020-09-18 19:04:59 -07001161 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001162 request = (MainThreadRequest) msg.obj;
1163 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001164 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001165 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001166 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1167 request.argument).first;
1168 request.phone.setCallForwardingOption(
1169 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001170 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001171 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001172 callForwardingInfoToSet.getReason(),
1173 callForwardingInfoToSet.getNumber(),
1174 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1175 break;
Hall Liu27d24262020-09-18 19:04:59 -07001176 }
Shuo Qian4a594052020-01-23 11:59:30 -08001177
Hall Liu27d24262020-09-18 19:04:59 -07001178 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001181 Consumer<Integer> callback =
1182 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1183 request.argument).second;
1184 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001186 int errorCode = TelephonyManager.CallForwardingInfoCallback
1187 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001188 if (ar.exception instanceof CommandException) {
1189 CommandException.Error error =
1190 ((CommandException) (ar.exception)).getCommandError();
1191 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001192 errorCode = TelephonyManager.CallForwardingInfoCallback
1193 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001194 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001195 errorCode = TelephonyManager.CallForwardingInfoCallback
1196 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001197 }
1198 }
1199 callback.accept(errorCode);
1200 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001201 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203 break;
Hall Liu27d24262020-09-18 19:04:59 -07001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205
Hall Liu27d24262020-09-18 19:04:59 -07001206 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1209 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1210 break;
Hall Liu27d24262020-09-18 19:04:59 -07001211 }
Shuo Qian4a594052020-01-23 11:59:30 -08001212
Hall Liu27d24262020-09-18 19:04:59 -07001213 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001214 ar = (AsyncResult) msg.obj;
1215 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001216 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1218 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001219 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001220 // Service Class is a bit mask per 3gpp 27.007.
1221 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001222 if (callForwardResults.length > 1
1223 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001224 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001225 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001226 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1227 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001229 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001230 }
1231 } else {
1232 if (ar.result == null) {
1233 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1234 }
1235 if (ar.exception != null) {
1236 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1237 }
1238 if (ar.exception instanceof CommandException) {
1239 CommandException.Error error =
1240 ((CommandException) (ar.exception)).getCommandError();
1241 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1242 callForwardingStatus =
1243 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1244 }
1245 }
1246 }
Hall Liu27d24262020-09-18 19:04:59 -07001247 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001254 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1255 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001256 break;
Hall Liu27d24262020-09-18 19:04:59 -07001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258
Hall Liu27d24262020-09-18 19:04:59 -07001259 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 ar = (AsyncResult) msg.obj;
1261 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001262 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1263 Consumer<Integer> callback =
1264 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1265 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001266 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001267 if (ar.exception instanceof CommandException) {
1268 CommandException.Error error =
1269 ((CommandException) (ar.exception)).getCommandError();
1270 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1271 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1272 } else {
1273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1274 }
1275 } else {
1276 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1277 }
1278 } else {
1279 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1280 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001281 }
Shuo Qian4a594052020-01-23 11:59:30 -08001282 break;
Hall Liu27d24262020-09-18 19:04:59 -07001283 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001284 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1285 ar = (AsyncResult) msg.obj;
1286 request = (MainThreadRequest) ar.userObj;
1287 CellNetworkScanResult cellScanResult;
1288 if (ar.exception == null && ar.result != null) {
1289 cellScanResult = new CellNetworkScanResult(
1290 CellNetworkScanResult.STATUS_SUCCESS,
1291 (List<OperatorInfo>) ar.result);
1292 } else {
1293 if (ar.result == null) {
1294 loge("getCellNetworkScanResults: Empty response");
1295 }
1296 if (ar.exception != null) {
1297 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1298 }
1299 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1300 if (ar.exception instanceof CommandException) {
1301 CommandException.Error error =
1302 ((CommandException) (ar.exception)).getCommandError();
1303 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1304 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1305 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1306 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1307 }
1308 }
1309 cellScanResult = new CellNetworkScanResult(errorCode, null);
1310 }
1311 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001312 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001313 break;
1314
1315 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1316 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001317 ManualNetworkSelectionArgument selArg =
1318 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001319 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1320 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001321 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1322 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001323 break;
1324
1325 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
1328 if (ar.exception == null) {
1329 request.result = true;
1330 } else {
1331 request.result = false;
1332 loge("setNetworkSelectionModeManual " + ar.exception);
1333 }
1334 notifyRequester(request);
1335 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001336 break;
1337
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001338 case CMD_GET_MODEM_ACTIVITY_INFO:
1339 request = (MainThreadRequest) msg.obj;
1340 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001341 if (defaultPhone != null) {
1342 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001343 } else {
1344 ResultReceiver result = (ResultReceiver) request.argument;
1345 Bundle bundle = new Bundle();
1346 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001347 new ModemActivityInfo(0, 0, 0,
1348 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001349 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001350 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001351 break;
1352
Hall Liud0f208c2020-10-14 16:54:44 -07001353 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001356 ResultReceiver result = (ResultReceiver) request.argument;
1357
Hall Liud0f208c2020-10-14 16:54:44 -07001358 ModemActivityInfo ret = null;
1359 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001360 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001361 // Update the last modem activity info and the result of the request.
1362 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1363 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001364 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001365 int[] txTimeMs = info.getTransmitTimeMillis();
1366 int[] lastModemTxTimeMs = mLastModemActivityInfo
1367 .getTransmitTimeMillis();
1368 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1369 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1370 }
Hall Liu49656c02020-10-09 19:00:11 -07001371 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001372 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1373 + mLastModemActivityInfo.getSleepTimeMillis());
1374 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1375 + mLastModemActivityInfo.getIdleTimeMillis());
1376 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1377 mLastModemActivityInfo.setReceiveTimeMillis(
1378 info.getReceiveTimeMillis()
1379 + mLastModemActivityInfo.getReceiveTimeMillis());
1380 }
Hall Liu49656c02020-10-09 19:00:11 -07001381 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001382 mLastModemActivityInfo.getSleepTimeMillis(),
1383 mLastModemActivityInfo.getIdleTimeMillis(),
1384 mLastModemActivityInfo.getTransmitTimeMillis(),
1385 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001386 } else {
1387 if (ar.result == null) {
1388 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001389 error = TelephonyManager.ModemActivityInfoException
1390 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001391 } else if (ar.exception instanceof CommandException) {
1392 loge("queryModemActivityInfo: CommandException: " +
1393 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001394 error = TelephonyManager.ModemActivityInfoException
1395 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001396 } else {
1397 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001398 error = TelephonyManager.ModemActivityInfoException
1399 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001400 }
1401 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001402 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001403 if (ret != null) {
1404 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1405 } else {
1406 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1407 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001409 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001411 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001412
Meng Wang1a7c35a2016-05-05 20:56:15 -07001413 case CMD_SET_ALLOWED_CARRIERS:
1414 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001415 CarrierRestrictionRules argument =
1416 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001418 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001419 break;
1420
1421 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 if (ar.exception == null && ar.result != null) {
1425 request.result = ar.result;
1426 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001427 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1428 if (ar.exception instanceof CommandException) {
1429 loge("setAllowedCarriers: CommandException: " + ar.exception);
1430 CommandException.Error error =
1431 ((CommandException) (ar.exception)).getCommandError();
1432 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1433 request.result =
1434 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1435 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001436 } else {
1437 loge("setAllowedCarriers: Unknown exception");
1438 }
1439 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001440 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001441 break;
1442
1443 case CMD_GET_ALLOWED_CARRIERS:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001446 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001447 break;
1448
1449 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 if (ar.exception == null && ar.result != null) {
1453 request.result = ar.result;
1454 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001455 request.result = new IllegalStateException(
1456 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001457 if (ar.result == null) {
1458 loge("getAllowedCarriers: Empty response");
1459 } else if (ar.exception instanceof CommandException) {
1460 loge("getAllowedCarriers: CommandException: " +
1461 ar.exception);
1462 } else {
1463 loge("getAllowedCarriers: Unknown exception");
1464 }
1465 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001466 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001467 break;
1468
Nathan Haroldb3014052017-01-25 15:57:32 -08001469 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1470 ar = (AsyncResult) msg.obj;
1471 request = (MainThreadRequest) ar.userObj;
1472 if (ar.exception == null && ar.result != null) {
1473 request.result = ar.result;
1474 } else {
1475 request.result = new IllegalArgumentException(
1476 "Failed to retrieve Forbidden Plmns");
1477 if (ar.result == null) {
1478 loge("getForbiddenPlmns: Empty response");
1479 } else {
1480 loge("getForbiddenPlmns: Unknown exception");
1481 }
1482 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001483 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001484 break;
1485
1486 case CMD_GET_FORBIDDEN_PLMNS:
1487 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001488 uiccPort = getUiccPortFromRequest(request);
1489 if (uiccPort == null) {
1490 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001491 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001492 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001493 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001494 break;
1495 }
1496 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001497 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001498 if (uiccApp == null) {
1499 loge("getForbiddenPlmns() no app with specified type -- "
1500 + appType);
1501 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001503 break;
1504 } else {
1505 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1506 + " specified type -- " + appType);
1507 }
1508 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1509 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1510 onCompleted);
1511 break;
1512
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001513 case CMD_SWITCH_SLOTS:
1514 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001515 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001516 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001517 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001518 break;
1519
1520 case EVENT_SWITCH_SLOTS_DONE:
1521 ar = (AsyncResult) msg.obj;
1522 request = (MainThreadRequest) ar.userObj;
1523 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001524 notifyRequester(request);
1525 break;
1526 case CMD_GET_NETWORK_SELECTION_MODE:
1527 request = (MainThreadRequest) msg.obj;
1528 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1529 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1530 break;
1531
1532 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 if (ar.exception != null) {
1536 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1537 } else {
1538 int mode = ((int[]) ar.result)[0];
1539 if (mode == 0) {
1540 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1541 } else {
1542 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1543 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001545 notifyRequester(request);
1546 break;
1547 case CMD_GET_CDMA_ROAMING_MODE:
1548 request = (MainThreadRequest) msg.obj;
1549 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1550 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1551 break;
1552 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1553 ar = (AsyncResult) msg.obj;
1554 request = (MainThreadRequest) ar.userObj;
1555 if (ar.exception != null) {
1556 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1557 } else {
1558 request.result = ((int[]) ar.result)[0];
1559 }
1560 notifyRequester(request);
1561 break;
1562 case CMD_SET_CDMA_ROAMING_MODE:
1563 request = (MainThreadRequest) msg.obj;
1564 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1565 int mode = (int) request.argument;
1566 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1567 break;
1568 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 request.result = ar.exception == null;
1572 notifyRequester(request);
1573 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001574 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1575 request = (MainThreadRequest) msg.obj;
1576 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1577 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1578 break;
1579 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1580 ar = (AsyncResult) msg.obj;
1581 request = (MainThreadRequest) ar.userObj;
1582 if (ar.exception != null) {
1583 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1584 } else {
1585 request.result = ((int[]) ar.result)[0];
1586 }
1587 notifyRequester(request);
1588 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001589 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1592 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001593 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1594 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001595 break;
1596 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1597 ar = (AsyncResult) msg.obj;
1598 request = (MainThreadRequest) ar.userObj;
1599 request.result = ar.exception == null;
1600 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001601 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001602 case CMD_GET_ALL_CELL_INFO:
1603 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001605 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001606 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001607 case EVENT_GET_ALL_CELL_INFO_DONE:
1608 ar = (AsyncResult) msg.obj;
1609 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001610 // If a timeout occurs, the response will be null
1611 request.result = (ar.exception == null && ar.result != null)
1612 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001613 synchronized (request) {
1614 request.notifyAll();
1615 }
1616 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001617 case CMD_REQUEST_CELL_INFO_UPDATE:
1618 request = (MainThreadRequest) msg.obj;
1619 request.phone.requestCellInfoUpdate(request.workSource,
1620 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1621 break;
1622 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1626 try {
1627 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001628 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001629 cb.onError(
1630 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1631 ar.exception.getClass().getName(),
1632 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001634 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001635 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001636 } else {
1637 // use the result as returned
1638 cb.onCellInfo((List<CellInfo>) ar.result);
1639 }
1640 } catch (RemoteException re) {
1641 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1642 }
1643 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001644 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001645 request = (MainThreadRequest) msg.obj;
1646 WorkSource ws = (WorkSource) request.argument;
1647 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001648 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001650 }
1651 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001652 ar = (AsyncResult) msg.obj;
1653 request = (MainThreadRequest) ar.userObj;
1654 if (ar.exception == null) {
1655 request.result = ar.result;
1656 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001657 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001659 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 }
1661
1662 synchronized (request) {
1663 request.notifyAll();
1664 }
1665 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001666 }
chen xu6dac5ab2018-10-26 17:39:23 -07001667 case CMD_MODEM_REBOOT:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001670 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001671 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001672 case EVENT_CMD_MODEM_REBOOT_DONE:
1673 handleNullReturnEvent(msg, "rebootModem");
1674 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001675 case CMD_REQUEST_ENABLE_MODEM:
1676 request = (MainThreadRequest) msg.obj;
1677 boolean enable = (boolean) request.argument;
1678 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001679 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001680 PhoneConfigurationManager.getInstance()
1681 .enablePhone(request.phone, enable, onCompleted);
1682 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001683 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001687 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001688 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001689 if ((boolean) request.result) {
1690 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1691 updateModemStateMetrics();
1692 } else {
1693 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1694 + ar.exception);
1695 }
1696 notifyRequester(request);
1697 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001698 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001699 case CMD_GET_MODEM_STATUS:
1700 request = (MainThreadRequest) msg.obj;
1701 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1702 PhoneConfigurationManager.getInstance()
1703 .getPhoneStatusFromModem(request.phone, onCompleted);
1704 break;
1705 case EVENT_GET_MODEM_STATUS_DONE:
1706 ar = (AsyncResult) msg.obj;
1707 request = (MainThreadRequest) ar.userObj;
1708 int id = request.phone.getPhoneId();
1709 if (ar.exception == null && ar.result != null) {
1710 request.result = ar.result;
1711 //update the cache as modem status has changed
1712 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1713 (boolean) request.result);
1714 } else {
1715 // Return true if modem status cannot be retrieved. For most cases,
1716 // modem status is on. And for older version modems, GET_MODEM_STATUS
1717 // and disable modem are not supported. Modem is always on.
1718 // TODO: this should be fixed in R to support a third
1719 // status UNKNOWN b/131631629
1720 request.result = true;
1721 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1722 + ar.exception);
1723 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001724 notifyRequester(request);
1725 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001726 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1727 request = (MainThreadRequest) msg.obj;
1728 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1729 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1730 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1731 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1732 break;
1733 }
1734 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1738 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1739 args.second.accept(ar.exception == null);
1740 notifyRequester(request);
1741 break;
1742 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001743 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1744 request = (MainThreadRequest) msg.obj;
1745 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1746 Phone phone = getPhoneFromRequest(request);
1747 if (phone != null) {
1748 phone.getSystemSelectionChannels(onCompleted);
1749 } else {
1750 loge("getSystemSelectionChannels: No phone object");
1751 request.result = new ArrayList<RadioAccessSpecifier>();
1752 notifyRequester(request);
1753 }
1754 break;
1755 }
1756 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 if (ar.exception == null && ar.result != null) {
1760 request.result = ar.result;
1761 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001762 request.result = new IllegalStateException(
1763 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001764 if (ar.result == null) {
1765 loge("getSystemSelectionChannels: Empty response");
1766 } else {
1767 loge("getSystemSelectionChannels: Unknown exception");
1768 }
1769 }
1770 notifyRequester(request);
1771 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001772 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1773 ar = (AsyncResult) msg.obj;
1774 request = (MainThreadRequest) ar.userObj;
1775 if (ar.exception == null && ar.result != null) {
1776 request.result = ar.result;
1777 } else {
1778 request.result = -1;
1779 loge("Failed to set Forbidden Plmns");
1780 if (ar.result == null) {
1781 loge("setForbidenPlmns: Empty response");
1782 } else if (ar.exception != null) {
1783 loge("setForbiddenPlmns: Exception: " + ar.exception);
1784 request.result = -1;
1785 } else {
1786 loge("setForbiddenPlmns: Unknown exception");
1787 }
1788 }
1789 notifyRequester(request);
1790 break;
1791 case CMD_SET_FORBIDDEN_PLMNS:
1792 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001793 uiccPort = getUiccPortFromRequest(request);
1794 if (uiccPort == null) {
1795 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001796 request.result = -1;
1797 notifyRequester(request);
1798 break;
1799 }
1800 Pair<Integer, List<String>> setFplmnsArgs =
1801 (Pair<Integer, List<String>>) request.argument;
1802 appType = setFplmnsArgs.first;
1803 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001804 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001805 if (uiccApp == null) {
1806 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1807 request.result = -1;
1808 loge("Failed to get UICC App");
1809 notifyRequester(request);
1810 } else {
1811 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1812 ((SIMRecords) uiccApp.getIccRecords())
1813 .setForbiddenPlmns(onCompleted, fplmns);
1814 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001815 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001816 case CMD_ERASE_MODEM_CONFIG:
1817 request = (MainThreadRequest) msg.obj;
1818 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1819 defaultPhone.eraseModemConfig(onCompleted);
1820 break;
1821 case EVENT_ERASE_MODEM_CONFIG_DONE:
1822 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001823 break;
zoey chene02881a2019-12-30 16:11:23 +08001824
Kai Shif70f46f2021-03-03 13:59:46 -08001825 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1826 request = (MainThreadRequest) msg.obj;
1827 request.result = defaultPhone.eraseDataInSharedPreferences();
1828 notifyRequester(request);
1829 break;
1830
zoey chene02881a2019-12-30 16:11:23 +08001831 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1832 request = (MainThreadRequest) msg.obj;
1833 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1834 Pair<String, String> changed = (Pair<String, String>) request.argument;
1835 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1836 changed.first, changed.second, onCompleted);
1837 break;
1838 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 if (ar.exception == null) {
1842 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001843 // If the operation is successful, update the PIN storage
1844 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1845 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001846 UiccController.getInstance().getPinStorage()
1847 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001848 } else {
1849 request.result = msg.arg1;
1850 }
1851 notifyRequester(request);
1852 break;
1853
Michele Berionne5e411512020-11-13 02:36:59 +00001854 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001855 request = (MainThreadRequest) msg.obj;
1856 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1857 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1858 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1859 enabled.first, enabled.second, onCompleted);
1860 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001861 }
zoey chene02881a2019-12-30 16:11:23 +08001862 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1863 ar = (AsyncResult) msg.obj;
1864 request = (MainThreadRequest) ar.userObj;
1865 if (ar.exception == null) {
1866 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001867 // If the operation is successful, update the PIN storage
1868 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1869 int phoneId = getPhoneFromRequest(request).getPhoneId();
1870 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001871 UiccController.getInstance().getPinStorage()
1872 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001873 } else {
1874 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1875 }
zoey chene02881a2019-12-30 16:11:23 +08001876 } else {
1877 request.result = msg.arg1;
1878 }
Michele Berionne5e411512020-11-13 02:36:59 +00001879
1880
zoey chene02881a2019-12-30 16:11:23 +08001881 notifyRequester(request);
1882 break;
1883
Peter Wangdafb9ac2020-01-15 14:13:38 -08001884 case MSG_NOTIFY_USER_ACTIVITY:
1885 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001886 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001887 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1888 getDefaultPhone().getContext().sendBroadcastAsUser(
1889 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1890 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001891
1892 case CMD_SET_DATA_THROTTLING: {
1893 request = (MainThreadRequest) msg.obj;
1894 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1895 DataThrottlingRequest dataThrottlingRequest =
1896 (DataThrottlingRequest) request.argument;
1897 Phone phone = getPhoneFromRequest(request);
1898 if (phone != null) {
1899 phone.setDataThrottling(onCompleted,
1900 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1901 dataThrottlingRequest.getCompletionDurationMillis());
1902 } else {
1903 loge("setDataThrottling: No phone object");
1904 request.result =
1905 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1906 notifyRequester(request);
1907 }
1908
1909 break;
1910 }
1911 case EVENT_SET_DATA_THROTTLING_DONE:
1912 ar = (AsyncResult) msg.obj;
1913 request = (MainThreadRequest) ar.userObj;
1914
1915 if (ar.exception == null) {
1916 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1917 } else if (ar.exception instanceof CommandException) {
1918 loge("setDataThrottling: CommandException: " + ar.exception);
1919 CommandException.Error error =
1920 ((CommandException) (ar.exception)).getCommandError();
1921
1922 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1923 request.result = TelephonyManager
1924 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1925 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1926 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001927 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1928 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001929 } else {
1930 request.result =
1931 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1932 }
1933 } else {
1934 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1935 }
1936 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1937 notifyRequester(request);
1938 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001939
1940 case CMD_SET_SIM_POWER: {
1941 request = (MainThreadRequest) msg.obj;
1942 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1943 request = (MainThreadRequest) msg.obj;
1944 int stateToSet =
1945 ((Pair<Integer, IIntegerConsumer>)
1946 request.argument).first;
1947 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1948 break;
1949 }
1950 case EVENT_SET_SIM_POWER_DONE: {
1951 ar = (AsyncResult) msg.obj;
1952 request = (MainThreadRequest) ar.userObj;
1953 IIntegerConsumer callback =
1954 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1955 if (ar.exception != null) {
1956 loge("setSimPower exception: " + ar.exception);
1957 int errorCode = TelephonyManager.CallForwardingInfoCallback
1958 .RESULT_ERROR_UNKNOWN;
1959 if (ar.exception instanceof CommandException) {
1960 CommandException.Error error =
1961 ((CommandException) (ar.exception)).getCommandError();
1962 if (error == CommandException.Error.SIM_ERR) {
1963 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1964 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1965 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1966 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1967 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1968 } else {
1969 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1970 }
1971 }
1972 try {
1973 callback.accept(errorCode);
1974 } catch (RemoteException e) {
1975 // Ignore if the remote process is no longer available to call back.
1976 Log.w(LOG_TAG, "setSimPower: callback not available.");
1977 }
1978 } else {
1979 try {
1980 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1981 } catch (RemoteException e) {
1982 // Ignore if the remote process is no longer available to call back.
1983 Log.w(LOG_TAG, "setSimPower: callback not available.");
1984 }
1985 }
1986 break;
1987 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001988 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1989 request = (MainThreadRequest) msg.obj;
1990
1991 final Phone phone = getPhoneFromRequest(request);
1992 if (phone == null || phone.getServiceStateTracker() == null) {
1993 request.result = new IllegalStateException("Phone or SST is null");
1994 notifyRequester(request);
1995 break;
1996 }
1997
1998 Pair<Integer, SignalStrengthUpdateRequest> pair =
1999 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2000 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2001 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002002 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002003 request.subId, pair.first /*callingUid*/,
2004 pair.second /*request*/, onCompleted);
2005 break;
2006 }
2007 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2008 ar = (AsyncResult) msg.obj;
2009 request = (MainThreadRequest) ar.userObj;
2010 // request.result will be the exception of ar if present, true otherwise.
2011 // Be cautious not to leave result null which will wait() forever
2012 request.result = ar.exception != null ? ar.exception : true;
2013 notifyRequester(request);
2014 break;
2015 }
2016 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2017 request = (MainThreadRequest) msg.obj;
2018
2019 Phone phone = getPhoneFromRequest(request);
2020 if (phone == null || phone.getServiceStateTracker() == null) {
2021 request.result = new IllegalStateException("Phone or SST is null");
2022 notifyRequester(request);
2023 break;
2024 }
2025
2026 Pair<Integer, SignalStrengthUpdateRequest> pair =
2027 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2028 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2029 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002030 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002031 request.subId, pair.first /*callingUid*/,
2032 pair.second /*request*/, onCompleted);
2033 break;
2034 }
2035 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2036 ar = (AsyncResult) msg.obj;
2037 request = (MainThreadRequest) ar.userObj;
2038 request.result = ar.exception != null ? ar.exception : true;
2039 notifyRequester(request);
2040 break;
2041 }
Jordan Liu109698e2020-11-24 14:50:34 -08002042
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002043 case CMD_GET_SLICING_CONFIG: {
2044 request = (MainThreadRequest) msg.obj;
2045 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2046 request.phone.getSlicingConfig(onCompleted);
2047 break;
2048 }
2049 case EVENT_GET_SLICING_CONFIG_DONE: {
2050 ar = (AsyncResult) msg.obj;
2051 request = (MainThreadRequest) ar.userObj;
2052 ResultReceiver result = (ResultReceiver) request.argument;
2053
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002054 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002055 Bundle bundle = new Bundle();
2056 int resultCode = 0;
2057 if (ar.exception != null) {
2058 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2059 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002060 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002061 } else if (ar.result == null) {
2062 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002063 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002064 } else {
2065 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002066 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2067 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002068 }
2069
2070 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002071 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002072 }
2073 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2074 result.send(resultCode, bundle);
2075 notifyRequester(request);
2076 break;
2077 }
2078
Michele Berionne5e411512020-11-13 02:36:59 +00002079 case CMD_PREPARE_UNATTENDED_REBOOT:
2080 request = (MainThreadRequest) msg.obj;
2081 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002082 UiccController.getInstance().getPinStorage()
2083 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002084 notifyRequester(request);
2085 break;
2086
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 default:
2088 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2089 break;
2090 }
2091 }
Jake Hambye994d462014-02-03 13:10:13 -08002092
Pengquan Menga1bb6272018-09-06 09:59:22 -07002093 private void notifyRequester(MainThreadRequest request) {
2094 synchronized (request) {
2095 request.notifyAll();
2096 }
2097 }
2098
Jake Hambye994d462014-02-03 13:10:13 -08002099 private void handleNullReturnEvent(Message msg, String command) {
2100 AsyncResult ar = (AsyncResult) msg.obj;
2101 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2102 if (ar.exception == null) {
2103 request.result = true;
2104 } else {
2105 request.result = false;
2106 if (ar.exception instanceof CommandException) {
2107 loge(command + ": CommandException: " + ar.exception);
2108 } else {
2109 loge(command + ": Unknown exception");
2110 }
2111 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002112 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
2116 /**
2117 * Posts the specified command to be executed on the main thread,
2118 * waits for the request to complete, and returns the result.
2119 * @see #sendRequestAsync
2120 */
2121 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002122 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2123 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002124 }
2125
2126 /**
2127 * Posts the specified command to be executed on the main thread,
2128 * waits for the request to complete, and returns the result.
2129 * @see #sendRequestAsync
2130 */
2131 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2132 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002133 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002134 }
2135
2136 /**
2137 * Posts the specified command to be executed on the main thread,
2138 * waits for the request to complete, and returns the result.
2139 * @see #sendRequestAsync
2140 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002141 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002142 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2143 }
2144
2145 /**
2146 * Posts the specified command to be executed on the main thread,
2147 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2148 * if not timeout or null otherwise.
2149 * @see #sendRequestAsync
2150 */
2151 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2152 long timeoutInMs) {
2153 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002154 }
2155
2156 /**
2157 * Posts the specified command to be executed on the main thread,
2158 * waits for the request to complete, and returns the result.
2159 * @see #sendRequestAsync
2160 */
Nathan Harold92bed182018-10-12 18:16:49 -07002161 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002162 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002163 }
2164
2165 /**
2166 * Posts the specified command to be executed on the main thread,
2167 * waits for the request to complete, and returns the result.
2168 * @see #sendRequestAsync
2169 */
2170 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002171 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2172 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002173 }
2174
2175 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002176 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2177 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2178 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002179 * @see #sendRequestAsync
2180 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002181 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2182 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2184 throw new RuntimeException("This method will deadlock if called from the main thread.");
2185 }
2186
Nathan Harold92bed182018-10-12 18:16:49 -07002187 MainThreadRequest request = null;
2188 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2189 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2190 } else if (phone != null) {
2191 request = new MainThreadRequest(argument, phone, workSource);
2192 } else {
2193 request = new MainThreadRequest(argument, subId, workSource);
2194 }
2195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 Message msg = mMainThreadHandler.obtainMessage(command, request);
2197 msg.sendToTarget();
2198
Rambo Wang0f050d82021-02-12 11:43:36 -08002199
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002201 if (timeoutInMs >= 0) {
2202 // Wait for at least timeoutInMs before returning null request result
2203 long now = SystemClock.elapsedRealtime();
2204 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002205 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002206 try {
2207 request.wait(deadline - now);
2208 } catch (InterruptedException e) {
2209 // Do nothing, go back and check if request is completed or timeout
2210 } finally {
2211 now = SystemClock.elapsedRealtime();
2212 }
2213 }
2214 } else {
2215 // Wait for the request to complete
2216 while (request.result == null) {
2217 try {
2218 request.wait();
2219 } catch (InterruptedException e) {
2220 // Do nothing, go back and wait until the request is complete
2221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 }
2223 }
2224 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002225 if (request.result == null) {
2226 Log.wtf(LOG_TAG,
2227 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 return request.result;
2230 }
2231
2232 /**
2233 * Asynchronous ("fire and forget") version of sendRequest():
2234 * Posts the specified command to be executed on the main thread, and
2235 * returns immediately.
2236 * @see #sendRequest
2237 */
2238 private void sendRequestAsync(int command) {
2239 mMainThreadHandler.sendEmptyMessage(command);
2240 }
2241
2242 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002243 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002244 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002245 */
2246 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002247 sendRequestAsync(command, argument, null, null);
2248 }
2249
2250 /**
2251 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2252 * @see {@link #sendRequest(int,Object)}
2253 */
2254 private void sendRequestAsync(
2255 int command, Object argument, Phone phone, WorkSource workSource) {
2256 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002257 Message msg = mMainThreadHandler.obtainMessage(command, request);
2258 msg.sendToTarget();
2259 }
2260
2261 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 * Initialize the singleton PhoneInterfaceManager instance.
2263 * This is only done once, at startup, from PhoneApp.onCreate().
2264 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002265 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 synchronized (PhoneInterfaceManager.class) {
2267 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002268 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 } else {
2270 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2271 }
2272 return sInstance;
2273 }
2274 }
2275
2276 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002277 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002280 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002281 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002283 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002285 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002286 mTelephonySharedPreferences =
2287 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002288 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002289 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002290 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002291 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 publish();
2294 }
2295
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002296 private Phone getDefaultPhone() {
2297 Phone thePhone = getPhone(getDefaultSubscription());
2298 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2299 }
2300
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 private void publish() {
2302 if (DBG) log("publish: " + this);
2303
Peter Wangc035ce42020-01-08 21:00:22 -08002304 TelephonyFrameworkInitializer
2305 .getTelephonyServiceManager()
2306 .getTelephonyServiceRegisterer()
2307 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
Stuart Scott584921c2015-01-15 17:10:34 -08002310 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002311 if (request.phone != null) {
2312 return request.phone;
2313 } else {
2314 return getPhoneFromSubId(request.subId);
2315 }
2316 }
2317
2318 private Phone getPhoneFromSubId(int subId) {
2319 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2320 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002321 }
2322
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002323 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002324 Phone phone = getPhoneFromRequest(request);
2325 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002326 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002327 }
2328
Wink Saville36469e72014-06-11 15:17:00 -07002329 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002330 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002331 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333
Kai Shif70f46f2021-03-03 13:59:46 -08002334 private void sendEraseModemConfig(@NonNull Phone phone) {
2335 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2336 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2337 }
2338
2339 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2340 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2341 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002342 }
2343
Peter Wang44b186e2020-01-13 23:33:09 -08002344 private boolean isImsAvailableOnDevice() {
2345 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2346 if (pm == null) {
2347 // For some reason package manger is not available.. This will fail internally anyway,
2348 // so do not throw error and allow.
2349 return true;
2350 }
2351 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2352 }
2353
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002355 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002356 }
2357
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 if (DBG) log("dial: " + number);
2360 // No permission check needed here: This is just a wrapper around the
2361 // ACTION_DIAL intent, which is available to any app since it puts up
2362 // the UI before it does anything.
2363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 String url = createTelUrl(number);
2367 if (url == null) {
2368 return;
2369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 // PENDING: should we just silently fail if phone is offhook or ringing?
2372 PhoneConstants.State state = mCM.getState(subId);
2373 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2374 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2375 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2376 mApp.startActivity(intent);
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 }
2381 }
2382
2383 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002384 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002385 }
2386
Wink Savilleb564aae2014-10-23 10:18:09 -07002387 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 if (DBG) log("call: " + number);
2389
2390 // This is just a wrapper around the ACTION_CALL intent, but we still
2391 // need to do a permission check since we're calling startActivity()
2392 // from the context of the phone app.
2393 enforceCallPermission();
2394
Jordan Liu1617b712019-07-10 15:06:26 -07002395 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 != AppOpsManager.MODE_ALLOWED) {
2397 return;
2398 }
2399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 String url = createTelUrl(number);
2403 if (url == null) {
2404 return;
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407 boolean isValid = false;
2408 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2409 if (slist != null) {
2410 for (SubscriptionInfo subInfoRecord : slist) {
2411 if (subInfoRecord.getSubscriptionId() == subId) {
2412 isValid = true;
2413 break;
2414 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002415 }
Wink Saville08874612014-08-31 19:19:58 -07002416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 if (!isValid) {
2418 return;
2419 }
Wink Saville08874612014-08-31 19:19:58 -07002420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2422 intent.putExtra(SUBSCRIPTION_KEY, subId);
2423 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2424 mApp.startActivity(intent);
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
Wink Savilleb564aae2014-10-23 10:18:09 -07002430 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002431 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002432 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2433 }
2434
Wink Savilleb564aae2014-10-23 10:18:09 -07002435 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002436 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002437 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2438 }
2439
Wink Savilleb564aae2014-10-23 10:18:09 -07002440 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442
2443 final long identity = Binder.clearCallingIdentity();
2444 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002445 Phone phone = getPhone(subId);
2446 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447 checkSimPin.start();
2448 return checkSimPin.unlockSim(null, pin);
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
2451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 }
2453
Wink Savilleb564aae2014-10-23 10:18:09 -07002454 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456
2457 final long identity = Binder.clearCallingIdentity();
2458 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002459 Phone phone = getPhone(subId);
2460 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461 checkSimPuk.start();
2462 return checkSimPuk.unlockSim(puk, pin);
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
2465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 }
2467
2468 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002469 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 * a synchronous one.
2471 */
2472 private static class UnlockSim extends Thread {
2473
2474 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002475 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476
2477 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002478 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2479 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480
2481 // For replies from SimCard interface
2482 private Handler mHandler;
2483
2484 // For async handler to identify request type
2485 private static final int SUPPLY_PIN_COMPLETE = 100;
2486
Michele Berionne5e411512020-11-13 02:36:59 +00002487 UnlockSim(int phoneId, IccCard simCard) {
2488 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 mSimCard = simCard;
2490 }
2491
2492 @Override
2493 public void run() {
2494 Looper.prepare();
2495 synchronized (UnlockSim.this) {
2496 mHandler = new Handler() {
2497 @Override
2498 public void handleMessage(Message msg) {
2499 AsyncResult ar = (AsyncResult) msg.obj;
2500 switch (msg.what) {
2501 case SUPPLY_PIN_COMPLETE:
2502 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2503 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002504 mRetryCount = msg.arg1;
2505 if (ar.exception != null) {
2506 if (ar.exception instanceof CommandException &&
2507 ((CommandException)(ar.exception)).getCommandError()
2508 == CommandException.Error.PASSWORD_INCORRECT) {
2509 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002510 } //When UiccCardApp dispose,handle message and return exception
2511 else if (ar.exception instanceof CommandException &&
2512 ((CommandException) (ar.exception)).getCommandError()
2513 == CommandException.Error.ABORTED) {
2514 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002515 } else {
2516 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2517 }
2518 } else {
2519 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 mDone = true;
2522 UnlockSim.this.notifyAll();
2523 }
2524 break;
2525 }
2526 }
2527 };
2528 UnlockSim.this.notifyAll();
2529 }
2530 Looper.loop();
2531 }
2532
2533 /*
2534 * Use PIN or PUK to unlock SIM card
2535 *
2536 * If PUK is null, unlock SIM card with PIN
2537 *
2538 * If PUK is not null, unlock SIM card with PUK and set PIN code
2539 */
Wink Saville9de0f752013-10-22 19:04:03 -07002540 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541
2542 while (mHandler == null) {
2543 try {
2544 wait();
2545 } catch (InterruptedException e) {
2546 Thread.currentThread().interrupt();
2547 }
2548 }
2549 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2550
2551 if (puk == null) {
2552 mSimCard.supplyPin(pin, callback);
2553 } else {
2554 mSimCard.supplyPuk(puk, pin, callback);
2555 }
2556
2557 while (!mDone) {
2558 try {
2559 Log.d(LOG_TAG, "wait for done");
2560 wait();
2561 } catch (InterruptedException e) {
2562 // Restore the interrupted status
2563 Thread.currentThread().interrupt();
2564 }
2565 }
2566 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002567 int[] resultArray = new int[2];
2568 resultArray[0] = mResult;
2569 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002570
2571 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002572 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002573 }
2574
Wink Saville9de0f752013-10-22 19:04:03 -07002575 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 }
2577 }
2578
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002579 /**
2580 * This method has been removed due to privacy and stability concerns.
2581 */
2582 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002584 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2585 return;
Wink Saville36469e72014-06-11 15:17:00 -07002586 }
2587
Nathan Harold1f889d82020-06-04 17:05:26 -07002588 @Override
2589 public void updateServiceLocationWithPackageName(String callingPackage) {
2590 mApp.getSystemService(AppOpsManager.class)
2591 .checkPackage(Binder.getCallingUid(), callingPackage);
2592
Nathan Haroldf096d982020-11-18 17:18:06 -08002593 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002594 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2595 // Callers targeting S have no business invoking this method.
2596 return;
2597 }
2598
2599 LocationAccessPolicy.LocationPermissionResult locationResult =
2600 LocationAccessPolicy.checkLocationPermission(mApp,
2601 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2602 .setCallingPackage(callingPackage)
2603 .setCallingFeatureId(null)
2604 .setCallingPid(Binder.getCallingPid())
2605 .setCallingUid(Binder.getCallingUid())
2606 .setMethod("updateServiceLocation")
2607 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2608 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2609 .build());
2610 // Apps that lack location permission have no business calling this method;
2611 // however, because no permission was declared in the public API, denials must
2612 // all be "soft".
2613 switch (locationResult) {
2614 case DENIED_HARD: /* fall through */
2615 case DENIED_SOFT:
2616 return;
2617 }
2618
2619 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 final long identity = Binder.clearCallingIdentity();
2621 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002622 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002624 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 }
2630
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002631 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002632 @Override
2633 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002634 return isRadioOnWithFeature(callingPackage, null);
2635 }
2636
2637
2638 @Override
2639 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2640 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2641 callingFeatureId);
2642 }
2643
2644 @Deprecated
2645 @Override
2646 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2647 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002648 }
2649
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002650 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002651 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2652 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002654 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002655 return false;
2656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 return isRadioOnForSubscriber(subId);
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002664 }
2665
2666 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 final Phone phone = getPhone(subId);
2670 if (phone != null) {
2671 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2672 } else {
2673 return false;
2674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
2680 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002681 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
Wink Saville36469e72014-06-11 15:17:00 -07002683
Wink Savilleb564aae2014-10-23 10:18:09 -07002684 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 final Phone phone = getPhone(subId);
2690 if (phone != null) {
2691 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2692 }
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002695 }
Wink Saville36469e72014-06-11 15:17:00 -07002696 }
2697
2698 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002699 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002700 }
2701
Wink Savilleb564aae2014-10-23 10:18:09 -07002702 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
2705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 final Phone phone = getPhone(subId);
2708 if (phone == null) {
2709 return false;
2710 }
2711 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2712 toggleRadioOnOffForSubscriber(subId);
2713 }
2714 return true;
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
Wink Saville36469e72014-06-11 15:17:00 -07002719
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002721 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002722 /*
2723 * If any of the Radios are available, it will need to be
2724 * shutdown. So return true if any Radio is available.
2725 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2729 Phone phone = PhoneFactory.getPhone(i);
2730 if (phone != null && phone.isRadioAvailable()) return true;
2731 }
2732 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2733 return false;
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002737 }
2738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002740 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741 enforceModifyPermission();
2742
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2746 logv("Shutting down Phone " + i);
2747 shutdownRadioUsingPhoneId(i);
2748 }
2749 } finally {
2750 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002751 }
2752 }
2753
2754 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002755 Phone phone = PhoneFactory.getPhone(phoneId);
2756 if (phone != null && phone.isRadioAvailable()) {
2757 phone.shutdownRadio();
2758 }
2759 }
2760
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2767 if (defaultPhone != null) {
2768 defaultPhone.setRadioPower(turnOn);
2769 return true;
2770 } else {
2771 loge("There's no default phone.");
2772 return false;
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002776 }
Wink Saville36469e72014-06-11 15:17:00 -07002777 }
2778
Wink Savilleb564aae2014-10-23 10:18:09 -07002779 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 final Phone phone = getPhone(subId);
2785 if (phone != null) {
2786 phone.setRadioPower(turnOn);
2787 return true;
2788 } else {
2789 return false;
2790 }
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
2795
Wink Saville36469e72014-06-11 15:17:00 -07002796 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002797 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 public boolean enableDataConnectivity() {
2799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 int subId = mSubscriptionController.getDefaultDataSubId();
2804 final Phone phone = getPhone(subId);
2805 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002806 phone.getDataEnabledSettings().setDataEnabled(
2807 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 return true;
2809 } else {
2810 return false;
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Wink Saville36469e72014-06-11 15:17:00 -07002817 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 public boolean disableDataConnectivity() {
2820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 int subId = mSubscriptionController.getDefaultDataSubId();
2825 final Phone phone = getPhone(subId);
2826 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002827 phone.getDataEnabledSettings().setDataEnabled(
2828 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 return true;
2830 } else {
2831 return false;
2832 }
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 }
2837
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002839 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 final Phone phone = getPhone(subId);
2843 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002844 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 } else {
2846 return false;
2847 }
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
2853 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002854 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002855 }
2856
pkanwarae03a6b2016-11-06 20:37:09 -08002857 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 enforceCallPermission();
2859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2863 return;
2864 }
2865 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2866 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
pkanwar32d516d2016-10-14 19:37:38 -07002870 };
2871
Wink Savilleb564aae2014-10-23 10:18:09 -07002872 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2878 return false;
2879 }
2880 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002886 /**
2887 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2888 * tag on getCallState Binder call.
2889 */
2890 @Deprecated
2891 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002893 if (CompatChanges.isChangeEnabled(
2894 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2895 Binder.getCallingUid())) {
2896 // Do not allow this API to be called on API version 31+, it should only be
2897 // called on old apps using this Binder call directly.
2898 throw new SecurityException("This method can only be used for applications "
2899 + "targeting API version 30 or less.");
2900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002903 Phone phone = getPhone(getDefaultSubscription());
2904 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2905 PhoneConstantConversions.convertCallState(phone.getState());
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
2909 }
2910
2911 @Override
2912 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2913 if (CompatChanges.isChangeEnabled(
2914 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2915 Binder.getCallingUid())) {
2916 // Check READ_PHONE_STATE for API version 31+
2917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2918 featureId, "getCallStateForSubscription")) {
2919 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2920 + "targeting API level 31+.");
2921 }
2922 }
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2927 PhoneConstantConversions.convertCallState(phone.getState());
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002934 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002935 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2936 }
2937
2938 @Override
2939 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 final long identity = Binder.clearCallingIdentity();
2941 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002942 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002944 if (phone.isUsingNewDataStack()) {
2945 return phone.getDataNetworkController().getInternetDataNetworkState();
2946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2948 } else {
2949 return PhoneConstantConversions.convertDataState(
2950 PhoneConstants.DataState.DISCONNECTED);
2951 }
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 }
2956
Sanket Padawe356d7632015-06-22 14:03:32 -07002957 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002958 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002959 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2960 }
2961
2962 @Override
2963 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964 final long identity = Binder.clearCallingIdentity();
2965 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002966 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967 if (phone != null) {
2968 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2969 } else {
2970 return TelephonyManager.DATA_ACTIVITY_NONE;
2971 }
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
2976
2977 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002978 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002979 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002980 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002981
2982 LocationAccessPolicy.LocationPermissionResult locationResult =
2983 LocationAccessPolicy.checkLocationPermission(mApp,
2984 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2985 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002986 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002987 .setCallingPid(Binder.getCallingPid())
2988 .setCallingUid(Binder.getCallingUid())
2989 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002990 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002991 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2992 .build());
2993 switch (locationResult) {
2994 case DENIED_HARD:
2995 throw new SecurityException("Not allowed to access cell location");
2996 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002997 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2998 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002999 }
3000
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003001 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003005 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003006 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
Svetoslav64fad262015-04-14 14:35:21 -07003010 }
3011
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003013 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003014 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3015 // registered cell info, so return a NULL country instead.
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003018 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3019 // Get default phone in this case.
3020 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3021 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003022 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003024 if (phone == null) return "";
3025 ServiceStateTracker sst = phone.getServiceStateTracker();
3026 if (sst == null) return "";
3027 LocaleTracker lt = sst.getLocaleTracker();
3028 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003029 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003033 }
3034
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003035 /**
3036 * This method was removed due to potential issues caused by performing partial
3037 * updates of service state, and lack of a credible use case.
3038 *
3039 * This has the ability to break the telephony implementation by disabling notification of
3040 * changes in device connectivity. DO NOT USE THIS!
3041 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003042 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 public void enableLocationUpdates() {
3044 mApp.enforceCallingOrSelfPermission(
3045 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 }
3047
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003048 /**
3049 * This method was removed due to potential issues caused by performing partial
3050 * updates of service state, and lack of a credible use case.
3051 *
3052 * This has the ability to break the telephony implementation by disabling notification of
3053 * changes in device connectivity. DO NOT USE THIS!
3054 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 @Override
3056 public void disableLocationUpdates() {
3057 mApp.enforceCallingOrSelfPermission(
3058 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 }
3060
3061 @Override
3062 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003063 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3064 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003065 try {
3066 mApp.getSystemService(AppOpsManager.class)
3067 .checkPackage(Binder.getCallingUid(), callingPackage);
3068 } catch (SecurityException e) {
3069 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3070 throw e;
3071 }
3072
Nathan Haroldf096d982020-11-18 17:18:06 -08003073 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003074 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3075 throw new SecurityException(
3076 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3077 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003078
Jordan Liu1617b712019-07-10 15:06:26 -07003079 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3081 return null;
3082 }
Svetoslav64fad262015-04-14 14:35:21 -07003083
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003084 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003086 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003087 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088
Nathan Haroldf180aac2018-06-01 18:43:55 -07003089 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3090 for (CellInfo ci : info) {
3091 if (ci instanceof CellInfoGsm) {
3092 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3093 } else if (ci instanceof CellInfoWcdma) {
3094 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003097 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 }
3099
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003100 private List<CellInfo> getCachedCellInfo() {
3101 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3102 for (Phone phone : PhoneFactory.getPhones()) {
3103 List<CellInfo> info = phone.getAllCellInfo();
3104 if (info != null) cellInfos.addAll(info);
3105 }
3106 return cellInfos;
3107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108
3109 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003110 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003111 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003112 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003113
3114 LocationAccessPolicy.LocationPermissionResult locationResult =
3115 LocationAccessPolicy.checkLocationPermission(mApp,
3116 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3117 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003118 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003119 .setCallingPid(Binder.getCallingPid())
3120 .setCallingUid(Binder.getCallingUid())
3121 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003122 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003123 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3124 .build());
3125 switch (locationResult) {
3126 case DENIED_HARD:
3127 throw new SecurityException("Not allowed to access cell info");
3128 case DENIED_SOFT:
3129 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003130 }
3131
Nathan Haroldf096d982020-11-18 17:18:06 -08003132 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003133 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3134 return getCachedCellInfo();
3135 }
3136
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003137 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003138 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3142 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003143 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003144 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 if (info != null) cellInfos.addAll(info);
3146 }
3147 return cellInfos;
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
3151 }
3152
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003153 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003154 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3155 String callingFeatureId) {
3156 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3157 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003158 }
3159
3160 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003161 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3162 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003163 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003164 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003165 }
3166
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003167 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3168 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003169 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003170 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003171
3172 LocationAccessPolicy.LocationPermissionResult locationResult =
3173 LocationAccessPolicy.checkLocationPermission(mApp,
3174 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3175 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003176 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003177 .setCallingPid(Binder.getCallingPid())
3178 .setCallingUid(Binder.getCallingUid())
3179 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003180 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3181 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003182 .build());
3183 switch (locationResult) {
3184 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003185 if (TelephonyPermissions
3186 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003187 // Safetynet logging for b/154934934
3188 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3189 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003190 throw new SecurityException("Not allowed to access cell info");
3191 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003192 if (TelephonyPermissions
3193 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003194 // Safetynet logging for b/154934934
3195 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3196 }
Nathan Harold5320c422019-05-09 10:26:08 -07003197 try {
3198 cb.onCellInfo(new ArrayList<CellInfo>());
3199 } catch (RemoteException re) {
3200 // Drop without consequences
3201 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003202 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003203 }
3204
Nathan Harolda939a962019-05-09 10:13:47 -07003205
3206 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003207 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3208
3209 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3210 }
3211
3212 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003214 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003219 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003223 }
3224
Shishir Agrawala9f32182016-04-12 12:00:16 -07003225 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003226 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003227 Phone phone = PhoneFactory.getPhone(slotIndex);
3228 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003229 return null;
3230 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003231 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003232 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003233 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003234 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003235 return null;
3236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237
3238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 return phone.getImei();
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003244 }
3245
3246 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003247 public String getTypeAllocationCodeForSlot(int slotIndex) {
3248 Phone phone = PhoneFactory.getPhone(slotIndex);
3249 String tac = null;
3250 if (phone != null) {
3251 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003252 try {
3253 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3254 } catch (IndexOutOfBoundsException e) {
3255 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3256 return null;
3257 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003258 }
3259 return tac;
3260 }
3261
3262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003263 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003264 try {
3265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3266 } catch (SecurityException se) {
3267 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3268 throw new SecurityException("Package " + callingPackage + " does not belong to "
3269 + Binder.getCallingUid());
3270 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 Phone phone = PhoneFactory.getPhone(slotIndex);
3272 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003273 return null;
3274 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275
Jeff Davidson913390f2018-02-23 17:11:49 -08003276 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003277 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003278 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003279 return null;
3280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 return phone.getMeid();
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
Jack Yu2af8d712017-03-15 17:14:14 -07003288 }
3289
3290 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003291 public String getManufacturerCodeForSlot(int slotIndex) {
3292 Phone phone = PhoneFactory.getPhone(slotIndex);
3293 String manufacturerCode = null;
3294 if (phone != null) {
3295 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003296 try {
3297 manufacturerCode =
3298 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3299 } catch (IndexOutOfBoundsException e) {
3300 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3301 return null;
3302 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003303 }
3304 return manufacturerCode;
3305 }
3306
3307 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003308 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3309 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003310 Phone phone = PhoneFactory.getPhone(slotIndex);
3311 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003312 return null;
3313 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003314 int subId = phone.getSubId();
3315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003316 mApp, subId, callingPackage, callingFeatureId,
3317 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003318 return null;
3319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 return phone.getDeviceSvn();
3324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003327 }
3328
fionaxu43304da2017-11-27 22:51:16 -08003329 @Override
3330 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 final Phone phone = getPhone(subId);
3334 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
fionaxu43304da2017-11-27 22:51:16 -08003338 }
3339
3340 @Override
3341 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = getPhone(subId);
3345 return phone == null ? null : phone.getCarrierName();
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
fionaxu43304da2017-11-27 22:51:16 -08003349 }
3350
calvinpanffe225e2018-11-01 19:43:06 +08003351 @Override
chen xu0026ca62019-03-06 15:28:50 -08003352 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 final Phone phone = getPhone(subId);
3356 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003357 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
3361 }
3362
3363 @Override
chen xu0026ca62019-03-06 15:28:50 -08003364 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003368 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
chen xu651eec72018-11-11 19:03:44 -08003374 @Override
chen xu864e11c2018-12-06 22:10:03 -08003375 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3376 if (!isSubscriptionMccMnc) {
3377 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3378 }
chen xu651eec72018-11-11 19:03:44 -08003379 final Phone phone = PhoneFactory.getPhone(slotIndex);
3380 if (phone == null) {
3381 return TelephonyManager.UNKNOWN_CARRIER_ID;
3382 }
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
3389 }
3390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003391 //
3392 // Internal helper methods.
3393 //
3394
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003395 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003396 * Make sure the caller is the calling package itself
3397 *
3398 * @throws SecurityException if the caller is not the calling package
3399 */
3400 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3401 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003402 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3403 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003404 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003405 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003406 } catch (PackageManager.NameNotFoundException e) {
3407 // packageUid is -1
3408 }
3409 if (packageUid != callingUid) {
3410 throw new SecurityException(message + ": Package " + callingPackage
3411 + " does not belong to " + callingUid);
3412 }
3413 }
3414
3415 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3417 *
3418 * @throws SecurityException if the caller does not have the required permission
3419 */
3420 private void enforceModifyPermission() {
3421 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3422 }
3423
Shuo Qian3b6ee772019-11-13 17:43:31 -08003424 private void enforceActiveEmergencySessionPermission() {
3425 mApp.enforceCallingOrSelfPermission(
3426 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3427 }
3428
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 /**
3430 * Make sure the caller has the CALL_PHONE permission.
3431 *
3432 * @throws SecurityException if the caller does not have the required permission
3433 */
3434 private void enforceCallPermission() {
3435 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3436 }
3437
paulhu5a773602019-08-23 19:17:33 +08003438 private void enforceSettingsPermission() {
3439 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003440 }
3441
Michele Berionne5e411512020-11-13 02:36:59 +00003442 private void enforceRebootPermission() {
3443 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3444 }
3445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003446 private String createTelUrl(String number) {
3447 if (TextUtils.isEmpty(number)) {
3448 return null;
3449 }
3450
Jake Hambye994d462014-02-03 13:10:13 -08003451 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 }
3453
Ihab Awadf9e92732013-12-05 18:02:52 -08003454 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3456 }
3457
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003458 private static void logv(String msg) {
3459 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3460 }
3461
Ihab Awadf9e92732013-12-05 18:02:52 -08003462 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3464 }
3465
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003466 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003467 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003468 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003469 }
3470
Sanket Padawe356d7632015-06-22 14:03:32 -07003471 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003472 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 final Phone phone = PhoneFactory.getPhone(slotIndex);
3476 if (phone == null) {
3477 return PhoneConstants.PHONE_TYPE_NONE;
3478 } else {
3479 return phone.getPhoneType();
3480 }
3481 } finally {
3482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484 }
3485
3486 /**
3487 * Returns the CDMA ERI icon index to display
3488 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003490 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3491 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3492 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003493 }
3494
Sanket Padawe356d7632015-06-22 14:03:32 -07003495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003496 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3497 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003499 mApp, subId, callingPackage, callingFeatureId,
3500 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 return -1;
3502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503
3504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 final Phone phone = getPhone(subId);
3507 if (phone != null) {
3508 return phone.getCdmaEriIconIndex();
3509 } else {
3510 return -1;
3511 }
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515 }
3516
3517 /**
3518 * Returns the CDMA ERI icon mode,
3519 * 0 - ON
3520 * 1 - FLASHING
3521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003523 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3524 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3525 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003526 }
3527
Sanket Padawe356d7632015-06-22 14:03:32 -07003528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003529 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3530 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003532 mApp, subId, callingPackage, callingFeatureId,
3533 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003534 return -1;
3535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 final Phone phone = getPhone(subId);
3540 if (phone != null) {
3541 return phone.getCdmaEriIconMode();
3542 } else {
3543 return -1;
3544 }
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003548 }
3549
3550 /**
3551 * Returns the CDMA ERI text,
3552 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003553 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003554 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3555 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3556 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003557 }
3558
Sanket Padawe356d7632015-06-22 14:03:32 -07003559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003560 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3561 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003563 mApp, subId, callingPackage, callingFeatureId,
3564 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003565 return null;
3566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
3571 if (phone != null) {
3572 return phone.getCdmaEriText();
3573 } else {
3574 return null;
3575 }
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003579 }
3580
3581 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003582 * Returns the CDMA MDN.
3583 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003585 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3587 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588
3589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003592 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593 return phone.getLine1Number();
3594 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596 return null;
3597 }
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003600 }
3601 }
3602
3603 /**
3604 * Returns the CDMA MIN.
3605 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003606 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003607 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3609 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610
3611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 final Phone phone = getPhone(subId);
3614 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3615 return phone.getCdmaMin();
3616 } else {
3617 return null;
3618 }
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003621 }
3622 }
3623
Hall Liud892bec2018-11-30 14:51:45 -08003624 @Override
3625 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3626 INumberVerificationCallback callback, String callingPackage) {
3627 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3628 != PERMISSION_GRANTED) {
3629 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3630 }
3631 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3632
3633 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3634 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003635 throw new SecurityException("Calling package must be configured in the device config: "
3636 + "calling package: " + callingPackage
3637 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003638 }
3639
3640 if (range == null) {
3641 throw new NullPointerException("Range must be non-null");
3642 }
3643
3644 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003645 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003646
3647 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3648 }
3649
Junda Liuca05d5d2014-08-14 22:36:34 -07003650 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003651 * Returns true if CDMA provisioning needs to run.
3652 */
3653 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 final long identity = Binder.clearCallingIdentity();
3655 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003660 }
3661
3662 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003663 * Sets the voice mail number of a given subId.
3664 */
3665 @Override
3666 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003667 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3668 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3673 new Pair<String, String>(alphaTag, number), new Integer(subId));
3674 return success;
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003678 }
3679
Ta-wei Yen87c49842016-05-13 21:19:52 -07003680 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003681 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003683 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3684 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003685 if (!TextUtils.equals(callingPackage, systemDialer)) {
3686 throw new SecurityException("caller must be system dialer");
3687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3692 if (phoneAccountHandle == null) {
3693 return null;
3694 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003695 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003698 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003699 }
3700
3701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003702 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3703 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003706 mApp, subId, callingPackage, callingFeatureId,
3707 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003708 return null;
3709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003711 final long identity = Binder.clearCallingIdentity();
3712 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003717 }
3718
3719 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003720 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3721 VisualVoicemailSmsFilterSettings settings) {
3722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003727 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 } finally {
3729 Binder.restoreCallingIdentity(identity);
3730 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003731 }
3732
3733 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003734 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736
3737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003744 }
3745
3746 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003747 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3748 String callingPackage, int subId) {
3749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003758 }
3759
3760 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003761 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763
3764 final long identity = Binder.clearCallingIdentity();
3765 try {
3766 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003767 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 } finally {
3769 Binder.restoreCallingIdentity(identity);
3770 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003771 }
3772
3773 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003774 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3775 String callingAttributionTag, int subId, String number, int port, String text,
3776 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003778 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003779 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003780 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003781 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3782 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003783 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003784
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003785 /**
fionaxu0152e512016-11-14 13:36:14 -08003786 * Sets the voice activation state of a given subId.
3787 */
3788 @Override
3789 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3791 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 final Phone phone = getPhone(subId);
3796 if (phone != null) {
3797 phone.setVoiceActivationState(activationState);
3798 } else {
3799 loge("setVoiceActivationState fails with invalid subId: " + subId);
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003803 }
3804 }
3805
3806 /**
3807 * Sets the data activation state of a given subId.
3808 */
3809 @Override
3810 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813
3814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 final Phone phone = getPhone(subId);
3817 if (phone != null) {
3818 phone.setDataActivationState(activationState);
3819 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003820 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003824 }
3825 }
3826
3827 /**
3828 * Returns the voice activation state of a given subId.
3829 */
3830 @Override
3831 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833
fionaxu0152e512016-11-14 13:36:14 -08003834 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 if (phone != null) {
3838 return phone.getVoiceActivationState();
3839 } else {
3840 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3841 }
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003844 }
3845 }
3846
3847 /**
3848 * Returns the data activation state of a given subId.
3849 */
3850 @Override
3851 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853
fionaxu0152e512016-11-14 13:36:14 -08003854 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 if (phone != null) {
3858 return phone.getDataActivationState();
3859 } else {
3860 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003864 }
3865 }
3866
3867 /**
Wink Saville36469e72014-06-11 15:17:00 -07003868 * Returns the unread count of voicemails for a subId
3869 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003871 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3872 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003874 mApp, subId, callingPackage, callingFeatureId,
3875 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003876 return 0;
3877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 final Phone phone = getPhone(subId);
3881 if (phone != null) {
3882 return phone.getVoiceMessageCount();
3883 } else {
3884 return 0;
3885 }
3886 } finally {
3887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889 }
3890
3891 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003892 * returns true, if the device is in a state where both voice and data
3893 * are supported simultaneously. This can change based on location or network condition.
3894 */
3895 @Override
3896 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 final Phone phone = getPhone(subId);
3900 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
3903 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003904 }
3905
3906 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003907 * Send the dialer code if called from the current default dialer or the caller has
3908 * carrier privilege.
3909 * @param inputCode The dialer code to send
3910 */
3911 @Override
3912 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003913 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003915 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3916 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003917 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003918 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003919 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921
3922 final long identity = Binder.clearCallingIdentity();
3923 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003924 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925 } finally {
3926 Binder.restoreCallingIdentity(identity);
3927 }
fionaxu235cc5e2017-03-06 22:25:57 -08003928 }
3929
Pengquan Menga1bb6272018-09-06 09:59:22 -07003930 @Override
3931 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003932 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003933 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003934 mApp, subId, "getNetworkSelectionMode");
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 if (!isActiveSubscription(subId)) {
3938 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3939 }
3940 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003944 }
3945
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003947 public boolean isInEmergencySmsMode() {
3948 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 for (Phone phone : PhoneFactory.getPhones()) {
3952 if (phone.isInEmergencySmsMode()) {
3953 return true;
3954 }
3955 }
3956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
3959 return false;
3960 }
3961
shilu366312e2019-12-17 09:28:10 -08003962 /**
3963 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3964 * @param subId The subscription to use to check the configuration.
3965 * @param c The callback that will be used to send the result.
3966 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003967 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003968 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3969 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003970 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003971 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003972
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003973 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3974 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3975 "IMS not available on device.");
3976 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 final long token = Binder.clearCallingIdentity();
3978 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003979 int slotId = getSlotIndexOrException(subId);
3980 verifyImsMmTelConfiguredOrThrow(slotId);
3981 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003982 } catch (ImsException e) {
3983 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 } finally {
3985 Binder.restoreCallingIdentity(token);
3986 }
3987 }
3988
shilu366312e2019-12-17 09:28:10 -08003989 /**
3990 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3991 * @param subId The subscription to use to check the configuration.
3992 * @param c The callback that will be used to send the result.
3993 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003995 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003996 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003997 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003998 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3999 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4000 }
Meng Wangafbc5852019-09-19 17:37:13 -07004001 final long token = Binder.clearCallingIdentity();
4002 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004003 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4004 .removeRegistrationCallbackForSubscription(c, subId);
4005 } catch (ImsException e) {
4006 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4007 + "is inactive, ignoring unregister.");
4008 // If the subscription is no longer active, just return, since the callback
4009 // will already have been removed internally.
4010 } finally {
4011 Binder.restoreCallingIdentity(token);
4012 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 }
4014
Brad Ebingera34a6c22019-10-22 17:36:18 -07004015 /**
4016 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4017 */
4018 @Override
4019 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4020 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4021 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4022 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4023 "IMS not available on device.");
4024 }
4025 final long token = Binder.clearCallingIdentity();
4026 try {
4027 Phone phone = getPhone(subId);
4028 if (phone == null) {
4029 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4030 + subId + "'");
4031 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4032 }
4033 phone.getImsRegistrationState(regState -> {
4034 try {
4035 consumer.accept((regState == null)
4036 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4037 } catch (RemoteException e) {
4038 // Ignore if the remote process is no longer available to call back.
4039 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4040 }
4041 });
4042 } finally {
4043 Binder.restoreCallingIdentity(token);
4044 }
4045 }
4046
4047 /**
4048 * Get the transport type for the IMS service registration state.
4049 */
4050 @Override
4051 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004052 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004053 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004054 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4055 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4056 "IMS not available on device.");
4057 }
4058 final long token = Binder.clearCallingIdentity();
4059 try {
4060 Phone phone = getPhone(subId);
4061 if (phone == null) {
4062 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4063 + subId + "'");
4064 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4065 }
4066 phone.getImsRegistrationTech(regTech -> {
4067 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4068 int regTechConverted = (regTech == null)
4069 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4070 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4071 regTechConverted);
4072 try {
4073 consumer.accept(regTechConverted);
4074 } catch (RemoteException e) {
4075 // Ignore if the remote process is no longer available to call back.
4076 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4077 }
4078 });
4079 } finally {
4080 Binder.restoreCallingIdentity(token);
4081 }
4082 }
4083
shilu366312e2019-12-17 09:28:10 -08004084 /**
4085 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4086 * @param subId The subscription to use to check the configuration.
4087 * @param c The callback that will be used to send the result.
4088 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004090 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4091 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004092 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004093 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004094 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4095 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4096 "IMS not available on device.");
4097 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 final long token = Binder.clearCallingIdentity();
4099 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004100 int slotId = getSlotIndexOrException(subId);
4101 verifyImsMmTelConfiguredOrThrow(slotId);
4102 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004103 } catch (ImsException e) {
4104 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 } finally {
4106 Binder.restoreCallingIdentity(token);
4107 }
4108 }
4109
shilu366312e2019-12-17 09:28:10 -08004110 /**
4111 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4112 * @param subId The subscription to use to check the configuration.
4113 * @param c The callback that will be used to send the result.
4114 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004116 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004117 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004118 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4120 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4121 }
Meng Wangafbc5852019-09-19 17:37:13 -07004122
4123 final long token = Binder.clearCallingIdentity();
4124 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004125 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004126 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004127 } catch (ImsException e) {
4128 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4129 + "is inactive, ignoring unregister.");
4130 // If the subscription is no longer active, just return, since the callback
4131 // will already have been removed internally.
4132 } finally {
4133 Binder.restoreCallingIdentity(token);
4134 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 }
4136
4137 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004138 public boolean isCapable(int subId, int capability, int regTech) {
4139 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 final long token = Binder.clearCallingIdentity();
4141 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004142 int slotId = getSlotIndexOrException(subId);
4143 verifyImsMmTelConfiguredOrThrow(slotId);
4144 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004145 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4147 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004149 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4150 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 } finally {
4152 Binder.restoreCallingIdentity(token);
4153 }
4154 }
4155
4156 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004157 public boolean isAvailable(int subId, int capability, int regTech) {
4158 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 final long token = Binder.clearCallingIdentity();
4160 try {
4161 Phone phone = getPhone(subId);
4162 if (phone == null) return false;
4163 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004164 } catch (com.android.ims.ImsException e) {
4165 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4166 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 } finally {
4168 Binder.restoreCallingIdentity(token);
4169 }
4170 }
4171
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004172 /**
4173 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4174 * subscription.
4175 * @param subId The subscription to use to check the configuration.
4176 * @param callback The callback that will be used to send the result.
4177 * @param capability The MmTelFeature capability that will be used to send the result.
4178 * @param transportType The transport type of the MmTelFeature capability.
4179 */
4180 @Override
4181 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4182 int transportType) {
4183 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4184 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4185 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4186 "IMS not available on device.");
4187 }
4188 final long token = Binder.clearCallingIdentity();
4189 try {
4190 int slotId = getSlotIndex(subId);
4191 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4192 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4193 + subId + "'");
4194 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4195 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004196 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004197 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4198 transportType, aBoolean -> {
4199 try {
4200 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4201 } catch (RemoteException e) {
4202 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4203 + "running. Ignore");
4204 }
4205 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004206 } catch (ImsException e) {
4207 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004208 } finally {
4209 Binder.restoreCallingIdentity(token);
4210 }
4211 }
4212
shilu366312e2019-12-17 09:28:10 -08004213 /**
4214 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4215 * @param subId The subscription to use to check the configuration.
4216 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 @Override
4218 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004219 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004220 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004221
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 final long token = Binder.clearCallingIdentity();
4223 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004225 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004226 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 } catch (ImsException e) {
4228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(token);
4231 }
4232 }
4233
4234 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004235 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004237 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 final long identity = Binder.clearCallingIdentity();
4239 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004240 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004241 // This setting doesn't require an active ImsService connection, so do not verify. The
4242 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004243 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004244 } catch (ImsException e) {
4245 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
4249 }
4250
shilu366312e2019-12-17 09:28:10 -08004251 /**
4252 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4253 * @param subId The subscription to use to check the configuration.
4254 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004256 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004257 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004258 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 final long identity = Binder.clearCallingIdentity();
4260 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004262 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004263 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004264 } catch (ImsException e) {
4265 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
4269 }
4270
4271 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004272 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004274 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 final long identity = Binder.clearCallingIdentity();
4276 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004277 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004278 // This setting doesn't require an active ImsService connection, so do not verify. The
4279 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004280 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004281 } catch (ImsException e) {
4282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 }
4287
shilu366312e2019-12-17 09:28:10 -08004288 /**
4289 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4290 * @param subId The subscription to use to check the configuration.
4291 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 @Override
4293 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004294 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004295 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004299 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004300 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 } catch (ImsException e) {
4302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
4306 }
4307
4308 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004309 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004311 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 final long identity = Binder.clearCallingIdentity();
4313 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004314 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004315 // This setting doesn't require an active ImsService connection, so do not verify. The
4316 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004318 } catch (ImsException e) {
4319 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
shilu366312e2019-12-17 09:28:10 -08004325 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004326 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4327 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4328 * @param subId The subscription to use to check the configuration.
4329 */
4330 @Override
4331 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004332 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004333 mApp, subId, "isCrossSimCallingEnabledByUser");
4334 final long identity = Binder.clearCallingIdentity();
4335 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004337 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004339 } catch (ImsException e) {
4340 throw new ServiceSpecificException(e.getCode());
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
4344 }
4345
4346 /**
4347 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4348 * Requires MODIFY_PHONE_STATE permission.
4349 * @param subId The subscription to use to check the configuration.
4350 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4351 * false otherwise
4352 */
4353 @Override
4354 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4356 "setCrossSimCallingEnabled");
4357 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. The
4361 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004363 } catch (ImsException e) {
4364 throw new ServiceSpecificException(e.getCode());
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368 }
4369
4370 /**
shilu366312e2019-12-17 09:28:10 -08004371 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4372 * @param subId The subscription to use to check the configuration.
4373 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004375
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004377 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004378 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long identity = Binder.clearCallingIdentity();
4380 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004382 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004383 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
4389 }
4390
4391 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004392 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004394 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 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. The
4399 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004400 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004401 } catch (ImsException e) {
4402 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
4406 }
4407
4408 @Override
4409 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4411 "setVoWiFiNonPersistent");
4412 final long identity = Binder.clearCallingIdentity();
4413 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004415 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004416 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004417 } catch (ImsException e) {
4418 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
4422 }
4423
shilu366312e2019-12-17 09:28:10 -08004424 /**
4425 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4426 * @param subId The subscription to use to check the configuration.
4427 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004428 @Override
4429 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004430 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004431 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 final long identity = Binder.clearCallingIdentity();
4433 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004434 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004435 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004437 } catch (ImsException e) {
4438 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 } finally {
4440 Binder.restoreCallingIdentity(identity);
4441 }
4442 }
4443
4444 @Override
4445 public void setVoWiFiModeSetting(int subId, int mode) {
4446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4447 "setVoWiFiModeSetting");
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004451 // This setting doesn't require an active ImsService connection, so do not verify. The
4452 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004453 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004454 } catch (ImsException e) {
4455 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
4459 }
4460
4461 @Override
4462 public int getVoWiFiRoamingModeSetting(int subId) {
4463 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4464 final long identity = Binder.clearCallingIdentity();
4465 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004467 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004468 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004469 } catch (ImsException e) {
4470 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
4474 }
4475
4476 @Override
4477 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4479 "setVoWiFiRoamingModeSetting");
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004482 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004483 // This setting doesn't require an active ImsService connection, so do not verify. The
4484 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004485 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004486 } catch (ImsException e) {
4487 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
4491 }
4492
4493 @Override
4494 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4496 "setRttCapabilityEnabled");
4497 final long identity = Binder.clearCallingIdentity();
4498 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004499 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004500 // This setting doesn't require an active ImsService connection, so do not verify. The
4501 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004502 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004503 } catch (ImsException e) {
4504 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508 }
4509
shilu366312e2019-12-17 09:28:10 -08004510 /**
4511 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4512 * @param subId The subscription to use to check the configuration.
4513 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 @Override
4515 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004516 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004517 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 final long identity = Binder.clearCallingIdentity();
4519 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004521 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004523 } catch (ImsException e) {
4524 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004525 } finally {
4526 Binder.restoreCallingIdentity(identity);
4527 }
4528 }
4529
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 @Override
4531 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4532 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004535 if (!isImsAvailableOnDevice()) {
4536 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4537 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004538 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 int slotId = getSlotIndexOrException(subId);
4540 verifyImsMmTelConfiguredOrThrow(slotId);
4541 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004542 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004543 } catch (ImsException e) {
4544 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
4548 }
4549
4550 @Override
4551 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4552 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4553 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004554 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4555 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4556 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004557 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004558 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004559 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004560 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004561 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4562 + "is inactive, ignoring unregister.");
4563 // If the subscription is no longer active, just return, since the callback will already
4564 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
4568 }
4569
allenwtsu99c623b2020-01-03 18:24:23 +08004570
4571 private void checkModifyPhoneStatePermission(int subId, String message) {
4572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4573 message);
4574 }
4575
4576 private boolean isImsProvisioningRequired(int subId, int capability,
4577 boolean isMmtelCapability) {
4578 Phone phone = getPhone(subId);
4579 if (phone == null) {
4580 loge("phone instance null for subid " + subId);
4581 return false;
4582 }
4583 if (isMmtelCapability) {
4584 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4585 return false;
4586 }
4587 } else {
4588 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4589 return false;
4590 }
4591 }
4592 return true;
4593 }
4594
4595 @Override
4596 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4597 boolean isProvisioned) {
4598 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4599
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4603 if (!isImsProvisioningRequired(subId, capability, false)) {
4604 return;
4605 }
4606
4607 // this capability requires provisioning, route to the correct API.
4608 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4609 switch (capability) {
4610 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4611 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4612 ims.setEabProvisioned(isProvisioned);
4613 break;
4614 default: {
4615 throw new IllegalArgumentException("Tried to set provisioning for "
4616 + "rcs capability '" + capability + "', which does not require "
4617 + "provisioning.");
4618 }
4619 }
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623
4624 }
4625
4626
4627 @Override
4628 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4629 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4633 if (!isImsProvisioningRequired(subId, capability, false)) {
4634 return true;
4635 }
4636
4637 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4638 switch (capability) {
4639 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4640 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4641 return ims.isEabProvisionedOnDevice();
4642
4643 default: {
4644 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4645 + "capability '" + capability + "', which does not require "
4646 + "provisioning.");
4647 }
4648 }
4649
4650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
4653 }
4654
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004655 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4657 boolean isProvisioned) {
4658 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4660 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4661 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4663 }
allenwtsu99c623b2020-01-03 18:24:23 +08004664 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 final long identity = Binder.clearCallingIdentity();
4666 try {
4667 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004668 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004669 return;
4670 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004671 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4672 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4673 loge("setImsProvisioningStatusForCapability: called for technology that does "
4674 + "not support provisioning - " + tech);
4675 return;
4676 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004677
4678 // this capability requires provisioning, route to the correct API.
4679 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4680 switch (capability) {
4681 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4682 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4683 ims.setVolteProvisioned(isProvisioned);
4684 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4685 ims.setWfcProvisioned(isProvisioned);
4686 }
4687 break;
4688 }
4689 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4690 // There is currently no difference in VT provisioning type.
4691 ims.setVtProvisioned(isProvisioned);
4692 break;
4693 }
4694 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4695 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4696 // change the capability of the feature instead if needed.
4697 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4698 == isProvisioned) {
4699 // No change in provisioning.
4700 return;
4701 }
4702 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4703 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004704 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004705 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004706 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4707 + ", Exception" + e.getMessage());
4708 }
4709 break;
4710 }
4711 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004712 throw new IllegalArgumentException("Tried to set provisioning for "
4713 + "MmTel capability '" + capability + "', which does not require "
4714 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004715 }
4716 }
4717
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
4721 }
4722
4723 @Override
4724 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4725 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004726 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4727 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4728 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004729 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4730 }
4731 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004735 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004736 return true;
4737 }
4738
Brad Ebinger0d79c572021-04-17 15:20:49 -07004739 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4740 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4741 loge("getImsProvisioningStatusForCapability: called for technology that does "
4742 + "not support provisioning - " + tech);
4743 return true;
4744 }
4745
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004746 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4747 switch (capability) {
4748 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4749 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4750 return ims.isVolteProvisionedOnDevice();
4751 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4752 return ims.isWfcProvisionedOnDevice();
4753 }
4754 // This should never happen, since we are checking tech above to make sure it
4755 // is either LTE or IWLAN.
4756 throw new IllegalArgumentException("Invalid radio technology for voice "
4757 + "capability.");
4758 }
4759 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4760 // There is currently no difference in VT provisioning type.
4761 return ims.isVtProvisionedOnDevice();
4762 }
4763 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4764 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4765 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4766 }
4767 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004768 throw new IllegalArgumentException(
4769 "Tried to get provisioning for MmTel capability '" + capability
4770 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004771 }
4772 }
4773
4774 } finally {
4775 Binder.restoreCallingIdentity(identity);
4776 }
4777 }
4778
4779 @Override
4780 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4781 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4782 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4783 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4784 }
4785 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4786 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4787 return (provisionedBits & capability) > 0;
4788 }
4789
4790 @Override
4791 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4792 boolean isProvisioned) {
4793 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4794 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4795 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4796 }
4797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4798 "setProvisioningStatusForCapability");
4799 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4800 // If the current provisioning status for capability already matches isProvisioned,
4801 // do nothing.
4802 if (((provisionedBits & capability) > 0) == isProvisioned) {
4803 return;
4804 }
4805 if (isProvisioned) {
4806 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4807 } else {
4808 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4809 }
4810 }
4811
4812 /**
4813 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4814 * technology. The bitfield should mirror the bitfield defined by
4815 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4816 */
4817 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4818 String key = getMmTelProvisioningKey(subId, tech);
4819 // Default is no capabilities are provisioned.
4820 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4821 }
4822
4823 /**
4824 * Sets the MmTel capability provisioning bitfield (defined by
4825 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4826 * technology specified.
4827 *
4828 * Note: This is a synchronous command and should not be called on UI thread.
4829 */
4830 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4831 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4832 String key = getMmTelProvisioningKey(subId, tech);
4833 editor.putInt(key, newField);
4834 editor.commit();
4835 }
4836
4837 private static String getMmTelProvisioningKey(int subId, int tech) {
4838 // resulting key is provision_ims_mmtel_{subId}_{tech}
4839 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4840 }
4841
4842 /**
4843 * Query CarrierConfig to see if the specified capability requires provisioning for the
4844 * carrier associated with the subscription id.
4845 */
4846 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4847 int capability) {
4848 CarrierConfigManager configManager = new CarrierConfigManager(context);
4849 PersistableBundle c = configManager.getConfigForSubId(subId);
4850 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004851 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004852 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4853 false);
4854 boolean requireVoiceVtProvisioning = c.getBoolean(
4855 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4856
4857 // First check to make sure that the capability requires provisioning.
4858 switch (capability) {
4859 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4860 // intentional fallthrough
4861 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4862 if (requireVoiceVtProvisioning) {
4863 // Voice and Video requires provisioning
4864 return true;
4865 }
4866 break;
4867 }
4868 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4869 if (requireUtProvisioning) {
4870 // UT requires provisioning
4871 return true;
4872 }
4873 break;
4874 }
4875 }
4876 return false;
4877 }
4878
allenwtsu99c623b2020-01-03 18:24:23 +08004879 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4880 int capability) {
4881 CarrierConfigManager configManager = new CarrierConfigManager(context);
4882 PersistableBundle c = configManager.getConfigForSubId(subId);
4883
4884 boolean requireRcsProvisioning = c.getBoolean(
4885 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4886
4887 // First check to make sure that the capability requires provisioning.
4888 switch (capability) {
4889 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4890 // intentional fallthrough
4891 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4892 if (requireRcsProvisioning) {
4893 // OPTION or PRESENCE requires provisioning
4894 return true;
4895 }
4896 break;
4897 }
4898 }
4899 return false;
4900 }
4901
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004903 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4905 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4906 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004907 enforceReadPrivilegedPermission("getImsProvisioningInt");
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911 int slotId = getSlotIndex(subId);
4912 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4913 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4914 + subId + "' for key:" + key);
4915 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4916 }
calvinpanb5a34062021-02-08 19:59:36 +08004917 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004918 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4920 + subId + "' for key:" + key);
4921 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
4925 }
4926
4927 @Override
4928 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4930 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4931 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 enforceReadPrivilegedPermission("getImsProvisioningString");
4933 final long identity = Binder.clearCallingIdentity();
4934 try {
4935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004936 int slotId = getSlotIndex(subId);
4937 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4938 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4939 + subId + "' for key:" + key);
4940 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4941 }
calvinpanb5a34062021-02-08 19:59:36 +08004942 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004943 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4945 + subId + "' for key:" + key);
4946 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004947 } finally {
4948 Binder.restoreCallingIdentity(identity);
4949 }
4950 }
4951
4952 @Override
4953 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004954 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4955 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4956 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4958 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004962 int slotId = getSlotIndex(subId);
4963 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4964 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4965 + subId + "' for key:" + key);
4966 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4967 }
calvinpanb5a34062021-02-08 19:59:36 +08004968 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4969 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004971 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
4976 }
4977
4978 @Override
4979 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4981 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4982 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4984 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004985 final long identity = Binder.clearCallingIdentity();
4986 try {
4987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004988 int slotId = getSlotIndex(subId);
4989 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4990 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4991 + subId + "' for key:" + key);
4992 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4993 }
calvinpanb5a34062021-02-08 19:59:36 +08004994 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4995 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004997 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
5002 }
5003
Brad Ebinger919631e2021-06-02 17:46:35 -07005004 /**
5005 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5006 * for the given slot ID or no ImsResolver instance has been created.
5007 * @param slotId The slot ID that the IMS service is created for.
5008 * @throws ImsException If there is no ImsService configured for this slot.
5009 */
5010 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5011 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5012 ImsFeature.FEATURE_MMTEL)) {
5013 throw new ImsException("This subscription does not support MMTEL over IMS",
5014 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5015 }
5016 }
5017
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005018 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005019 int slotId = SubscriptionManager.getSlotIndex(subId);
5020 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005021 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5022 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005023 }
5024 return slotId;
5025 }
5026
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005027 private int getSlotIndex(int subId) {
5028 int slotId = SubscriptionManager.getSlotIndex(subId);
5029 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5030 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5031 }
5032 return slotId;
5033 }
5034
Wink Saville36469e72014-06-11 15:17:00 -07005035 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005036 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005037 */
5038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005039 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5040 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005041 try {
5042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5043 } catch (SecurityException se) {
5044 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5045 throw new SecurityException("Package " + callingPackage + " does not belong to "
5046 + Binder.getCallingUid());
5047 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005048 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005049 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005050 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005051 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005052 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005053 mApp, subId, callingPackage, callingFeatureId,
5054 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005055 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5056 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 final Phone phone = getPhone(subId);
5061 if (phone != null) {
5062 return phone.getServiceState().getDataNetworkType();
5063 } else {
5064 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5065 }
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005069 }
5070
5071 /**
5072 * Returns the data network type
5073 */
5074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005075 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005076 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5077 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005078 }
5079
5080 /**
5081 * Returns the data network type for a subId
5082 */
5083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005084 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5085 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005086 String functionName = "getDataNetworkTypeForSubscriber";
5087 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5088 mApp, functionName)) {
5089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5090 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5091 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5092 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005093 }
5094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 final Phone phone = getPhone(subId);
5098 if (phone != null) {
5099 return phone.getServiceState().getDataNetworkType();
5100 } else {
5101 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5102 }
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005106 }
5107
5108 /**
Wink Saville36469e72014-06-11 15:17:00 -07005109 * Returns the Voice network type for a subId
5110 */
5111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005112 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5113 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005114 String functionName = "getVoiceNetworkTypeForSubscriber";
5115 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5116 mApp, functionName)) {
5117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5118 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5119 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5120 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005121 }
5122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 final long identity = Binder.clearCallingIdentity();
5124 try {
5125 final Phone phone = getPhone(subId);
5126 if (phone != null) {
5127 return phone.getServiceState().getVoiceNetworkType();
5128 } else {
5129 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5130 }
5131 } finally {
5132 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005134 }
5135
5136 /**
5137 * @return true if a ICC card is present
5138 */
5139 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005140 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005141 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5142 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005143 }
5144
5145 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005146 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005147 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005148 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005149 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 final Phone phone = PhoneFactory.getPhone(slotIndex);
5153 if (phone != null) {
5154 return phone.getIccCard().hasIccCard();
5155 } else {
5156 return false;
5157 }
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 }
5162
5163 /**
5164 * Return if the current radio is LTE on CDMA. This
5165 * is a tri-state return value as for a period of time
5166 * the mode may be unknown.
5167 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005168 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005169 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005170 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005171 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005172 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005173 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5174 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5175 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005176 }
5177
Sanket Padawe356d7632015-06-22 14:03:32 -07005178 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005179 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5180 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005181 try {
5182 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5183 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005184 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5185 }
5186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 final Phone phone = getPhone(subId);
5190 if (phone == null) {
5191 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5192 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005193 return TelephonyProperties.lte_on_cdma_device()
5194 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 }
5196 } finally {
5197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005198 }
Wink Saville36469e72014-06-11 15:17:00 -07005199 }
5200
Wink Saville36469e72014-06-11 15:17:00 -07005201 /**
5202 * {@hide}
5203 * Returns Default subId, 0 in the case of single standby.
5204 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005205 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005206 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005207 }
5208
Shishir Agrawala9f32182016-04-12 12:00:16 -07005209 private int getSlotForDefaultSubscription() {
5210 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5211 }
5212
Wink Savilleb564aae2014-10-23 10:18:09 -07005213 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005214 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005215 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005216
Pengquan Menge92a50d2018-09-21 15:54:48 -07005217 private boolean isActiveSubscription(int subId) {
5218 return mSubscriptionController.isActiveSubId(subId);
5219 }
5220
Ihab Awadf2177b72013-11-25 13:33:23 -08005221 /**
5222 * @see android.telephony.TelephonyManager.WifiCallingChoices
5223 */
5224 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5229 getWhenToMakeWifiCallsDefaultPreference());
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005233 }
5234
5235 /**
5236 * @see android.telephony.TelephonyManager.WifiCallingChoices
5237 */
5238 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
5241 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005242 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005247 }
5248
Sailesh Nepald1e68152013-12-12 19:08:02 -08005249 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005250 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005251 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005252 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005253
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005254 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5255 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5256 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005257 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005258 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5259 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005260 }
5261 return PhoneFactory.getPhone(phoneId);
5262 }
5263
Shishir Agrawal566b7612013-10-28 14:41:00 -07005264 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005265 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005266 @NonNull IccLogicalChannelRequest request) {
5267 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5268 /*message=*/ "iccOpenLogicalChannel");
5269
5270 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5271 // Verify that the callingPackage in the request belongs to the calling UID
5272 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5273
5274 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005276
Rambo Wanga1782702021-11-10 20:15:19 -08005277 private Phone getPhoneFromValidIccLogicalChannelRequest(
5278 @NonNull IccLogicalChannelRequest request, String message) {
5279 Phone phone;
5280 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5282 mApp, request.subId, message);
5283 phone = getPhoneFromSubId(request.subId);
5284 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5285 enforceModifyPermission();
5286 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5287 } else {
5288 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005289 }
Rambo Wanga1782702021-11-10 20:15:19 -08005290 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005291 }
5292
5293 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005294 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 final long identity = Binder.clearCallingIdentity();
5296 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005297 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005299 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5300 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005301 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5302 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 loge("The calling package is not allowed to access ISD-R.");
5304 throw new SecurityException(
5305 "The calling package is not allowed to access ISD-R.");
5306 }
Derek Tan740e1672017-06-27 14:56:27 -07005307 }
Derek Tan740e1672017-06-27 14:56:27 -07005308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005310 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5311 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 return response;
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005316 }
5317
5318 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005319 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5320 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5321 /*message=*/"iccCloseLogicalChannel");
5322
5323 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5324
5325 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005326 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005327
Rambo Wanga1782702021-11-10 20:15:19 -08005328 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5329 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 final long identity = Binder.clearCallingIdentity();
5331 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005332 if (request.channel < 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 return false;
5334 }
Rambo Wanga1782702021-11-10 20:15:19 -08005335 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005336 null /* workSource */);
Rambo Wanga1782702021-11-10 20:15:19 -08005337 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 return success;
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005342 }
5343
5344 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005345 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005346 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5348 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005349 if (DBG) {
5350 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5351 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5352 + p3 + " data=" + data);
5353 }
5354 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5355 command, p1, p2, p3, data);
5356 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005357
Jordan Liu4c733742019-02-28 12:03:40 -08005358 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005359 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5360 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005361 enforceModifyPermission();
5362 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005363 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5364 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5365 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005366 }
5367 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005368 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5369 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005370 }
5371
5372 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5373 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 final long identity = Binder.clearCallingIdentity();
5375 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005376 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 return "";
5378 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005381 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5382 null /* workSource */);
5383 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 // Append the returned status code to the end of the response payload.
5386 String s = Integer.toHexString(
5387 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5388 if (response.payload != null) {
5389 s = IccUtils.bytesToHexString(response.payload) + s;
5390 }
5391 return s;
5392 } finally {
5393 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005394 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005395 }
Jake Hambye994d462014-02-03 13:10:13 -08005396
Evan Charltonc66da362014-05-16 14:06:40 -07005397 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005398 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5399 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5401 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005403 if (DBG) {
5404 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5405 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5406 }
5407 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5408 cla, command, p1, p2, p3, data);
5409 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005410
Jordan Liu4c733742019-02-28 12:03:40 -08005411 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005412 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5413 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005414 enforceModifyPermission();
5415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5416 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005417 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5418 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5419 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005420 }
5421
5422 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005423 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5424 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005425 }
5426
5427 // open APDU basic channel assuming the caller has sufficient permissions
5428 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5429 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5433 && TextUtils.equals(ISDR_AID, data)) {
5434 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005435 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5436 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 if (bestComponent == null
5438 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5439 loge("The calling package is not allowed to select ISD-R.");
5440 throw new SecurityException(
5441 "The calling package is not allowed to select ISD-R.");
5442 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005443 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005446 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5447 null /* workSource */);
5448 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 // Append the returned status code to the end of the response payload.
5451 String s = Integer.toHexString(
5452 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5453 if (response.payload != null) {
5454 s = IccUtils.bytesToHexString(response.payload) + s;
5455 }
5456 return s;
5457 } finally {
5458 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005459 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005460 }
5461
5462 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005463 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005464 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5466 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 if (DBG) {
5471 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5472 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5473 }
5474
5475 IccIoResult response =
5476 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5477 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5478 subId);
5479
5480 if (DBG) {
5481 log("Exchange SIM_IO [R]" + response);
5482 }
5483
5484 byte[] result = null;
5485 int length = 2;
5486 if (response.payload != null) {
5487 length = 2 + response.payload.length;
5488 result = new byte[length];
5489 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5490 } else {
5491 result = new byte[length];
5492 }
5493
5494 result[length - 1] = (byte) response.sw2;
5495 result[length - 2] = (byte) response.sw1;
5496 return result;
5497 } finally {
5498 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005499 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005500 }
5501
Nathan Haroldb3014052017-01-25 15:57:32 -08005502 /**
5503 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5504 * on a particular subscription
5505 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005506 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5507 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005509 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005510 return null;
5511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512
5513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 if (appType != TelephonyManager.APPTYPE_USIM
5516 && appType != TelephonyManager.APPTYPE_SIM) {
5517 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5518 return null;
5519 }
5520 Object response = sendRequest(
5521 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5522 if (response instanceof String[]) {
5523 return (String[]) response;
5524 }
yincheng zhao2737e882019-09-06 17:06:54 -07005525 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005527 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 } finally {
5529 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005530 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005531 }
5532
yincheng zhao2737e882019-09-06 17:06:54 -07005533 /**
5534 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5535 * subscription.
5536 *
5537 * @param subId the id of the subscription.
5538 * @param appType the uicc app type, must be USIM or SIM.
5539 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5540 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005541 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005542 * @return number of fplmns that is successfully written to the SIM.
5543 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005544 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5545 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5547 mApp, subId, "setForbiddenPlmns");
5548
yincheng zhao2737e882019-09-06 17:06:54 -07005549 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5550 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5551 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5552 }
5553 if (fplmns == null) {
5554 throw new IllegalArgumentException("Fplmn List provided is null");
5555 }
5556 for (String fplmn : fplmns) {
5557 if (!CellIdentity.isValidPlmn(fplmn)) {
5558 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5559 }
5560 }
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 Object response = sendRequest(
5564 CMD_SET_FORBIDDEN_PLMNS,
5565 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5566 subId);
5567 return (int) response;
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005573 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005574 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5576 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5581 if (response.payload == null) {
5582 return "";
5583 }
Evan Charltonc66da362014-05-16 14:06:40 -07005584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 // Append the returned status code to the end of the response payload.
5586 String s = Integer.toHexString(
5587 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5588 s = IccUtils.bytesToHexString(response.payload) + s;
5589 return s;
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
Evan Charltonc66da362014-05-16 14:06:40 -07005593 }
5594
Jake Hambye994d462014-02-03 13:10:13 -08005595 /**
5596 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5597 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5598 *
5599 * @param itemID the ID of the item to read
5600 * @return the NV item as a String, or null on error.
5601 */
5602 @Override
5603 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005604 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5606 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005611 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5613 return value;
5614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
Jake Hambye994d462014-02-03 13:10:13 -08005617 }
5618
5619 /**
5620 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5621 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5622 *
5623 * @param itemID the ID of the item to read
5624 * @param itemValue the value to write, as a String
5625 * @return true on success; false on any failure
5626 */
5627 @Override
5628 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005629 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5636 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005637 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5639 return success;
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Jake Hambye994d462014-02-03 13:10:13 -08005643 }
5644
5645 /**
5646 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5647 * Used for device configuration by some CDMA operators.
5648 *
5649 * @param preferredRoamingList byte array containing the new PRL
5650 * @return true on success; false on any failure
5651 */
5652 @Override
5653 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5655 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5660 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5661 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5662 return success;
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Jake Hambye994d462014-02-03 13:10:13 -08005666 }
5667
5668 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005669 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005670 * Used for device configuration by some CDMA operators.
5671 *
chen xu6dac5ab2018-10-26 17:39:23 -07005672 * @param slotIndex - device slot.
5673 *
Jake Hambye994d462014-02-03 13:10:13 -08005674 * @return true on success; false on any failure
5675 */
5676 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005677 public boolean resetModemConfig(int slotIndex) {
5678 Phone phone = PhoneFactory.getPhone(slotIndex);
5679 if (phone != null) {
5680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5681 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682
chen xu6dac5ab2018-10-26 17:39:23 -07005683 final long identity = Binder.clearCallingIdentity();
5684 try {
5685 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5686 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5687 return success;
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
5690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 }
chen xu6dac5ab2018-10-26 17:39:23 -07005692 return false;
5693 }
5694
5695 /**
5696 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5697 *
5698 * @param slotIndex - device slot.
5699 *
5700 * @return true on success; false on any failure
5701 */
5702 @Override
5703 public boolean rebootModem(int slotIndex) {
5704 Phone phone = PhoneFactory.getPhone(slotIndex);
5705 if (phone != null) {
5706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5707 mApp, phone.getSubId(), "rebootModem");
5708
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5712 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5713 return success;
5714 } finally {
5715 Binder.restoreCallingIdentity(identity);
5716 }
5717 }
5718 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005719 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005720
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005721 public String[] getPcscfAddress(String apnType, String callingPackage,
5722 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005723 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5725 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005726 return new String[0];
5727 }
5728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005731 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
Wink Saville36469e72014-06-11 15:17:00 -07005735 }
5736
Brad Ebinger51f743a2017-01-23 13:50:20 -08005737 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005738 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5739 * {@link #disableIms(int)}.
5740 * @param slotIndex device slot.
5741 */
5742 public void resetIms(int slotIndex) {
5743 enforceModifyPermission();
5744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
5747 if (mImsResolver == null) {
5748 // may happen if the does not support IMS.
5749 return;
5750 }
5751 mImsResolver.disableIms(slotIndex);
5752 mImsResolver.enableIms(slotIndex);
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
5756 }
5757
5758 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005759 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5760 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005761 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005762 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005767 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005768 // may happen if the device does not support IMS.
5769 return;
5770 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005771 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005775 }
5776
5777 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005778 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5779 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005780 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005781 public void disableIms(int slotId) {
5782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005787 // may happen if the device does not support IMS.
5788 return;
5789 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005794 }
5795
5796 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005797 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5798 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005799 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005800 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005801 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005802 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803
5804 final long identity = Binder.clearCallingIdentity();
5805 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005806 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005807 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5808 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005809 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005810 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 } finally {
5812 Binder.restoreCallingIdentity(identity);
5813 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005814 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005815 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005816 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5817 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005818 @Override
5819 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005820 enforceModifyPermission();
5821
5822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005825 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
5829 }
5830
5831 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005832 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005833 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005834 */
5835 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005841 // may happen if the device does not support IMS.
5842 return null;
5843 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005848 }
5849
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005850 /**
5851 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005852 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005853 */
5854 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005860 // may happen if the device does not support IMS.
5861 return null;
5862 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005867 }
5868
Brad Ebinger884c07b2018-02-15 16:17:40 -08005869 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005870 * Sets the ImsService Package Name that Telephony will bind to.
5871 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005872 * @param slotIndex the slot ID that the ImsService should bind for.
5873 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 * @param featureTypes An integer array of feature types associated with a packageName.
5876 * @param packageName The name of the package that the current configuration will be replaced
5877 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005878 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005879 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5881 int[] featureTypes, String packageName) {
5882 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5885 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 final long identity = Binder.clearCallingIdentity();
5889 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005891 // may happen if the device does not support IMS.
5892 return false;
5893 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 Map<Integer, String> featureConfig = new HashMap<>();
5895 for (int featureType : featureTypes) {
5896 featureConfig.put(featureType, packageName);
5897 }
5898 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5899 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005903 }
5904
5905 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005906 * Clears any carrier ImsService overrides for the slot index specified that were previously
5907 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5908 *
5909 * This should only be used for testing.
5910 *
5911 * @param slotIndex the slot ID that the ImsService should bind for.
5912 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5913 */
5914 @Override
5915 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5916 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5918 "clearCarrierImsServiceOverride");
5919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5920 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5921 "clearCarrierImsServiceOverride");
5922
5923 final long identity = Binder.clearCallingIdentity();
5924 try {
5925 if (mImsResolver == null) {
5926 // may happen if the device does not support IMS.
5927 return false;
5928 }
5929 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5930 } finally {
5931 Binder.restoreCallingIdentity(identity);
5932 }
5933 }
5934
5935 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005937 *
5938 * @param slotId The slot that the ImsService is associated with.
5939 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5940 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005942 * @return the package name of the ImsService configuration.
5943 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005944 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5945 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005946 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005947 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005948 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005949 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5950 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 final long identity = Binder.clearCallingIdentity();
5953 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005954 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005955 // may happen if the device does not support IMS.
5956 return "";
5957 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005958 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005959 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5960 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005964 }
5965
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005966 /**
5967 * Get the MmTelFeature state associated with the requested subscription id.
5968 * @param subId The subscription that the MmTelFeature is associated with.
5969 * @param callback A callback with an integer containing the
5970 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5971 */
5972 @Override
5973 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5974 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5975 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5976 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5977 "IMS not available on device.");
5978 }
5979 final long token = Binder.clearCallingIdentity();
5980 try {
5981 int slotId = getSlotIndex(subId);
5982 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5983 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5984 + subId + "'");
5985 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5986 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005987 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005988 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5989 try {
5990 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5991 } catch (RemoteException e) {
5992 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5993 + "Ignore");
5994 }
5995 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005996 } catch (ImsException e) {
5997 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005998 } finally {
5999 Binder.restoreCallingIdentity(token);
6000 }
6001 }
6002
Daniel Brightbb5840b2021-01-12 15:48:18 -08006003 /**
6004 * Sets the ims registration state on all valid {@link Phone}s.
6005 */
6006 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006007 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008
6009 final long identity = Binder.clearCallingIdentity();
6010 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006011 // NOTE: Before S, this method only set the default phone.
6012 for (final Phone phone : PhoneFactory.getPhones()) {
6013 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6014 phone.setImsRegistrationState(registered);
6015 }
6016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
Wink Saville36469e72014-06-11 15:17:00 -07006020 }
6021
6022 /**
Stuart Scott54788802015-03-30 13:18:01 -07006023 * Set the network selection mode to automatic.
6024 *
6025 */
6026 @Override
6027 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6029 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030
6031 final long identity = Binder.clearCallingIdentity();
6032 try {
shilufc958392020-01-20 11:36:01 -08006033 if (!isActiveSubscription(subId)) {
6034 return;
6035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006037 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6038 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
Stuart Scott54788802015-03-30 13:18:01 -07006042 }
6043
Jack Yud10cdd42020-09-28 20:28:01 -07006044 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006045 * Ask the radio to connect to the input network and change selection mode to manual.
6046 *
6047 * @param subId the id of the subscription.
6048 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6049 * the operator to attach to.
6050 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6051 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6052 * normal network selection next time.
6053 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006054 */
6055 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006056 public boolean setNetworkSelectionModeManual(
6057 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6059 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006060
6061 if (!isActiveSubscription(subId)) {
6062 return false;
6063 }
6064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 final long identity = Binder.clearCallingIdentity();
6066 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006067 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006069 if (DBG) {
6070 log("setNetworkSelectionModeManual: subId: " + subId
6071 + " operator: " + operatorInfo);
6072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006077 }
shilu84f6e8b2019-12-19 13:58:01 -08006078 /**
6079 * Get the manual network selection
6080 *
6081 * @param subId the id of the subscription.
6082 *
6083 * @return the previously saved user selected PLMN
6084 */
6085 @Override
6086 public String getManualNetworkSelectionPlmn(int subId) {
6087 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006088 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006089 mApp, subId, "getManualNetworkSelectionPlmn");
6090
6091 final long identity = Binder.clearCallingIdentity();
6092 try {
6093 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006094 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006095 }
6096
6097 final Phone phone = getPhone(subId);
6098 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006099 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006100 }
6101 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6102 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6103 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
6107 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006108
6109 /**
6110 * Scans for available networks.
6111 */
6112 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006113 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6114 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6116 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006117 LocationAccessPolicy.LocationPermissionResult locationResult =
6118 LocationAccessPolicy.checkLocationPermission(mApp,
6119 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6120 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006121 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006122 .setCallingPid(Binder.getCallingPid())
6123 .setCallingUid(Binder.getCallingUid())
6124 .setMethod("getCellNetworkScanResults")
6125 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006126 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6127 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006128 .build());
6129 switch (locationResult) {
6130 case DENIED_HARD:
6131 throw new SecurityException("Not allowed to access scan results -- location");
6132 case DENIED_SOFT:
6133 return null;
6134 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135
Pengquan Menga1bb6272018-09-06 09:59:22 -07006136 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 try {
6138 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006139 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006144 }
6145
6146 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006147 * Get the call forwarding info, given the call forwarding reason.
6148 */
6149 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006150 public void getCallForwarding(int subId, int callForwardingReason,
6151 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006152 enforceReadPrivilegedPermission("getCallForwarding");
6153 long identity = Binder.clearCallingIdentity();
6154 try {
6155 if (DBG) {
6156 log("getCallForwarding: subId " + subId
6157 + " callForwardingReason" + callForwardingReason);
6158 }
Hall Liu27d24262020-09-18 19:04:59 -07006159
6160 Phone phone = getPhone(subId);
6161 if (phone == null) {
6162 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006163 callback.onError(
6164 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006165 } catch (RemoteException e) {
6166 // ignore
6167 }
6168 return;
6169 }
6170
6171 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6172 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6173 @Override
6174 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6175 try {
6176 callback.onCallForwardingInfoAvailable(info);
6177 } catch (RemoteException e) {
6178 // ignore
6179 }
6180 }
6181
6182 @Override
6183 public void onError(int error) {
6184 try {
6185 callback.onError(error);
6186 } catch (RemoteException e) {
6187 // ignore
6188 }
6189 }
6190 });
6191 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
6195 }
6196
6197 /**
6198 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6199 * reason, the number to forward, and the timeout before the forwarding is attempted.
6200 */
6201 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006202 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6203 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006204 enforceModifyPermission();
6205 long identity = Binder.clearCallingIdentity();
6206 try {
6207 if (DBG) {
6208 log("setCallForwarding: subId " + subId
6209 + " callForwardingInfo" + callForwardingInfo);
6210 }
Hall Liu27d24262020-09-18 19:04:59 -07006211
6212 Phone phone = getPhone(subId);
6213 if (phone == null) {
6214 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006215 callback.accept(
6216 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006217 } catch (RemoteException e) {
6218 // ignore
6219 }
6220 return;
6221 }
6222
6223 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6224 FunctionalUtils.ignoreRemoteException(callback::accept));
6225
6226 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006227 } finally {
6228 Binder.restoreCallingIdentity(identity);
6229 }
6230 }
6231
6232 /**
Hall Liu27d24262020-09-18 19:04:59 -07006233 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006234 */
6235 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006236 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006237 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006238 long identity = Binder.clearCallingIdentity();
6239 try {
Hall Liu27d24262020-09-18 19:04:59 -07006240 Phone phone = getPhone(subId);
6241 if (phone == null) {
6242 try {
6243 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6244 } catch (RemoteException e) {
6245 // ignore
6246 }
6247 return;
6248 }
SongFerngWang0e767992021-03-31 22:08:45 +08006249 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6250 PersistableBundle c = configManager.getConfigForSubId(subId);
6251 boolean requireUssd = c.getBoolean(
6252 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006253
Shuo Qian4a594052020-01-23 11:59:30 -08006254 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006255 if (requireUssd) {
6256 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6257 getSubscriptionCarrierId(subId));
6258 String newUssdCommand = "";
6259 try {
6260 newUssdCommand = carrierXmlParser.getFeature(
6261 CarrierXmlParser.FEATURE_CALL_WAITING)
6262 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6263 } catch (NullPointerException e) {
6264 loge("Failed to generate USSD number" + e);
6265 }
6266 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6267 mMainThreadHandler, callback, carrierXmlParser,
6268 CarrierXmlParser.SsEntry.SSAction.QUERY);
6269 final String ussdCommand = newUssdCommand;
6270 Executors.newSingleThreadExecutor().execute(() -> {
6271 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6272 });
6273 } else {
6274 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6275 callback::accept);
6276 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6277 }
Shuo Qian4a594052020-01-23 11:59:30 -08006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
6281 }
6282
6283 /**
Hall Liu27d24262020-09-18 19:04:59 -07006284 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006285 */
6286 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006287 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006288 enforceModifyPermission();
6289 long identity = Binder.clearCallingIdentity();
6290 try {
Hall Liu27d24262020-09-18 19:04:59 -07006291 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6292
6293 Phone phone = getPhone(subId);
6294 if (phone == null) {
6295 try {
6296 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6297 } catch (RemoteException e) {
6298 // ignore
6299 }
6300 return;
6301 }
6302
SongFerngWang0e767992021-03-31 22:08:45 +08006303 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6304 PersistableBundle c = configManager.getConfigForSubId(subId);
6305 boolean requireUssd = c.getBoolean(
6306 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006307
SongFerngWang0e767992021-03-31 22:08:45 +08006308 if (DBG) log("getCallWaitingStatus: subId " + subId);
6309 if (requireUssd) {
6310 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6311 getSubscriptionCarrierId(subId));
6312 CarrierXmlParser.SsEntry.SSAction ssAction =
6313 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6314 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6315 String newUssdCommand = "";
6316 try {
6317 newUssdCommand = carrierXmlParser.getFeature(
6318 CarrierXmlParser.FEATURE_CALL_WAITING)
6319 .makeCommand(ssAction, null);
6320 } catch (NullPointerException e) {
6321 loge("Failed to generate USSD number" + e);
6322 }
6323 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6324 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6325 final String ussdCommand = newUssdCommand;
6326 Executors.newSingleThreadExecutor().execute(() -> {
6327 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6328 });
6329 } else {
6330 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6331 FunctionalUtils.ignoreRemoteException(callback::accept));
6332
6333 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6334 }
Shuo Qian4a594052020-01-23 11:59:30 -08006335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
6338 }
6339
6340 /**
yinxub1bed742017-04-17 11:45:04 -07006341 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006342 *
yinxub1bed742017-04-17 11:45:04 -07006343 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006344 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6345 * location related information which will be sent if the caller already possess
6346 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006347 * @param request contains the radio access networks with bands/channels to scan
6348 * @param messenger callback messenger for scan results or errors
6349 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006350 * @return the id of the requested scan which can be used to stop the scan.
6351 */
6352 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006353 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6354 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006355 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6357 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006358 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006359 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6360 if (!renounceFineLocationAccess) {
6361 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6362 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6363 .setCallingPackage(callingPackage)
6364 .setCallingFeatureId(callingFeatureId)
6365 .setCallingPid(Binder.getCallingPid())
6366 .setCallingUid(Binder.getCallingUid())
6367 .setMethod("requestNetworkScan")
6368 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6369 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6370 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6371 .build());
6372 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006373 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006374 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6375 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006376 if (e != null) {
6377 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6378 throw e;
6379 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006380 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006381 return TelephonyScanManager.INVALID_SCAN_ID;
6382 }
6383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 }
Hall Liu912dfd32019-04-25 14:02:26 -07006385 int callingUid = Binder.getCallingUid();
6386 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006387 final long identity = Binder.clearCallingIdentity();
6388 try {
6389 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006390 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006391 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
yinxu504e1392017-04-12 16:03:22 -07006395 }
6396
Hall Liub2ac8ef2019-02-28 15:56:23 -08006397 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006398 NetworkScanRequest request, int subId, String callingPackage) {
6399 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006400 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6401 boolean hasNetworkScanPermission =
6402 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6403 == PERMISSION_GRANTED;
6404
6405 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6406 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6407 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006408 }
6409
6410 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6411 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006412 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6413 return new SecurityException("Specific channels must not be"
6414 + " scanned without location access.");
6415 }
6416 }
6417 }
6418
Hall Liub2ac8ef2019-02-28 15:56:23 -08006419 return null;
6420 }
6421
yinxu504e1392017-04-12 16:03:22 -07006422 /**
6423 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006424 *
6425 * @param subId id of the subscription
6426 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006427 */
6428 @Override
6429 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6431 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432
Hall Liu912dfd32019-04-25 14:02:26 -07006433 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 final long identity = Binder.clearCallingIdentity();
6435 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006436 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
yinxu504e1392017-04-12 16:03:22 -07006440 }
6441
6442 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006443 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006444 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006445 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006446 */
6447 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006448 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006449 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006450 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006451 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452
6453 final long identity = Binder.clearCallingIdentity();
6454 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006455 if (DBG) log("getAllowedNetworkTypesBitmask");
6456 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6457 int networkTypesBitmask = (result != null ? result[0] : -1);
6458 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6459 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006463 }
6464
6465 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006466 * Get the allowed network types for certain reason.
6467 *
6468 * @param subId the id of the subscription.
6469 * @param reason the reason the allowed network type change is taking place
6470 * @return the allowed network types.
6471 */
6472 @Override
6473 public long getAllowedNetworkTypesForReason(int subId,
6474 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006475 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006476 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
6483 }
6484
6485 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006486 * Enable/Disable E-UTRA-NR Dual Connectivity
6487 * @param subId subscription id of the sim card
6488 * @param nrDualConnectivityState expected NR dual connectivity state
6489 * This can be passed following states
6490 * <ol>
6491 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6492 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6493 * <li>Disable NR dual connectivity and force secondary cell to be released
6494 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6495 * </ol>
6496 * @return operation result.
6497 */
6498 @Override
6499 public int setNrDualConnectivityState(int subId,
6500 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6502 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006503 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006504 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6505 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6506 }
6507
Sooraj Sasindran37444802020-08-11 10:40:43 -07006508 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6509 final long identity = Binder.clearCallingIdentity();
6510 try {
6511 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6512 nrDualConnectivityState, subId,
6513 workSource);
6514 if (DBG) log("enableNRDualConnectivity result: " + result);
6515 return result;
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
6519 }
6520
6521 /**
6522 * Is E-UTRA-NR Dual Connectivity enabled
6523 * @return true if dual connectivity is enabled else false
6524 */
6525 @Override
6526 public boolean isNrDualConnectivityEnabled(int subId) {
6527 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006528 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006529 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006530 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006531 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6532 return false;
6533 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006534 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6535 final long identity = Binder.clearCallingIdentity();
6536 try {
6537 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6538 null, subId, workSource);
6539 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6540 return isEnabled;
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
6544 }
6545
6546 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006547 * Set the allowed network types of the device and
6548 * provide the reason triggering the allowed network change.
6549 *
6550 * @param subId the id of the subscription.
6551 * @param reason the reason the allowed network type change is taking place
6552 * @param allowedNetworkTypes the allowed network types.
6553 * @return true on success; false on any failure.
6554 */
6555 @Override
6556 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 @TelephonyManager.AllowedNetworkTypesReason int reason,
6558 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6560 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006561 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006562 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6563 return false;
6564 }
6565 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6566 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006567 return false;
6568 }
6569
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006570 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6571 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6572
6573
6574 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6575 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6576 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006577 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006578
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006579 final long identity = Binder.clearCallingIdentity();
6580 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006581 Boolean success = (Boolean) sendRequest(
6582 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6583 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6584
6585 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6586 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006587 } finally {
6588 Binder.restoreCallingIdentity(identity);
6589 }
6590 }
6591
6592 /**
Miaoa84611c2019-03-15 09:21:10 +08006593 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006594 *
Miaoa84611c2019-03-15 09:21:10 +08006595 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006596 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006597 * @hide
6598 */
6599 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006600 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006601 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006603 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 try {
Miaoa84611c2019-03-15 09:21:10 +08006605 if (phone != null) {
6606 return phone.hasMatchedTetherApnSetting();
6607 } else {
6608 return false;
6609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 } finally {
6611 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006612 }
Junda Liu475951f2014-11-07 16:45:03 -08006613 }
6614
6615 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006616 * Get the user enabled state of Mobile Data.
6617 *
6618 * TODO: remove and use isUserDataEnabled.
6619 * This can't be removed now because some vendor codes
6620 * calls through ITelephony directly while they should
6621 * use TelephonyManager.
6622 *
6623 * @return true on enabled
6624 */
6625 @Override
6626 public boolean getDataEnabled(int subId) {
6627 return isUserDataEnabled(subId);
6628 }
6629
6630 /**
6631 * Get whether mobile data is enabled per user setting.
6632 *
6633 * There are other factors deciding whether mobile data is actually enabled, but they are
6634 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006635 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006636 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6637 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006638 *
6639 * @return {@code true} if data is enabled else {@code false}
6640 */
6641 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006642 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006643 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006644 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006645 try {
6646 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6647 functionName);
6648 } catch (Exception e) {
6649 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6650 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006651 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006653 mApp, subId, functionName);
6654
Robert Greenwalt646120a2014-05-23 11:54:03 -07006655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656
6657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 int phoneId = mSubscriptionController.getPhoneId(subId);
6660 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6661 Phone phone = PhoneFactory.getPhone(phoneId);
6662 if (phone != null) {
6663 boolean retVal = phone.isUserDataEnabled();
6664 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6665 return retVal;
6666 } else {
6667 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6668 return false;
6669 }
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006672 }
6673 }
6674
6675 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006676 * Checks if the device is capable of mobile data by considering whether whether the
6677 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6678 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006679 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006680 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006681 */
6682 @Override
6683 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006684 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006685 try {
6686 try {
6687 mApp.enforceCallingOrSelfPermission(
6688 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006689 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006690 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006691 try {
6692 mApp.enforceCallingOrSelfPermission(
6693 android.Manifest.permission.READ_PHONE_STATE,
6694 functionName);
6695 } catch (Exception e2) {
6696 mApp.enforceCallingOrSelfPermission(
6697 permission.READ_BASIC_PHONE_STATE, functionName);
6698 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006699 }
6700 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006701 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703
6704 final long identity = Binder.clearCallingIdentity();
6705 try {
6706 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 Phone phone = PhoneFactory.getPhone(phoneId);
6708 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006709 boolean retVal;
6710 if (phone.isUsingNewDataStack()) {
6711 retVal = phone.getDataNetworkController().getDataSettingsManager()
6712 .isDataEnabled();
6713 } else {
6714 retVal = phone.getDataEnabledSettings().isDataEnabled();
6715 }
6716 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 return retVal;
6718 } else {
6719 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6720 return false;
6721 }
6722 } finally {
6723 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006724 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006725 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006726
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006727 /**
6728 * Check if data is enabled for a specific reason
6729 * @param subId Subscription index
6730 * @param reason the reason the data enable change is taking place
6731 * @return {@code true} if the overall data is enabled; {@code false} if not.
6732 */
6733 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006734 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006735 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006736 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006737 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006738 try {
6739 mApp.enforceCallingOrSelfPermission(
6740 android.Manifest.permission.ACCESS_NETWORK_STATE,
6741 functionName);
6742 } catch (Exception e) {
6743 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6744 functionName);
6745 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006746 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006747 try {
6748 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006749 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006750 } catch (Exception e2) {
6751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006752 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006753 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006754 }
6755
6756
6757 final long identity = Binder.clearCallingIdentity();
6758 try {
6759 int phoneId = mSubscriptionController.getPhoneId(subId);
6760 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006761 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006762 + " reason=" + reason);
6763 }
6764 Phone phone = PhoneFactory.getPhone(phoneId);
6765 if (phone != null) {
6766 boolean retVal;
6767 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6768 retVal = phone.isUserDataEnabled();
6769 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006770 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006771 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006772 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006773 return retVal;
6774 } else {
6775 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006776 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006777 + subId + " retVal=false");
6778 }
6779 return false;
6780 }
6781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
6784 }
6785
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006786 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006787 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006788 if (uid == Process.PHONE_UID) {
6789 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6790 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6792 }
6793
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006794 //load access rules from carrier configs, and check those as well: b/139133814
6795 SubscriptionController subController = SubscriptionController.getInstance();
6796 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6797 || subController == null) return privilegeFromSim;
6798
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006799 PackageManager pkgMgr = phone.getContext().getPackageManager();
6800 String[] packages = pkgMgr.getPackagesForUid(uid);
6801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006804 int subId = phone.getSubId();
6805 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6806 // A test override is in place for the privileges for this subId, so don't try to
6807 // read the subscription privileges.
6808 return privilegeFromSim;
6809 }
6810 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006811 SubscriptionManager subManager = (SubscriptionManager)
6812 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6813 for (String pkg : packages) {
6814 if (subManager.canManageSubscription(subInfo, pkg)) {
6815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6816 }
6817 }
6818 return privilegeFromSim;
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
6822 }
6823
6824 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6825 String pkgName) {
6826 //load access rules from carrier configs, and check those as well: b/139133814
6827 SubscriptionController subController = SubscriptionController.getInstance();
6828 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6829 || subController == null) return privilegeFromSim;
6830
6831 final long identity = Binder.clearCallingIdentity();
6832 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006833 int subId = phone.getSubId();
6834 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6835 // A test override is in place for the privileges for this subId, so don't try to
6836 // read the subscription privileges.
6837 return privilegeFromSim;
6838 }
6839 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006840 SubscriptionManager subManager = (SubscriptionManager)
6841 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6842 return subManager.canManageSubscription(subInfo, pkgName)
6843 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6844 } finally {
6845 Binder.restoreCallingIdentity(identity);
6846 }
6847 }
6848
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006850 public int getCarrierPrivilegeStatus(int subId) {
6851 final Phone phone = getPhone(subId);
6852 if (phone == null) {
6853 loge("getCarrierPrivilegeStatus: Invalid subId");
6854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6855 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006856 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6857 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006858 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006859 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6860 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006861
6862 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006863 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006864 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006865 }
Junda Liu29340342014-07-10 15:23:27 -07006866
6867 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006868 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006869 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006870 final Phone phone = getPhone(subId);
6871 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006872 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006873 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6874 }
6875 UiccProfile profile =
6876 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6877 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006878 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006879 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6880 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006881 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006882 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006883 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006884 }
6885
6886 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006887 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006888 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006889 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006890 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006891 }
6892
6893 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006894 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6895 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006896 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006897 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6898 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006899 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006900 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006901 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006902 }
6903
6904 @Override
6905 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006906 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006907 if (TextUtils.isEmpty(pkgName))
6908 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006909 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6910 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006911 UiccPort port = UiccController.getInstance().getUiccPort(i);
6912 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006913 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006914 continue;
6915 }
6916
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006917 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006918 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006919 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006920 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6921 break;
6922 }
6923 }
6924
6925 return result;
Junda Liu29340342014-07-10 15:23:27 -07006926 }
Derek Tan89e89d42014-07-08 17:00:10 -07006927
6928 @Override
Junda Liue64de782015-04-16 17:19:16 -07006929 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006930 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006931 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6932 loge("phoneId " + phoneId + " is not valid.");
6933 return null;
6934 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006935 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6936 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006937 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006938 return null ;
6939 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006940 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006941 }
6942
Amith Yamasani6e118872016-02-19 12:53:51 -08006943 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006944 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006945 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006946 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006947 List<String> privilegedPackages = new ArrayList<>();
6948 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006949 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006950 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006951 if (port != null) {
6952 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006953 if (packages == null) {
6954 // Only check packages in user 0 for now
6955 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006956 PackageManager.MATCH_DISABLED_COMPONENTS
6957 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006958 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006959 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006960 }
6961 for (int p = packages.size() - 1; p >= 0; p--) {
6962 PackageInfo pkgInfo = packages.get(p);
6963 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006964 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6965 port.getCarrierPrivilegeStatus(pkgInfo),
6966 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006967 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006968 privilegedPackages.add(pkgInfo.packageName);
6969 }
6970 }
6971 }
6972 }
6973 return privilegedPackages;
6974 }
6975
chen xuf7e9fe82019-05-09 19:31:02 -07006976 @Override
6977 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006978 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6979
6980 final long identity = Binder.clearCallingIdentity();
6981
chen xuf7e9fe82019-05-09 19:31:02 -07006982 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006983 try {
6984 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6985 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6986 }
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006989 }
6990 return privilegedPackages;
6991 }
6992
Wink Savilleb564aae2014-10-23 10:18:09 -07006993 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006994 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006995 UiccPort port = phone == null ? null : phone.getUiccPort();
6996 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006997 return null;
6998 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006999 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007000 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007001 return null;
7002 }
7003 return iccId;
7004 }
7005
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007006 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007007 public void setCallComposerStatus(int subId, int status) {
7008 enforceModifyPermission();
7009
7010 final long identity = Binder.clearCallingIdentity();
7011 try {
7012 Phone phone = getPhone(subId);
7013 if (phone != null) {
7014 Phone defaultPhone = phone.getImsPhone();
7015 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7016 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7017 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007018 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7019 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007020 }
7021 }
Shuo Qian284ae752020-12-22 19:10:14 -08007022 } catch (ImsException e) {
7023 throw new ServiceSpecificException(e.getCode());
7024 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007025 Binder.restoreCallingIdentity(identity);
7026 }
7027 }
7028
7029 @Override
7030 public int getCallComposerStatus(int subId) {
7031 enforceReadPrivilegedPermission("getCallComposerStatus");
7032
7033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 Phone phone = getPhone(subId);
7036 if (phone != null) {
7037 Phone defaultPhone = phone.getImsPhone();
7038 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7039 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7040 return imsPhone.getCallComposerStatus();
7041 }
7042 }
7043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
7046 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7047 }
7048
7049 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007050 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7051 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007052 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007053 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 final long identity = Binder.clearCallingIdentity();
7056 try {
7057 final String iccId = getIccId(subId);
7058 final Phone phone = getPhone(subId);
7059 if (phone == null) {
7060 return false;
7061 }
7062 final String subscriberId = phone.getSubscriberId();
7063
7064 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007065 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 + subscriberId + " to " + number);
7067 }
7068
7069 if (TextUtils.isEmpty(iccId)) {
7070 return false;
7071 }
7072
7073 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7074
7075 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7076 if (alphaTag == null) {
7077 editor.remove(alphaTagPrefKey);
7078 } else {
7079 editor.putString(alphaTagPrefKey, alphaTag);
7080 }
7081
7082 // Record both the line number and IMSI for this ICCID, since we need to
7083 // track all merged IMSIs based on line number
7084 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7085 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7086 if (number == null) {
7087 editor.remove(numberPrefKey);
7088 editor.remove(subscriberPrefKey);
7089 } else {
7090 editor.putString(numberPrefKey, number);
7091 editor.putString(subscriberPrefKey, subscriberId);
7092 }
7093
7094 editor.commit();
7095 return true;
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007098 }
Derek Tan7226c842014-07-02 17:42:23 -07007099 }
7100
7101 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007102 public String getLine1NumberForDisplay(int subId, String callingPackage,
7103 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007104 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007106 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007107 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007108 return null;
7109 }
Derek Tan97ebb422014-09-05 16:55:38 -07007110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 String iccId = getIccId(subId);
7114 if (iccId != null) {
7115 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7116 if (DBG_MERGE) {
7117 log("getLine1NumberForDisplay returning "
7118 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7119 }
7120 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007121 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7123 return null;
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007126 }
Derek Tan7226c842014-07-02 17:42:23 -07007127 }
7128
7129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007130 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7131 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007133 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007134 return null;
7135 }
Derek Tan97ebb422014-09-05 16:55:38 -07007136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 final long identity = Binder.clearCallingIdentity();
7138 try {
7139 String iccId = getIccId(subId);
7140 if (iccId != null) {
7141 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7142 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7143 }
7144 return null;
7145 } finally {
7146 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007147 }
Derek Tan7226c842014-07-02 17:42:23 -07007148 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007149
7150 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007151 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7152 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007153 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7154 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007156 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007157 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007158 return null;
7159 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007160
Jordan Liub49b04b2019-05-06 14:45:15 -07007161 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7162 // the process, where TelephonyManager was instantiated.
7163 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007164 final long identity = Binder.clearCallingIdentity();
7165 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007166 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 final TelephonyManager tele = TelephonyManager.from(context);
7168 final SubscriptionManager sub = SubscriptionManager.from(context);
7169
7170 // Figure out what subscribers are currently active
7171 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172
Jordan Liub49b04b2019-05-06 14:45:15 -07007173 // Only consider subs which match the current subId
7174 // This logic can be simplified. See b/131189269 for progress.
7175 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007176 activeSubscriberIds.add(tele.getSubscriberId(subId));
7177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178
7179 // First pass, find a number override for an active subscriber
7180 String mergeNumber = null;
7181 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7182 for (String key : prefs.keySet()) {
7183 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7184 final String subscriberId = (String) prefs.get(key);
7185 if (activeSubscriberIds.contains(subscriberId)) {
7186 final String iccId = key.substring(
7187 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7188 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7189 mergeNumber = (String) prefs.get(numberKey);
7190 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007191 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 + " for active subscriber " + subscriberId);
7193 }
7194 if (!TextUtils.isEmpty(mergeNumber)) {
7195 break;
7196 }
7197 }
7198 }
7199 }
7200
7201 // Shortcut when no active merged subscribers
7202 if (TextUtils.isEmpty(mergeNumber)) {
7203 return null;
7204 }
7205
7206 // Second pass, find all subscribers under that line override
7207 final ArraySet<String> result = new ArraySet<>();
7208 for (String key : prefs.keySet()) {
7209 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7210 final String number = (String) prefs.get(key);
7211 if (mergeNumber.equals(number)) {
7212 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7213 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7214 final String subscriberId = (String) prefs.get(subscriberKey);
7215 if (!TextUtils.isEmpty(subscriberId)) {
7216 result.add(subscriberId);
7217 }
7218 }
7219 }
7220 }
7221
7222 final String[] resultArray = result.toArray(new String[result.size()]);
7223 Arrays.sort(resultArray);
7224 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007225 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007226 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7227 }
7228 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007229 } finally {
7230 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007231 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007232 }
7233
7234 @Override
zoey chen38003472019-12-13 17:16:31 +08007235 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7236 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 final TelephonyManager telephonyManager = mApp.getSystemService(
7241 TelephonyManager.class);
7242 String subscriberId = telephonyManager.getSubscriberId(subId);
7243 if (subscriberId == null) {
7244 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007245 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007246 + subId);
7247 }
7248 return null;
7249 }
7250
7251 final SubscriptionInfo info = SubscriptionController.getInstance()
7252 .getSubscriptionInfo(subId);
7253 final ParcelUuid groupUuid = info.getGroupUuid();
7254 // If it doesn't belong to any group, return just subscriberId of itself.
7255 if (groupUuid == null) {
7256 return new String[]{subscriberId};
7257 }
7258
7259 // Get all subscriberIds from the group.
7260 final List<String> mergedSubscriberIds = new ArrayList<>();
7261 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007262 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007263 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007264 for (SubscriptionInfo subInfo : groupInfos) {
7265 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7266 if (subscriberId != null) {
7267 mergedSubscriberIds.add(subscriberId);
7268 }
7269 }
7270
7271 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
7274
7275 }
7276 }
7277
7278 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007279 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007280 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007281 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282
7283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 final Phone phone = getPhone(subId);
7286 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007290 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007291
7292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007293 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007294 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7295 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007296 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7297 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 final Phone phone = getPhone(subId);
7302 if (phone == null) {
7303 return false;
7304 }
7305 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7306 cdmaNonRoamingList);
7307 } finally {
7308 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007309 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007310 }
7311
7312 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007313 @Deprecated
7314 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7315 enforceModifyPermission();
7316
7317 int returnValue = 0;
7318 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007319 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007320 if(result.exception == null) {
7321 if (result.result != null) {
7322 byte[] responseData = (byte[])(result.result);
7323 if(responseData.length > oemResp.length) {
7324 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7325 responseData.length + "bytes. Buffer Size is " +
7326 oemResp.length + "bytes.");
7327 }
7328 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7329 returnValue = responseData.length;
7330 }
7331 } else {
7332 CommandException ex = (CommandException) result.exception;
7333 returnValue = ex.getCommandError().ordinal();
7334 if(returnValue > 0) returnValue *= -1;
7335 }
7336 } catch (RuntimeException e) {
7337 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7338 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7339 if(returnValue > 0) returnValue *= -1;
7340 }
7341
7342 return returnValue;
7343 }
7344
7345 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007346 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007347 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007348 try {
7349 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007350 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007351 mApp, phone.getSubId(), "getRadioAccessFamily");
7352 } catch (SecurityException e) {
7353 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7354 throw e;
7355 }
chen xub97461a2018-10-26 14:17:57 -07007356 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007357 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007358 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 final long identity = Binder.clearCallingIdentity();
7361 try {
chen xub97461a2018-10-26 14:17:57 -07007362 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007363 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007364 mApp, phone.getSubId(), "getRadioAccessFamily");
7365 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
chen xub97461a2018-10-26 14:17:57 -07007369 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007370 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007371
7372 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007373 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007374 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007375 try {
7376 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7377 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007378 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007379 }
7380 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007381 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007382 }
7383 RoleManager rm = mApp.getSystemService(RoleManager.class);
7384 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7385 if (!dialerRoleHolders.contains(callingPackage)) {
7386 throw new SecurityException("App must be the dialer role holder to"
7387 + " upload a call composer pic");
7388 }
7389
7390 Executors.newSingleThreadExecutor().execute(() -> {
7391 ByteArrayOutputStream output = new ByteArrayOutputStream(
7392 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7393 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7394 boolean readUntilEnd = false;
7395 int totalBytesRead = 0;
7396 byte[] buffer = new byte[16 * 1024];
7397 while (true) {
7398 int numRead;
7399 try {
7400 numRead = input.read(buffer);
7401 } catch (IOException e) {
7402 try {
7403 fd.checkError();
7404 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7405 null);
7406 } catch (IOException e1) {
7407 // This means that the other side closed explicitly with an error. If this
7408 // happens, log and ignore.
7409 loge("Remote end of call composer picture pipe closed: " + e1);
7410 }
7411 break;
7412 }
7413 if (numRead == -1) {
7414 readUntilEnd = true;
7415 break;
7416 }
7417 totalBytesRead += numRead;
7418 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7419 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7420 try {
7421 input.close();
7422 } catch (IOException e) {
7423 // ignore
7424 }
7425 break;
7426 }
7427 output.write(buffer, 0, numRead);
7428 }
7429 // Generally, the remote end will close the file descriptors. The only case where we
7430 // close is above, where the picture size is too big.
7431
7432 try {
7433 fd.checkError();
7434 } catch (IOException e) {
7435 loge("Remote end for call composer closed with an error: " + e);
7436 return;
7437 }
7438
Hall Liuaa4211e2021-01-20 15:43:39 -08007439 if (!readUntilEnd) {
7440 loge("Did not finish reading entire image; aborting");
7441 return;
7442 }
Hall Liu82694d52020-12-11 18:22:04 -08007443
Hall Liuaa4211e2021-01-20 15:43:39 -08007444 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7445 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7446 new CallComposerPictureTransfer.Factory() {},
7447 imageData,
7448 (result) -> {
7449 if (result.first != null) {
7450 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7451 Bundle outputResult = new Bundle();
7452 outputResult.putParcelable(
7453 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7454 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7455 outputResult);
7456 } else {
7457 callback.send(result.second, null);
7458 }
7459 }
7460 );
Hall Liu82694d52020-12-11 18:22:04 -08007461 });
7462 }
7463
7464 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007465 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007466 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007467 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468
7469 final long identity = Binder.clearCallingIdentity();
7470 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007471 ImsManager.getInstance(defaultPhone.getContext(),
7472 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 } finally {
7474 Binder.restoreCallingIdentity(identity);
7475 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007476 }
7477
7478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007479 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007480 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7482 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007483 return false;
7484 }
Svet Ganovb320e182015-04-16 12:30:10 -07007485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 final long identity = Binder.clearCallingIdentity();
7487 try {
7488 // Check the user preference and the system-level IMS setting. Even if the user has
7489 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7490 // In the long run, we may instead need to check if there exists a connection service
7491 // which can support video calling.
7492 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007493 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 return imsManager.isVtEnabledByPlatform()
7495 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7496 && imsManager.isVtEnabledByUser();
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007500 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007501
Andrew Leea1239f22015-03-02 17:44:07 -08007502 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007503 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7504 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007506 mApp, subId, callingPackage, callingFeatureId,
7507 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 return false;
7509 }
7510
7511 final long identity = Binder.clearCallingIdentity();
7512 try {
7513 CarrierConfigManager configManager =
7514 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007515 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
Andrew Leea1239f22015-03-02 17:44:07 -08007520 }
7521
7522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007523 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007525 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 return false;
7527 }
7528
7529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 CarrierConfigManager configManager =
7532 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007533 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
Andrew Leea1239f22015-03-02 17:44:07 -08007538 }
7539
Andrew Lee9431b832015-03-09 18:46:45 -07007540 @Override
7541 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007542 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007543 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007544 }
7545
7546 @Override
7547 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 final long identity = Binder.clearCallingIdentity();
7549 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007550 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Andrew Lee9431b832015-03-09 18:46:45 -07007554 }
7555
Hall Liuf6668912018-10-31 17:05:23 -07007556 /**
7557 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7558 * support for the feature and device firmware support.
7559 *
7560 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7561 */
7562 @Override
7563 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007565 final Phone phone = getPhone(subscriptionId);
7566 if (phone == null) {
7567 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7568 return false;
7569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007571 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7573 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007574 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 return isCarrierSupported && isDeviceSupported;
7576 } finally {
7577 Binder.restoreCallingIdentity(identity);
7578 }
Hall Liu98187582018-01-22 19:15:32 -08007579 }
7580
Hall Liuf6668912018-10-31 17:05:23 -07007581 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007582 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7583 * RTT setting, will return true if the device and carrier both support RTT.
7584 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007585 */
7586 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 final long identity = Binder.clearCallingIdentity();
7588 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007589 boolean isRttSupported = isRttSupported(subscriptionId);
7590 boolean isUserRttSettingOn = Settings.Secure.getInt(
7591 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7592 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7593 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7594 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 } finally {
7596 Binder.restoreCallingIdentity(identity);
7597 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007598 }
7599
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007600 @Deprecated
7601 @Override
7602 public String getDeviceId(String callingPackage) {
7603 return getDeviceIdWithFeature(callingPackage, null);
7604 }
7605
Sanket Padawe7310cc72015-01-14 09:53:20 -08007606 /**
7607 * Returns the unique device ID of phone, for example, the IMEI for
7608 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7609 *
7610 * <p>Requires Permission:
7611 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7612 */
7613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007614 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007615 try {
7616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7617 } catch (SecurityException se) {
7618 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7619 throw new SecurityException("Package " + callingPackage + " does not belong to "
7620 + Binder.getCallingUid());
7621 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007622 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007623 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007624 return null;
7625 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007626 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007627 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007628 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007629 return null;
7630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631
7632 final long identity = Binder.clearCallingIdentity();
7633 try {
7634 return phone.getDeviceId();
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007638 }
7639
Ping Sunc67b7c22016-03-02 19:16:45 +08007640 /**
7641 * {@hide}
7642 * Returns the IMS Registration Status on a particular subid
7643 *
7644 * @param subId
7645 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007646 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007647 Phone phone = getPhone(subId);
7648 if (phone != null) {
7649 return phone.isImsRegistered();
7650 } else {
7651 return false;
7652 }
7653 }
7654
Santos Cordon7a1885b2015-02-03 11:15:19 -08007655 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007656 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007657 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007659 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007660 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7661 }
7662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
7668 }
7669
7670 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007671 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007672 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007673 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007674 mApp,
7675 subscriptionId,
7676 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007677 final long identity = Binder.clearCallingIdentity();
7678 try {
7679 Phone phone = getPhone(subscriptionId);
7680 if (phone == null) {
7681 return null;
7682 }
7683 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
7686 }
7687 }
7688
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007689 /**
7690 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007691 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007692 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 Phone phone = getPhone(subId);
7696 if (phone != null) {
7697 return phone.isWifiCallingEnabled();
7698 } else {
7699 return false;
7700 }
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007703 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007704 }
7705
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007706 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007707 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007708 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007709 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 Phone phone = getPhone(subId);
7713 if (phone != null) {
7714 return phone.isVideoEnabled();
7715 } else {
7716 return false;
7717 }
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007720 }
7721 }
7722
7723 /**
7724 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7725 * defined in {@link ImsRegistrationImplBase}.
7726 */
7727 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 final long identity = Binder.clearCallingIdentity();
7729 try {
7730 Phone phone = getPhone(subId);
7731 if (phone != null) {
7732 return phone.getImsRegistrationTech();
7733 } else {
7734 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7735 }
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007738 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007739 }
7740
Stuart Scott8eef64f2015-04-08 15:13:54 -07007741 @Override
7742 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007743 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007744 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7745 return;
7746 }
Kai Shif70f46f2021-03-03 13:59:46 -08007747 Phone defaultPhone = getDefaultPhone();
7748 if (defaultPhone != null) {
7749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7750 mApp, getDefaultPhone().getSubId(), "factoryReset");
7751 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007752 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007753
Svet Ganovcc087f82015-05-12 20:35:54 -07007754 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007755 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7756 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007757 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007758 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007759 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007760 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007761 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007762 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007763 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007764 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007765 // There has been issues when Sms raw table somehow stores orphan
7766 // fragments. They lead to garbled message when new fragments come
7767 // in and combined with those stale ones. In case this happens again,
7768 // user can reset all network settings which will clean up this table.
7769 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007770 // Clean up IMS settings as well here.
7771 int slotId = getSlotIndex(subId);
7772 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7773 ImsManager.getInstance(mApp, slotId).factoryReset();
7774 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007775
Kai Shif70f46f2021-03-03 13:59:46 -08007776 if (defaultPhone == null) {
7777 return;
7778 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007779 // Erase modem config if erase modem on network setting is enabled.
7780 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7781 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7782 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007783 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007784 }
Kai Shif70f46f2021-03-03 13:59:46 -08007785
7786 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007787 } finally {
7788 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007789 }
7790 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007791
SongFerngWangfd89b102021-05-27 22:44:54 +08007792 @VisibleForTesting
7793 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7794 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7795 return;
7796 }
7797 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7798 RILConstants.PREFERRED_NETWORK_MODE);
7799 SubscriptionManager.setSubscriptionProperty(subId,
7800 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7801 "user=" + defaultNetworkType);
7802 phone.loadAllowedNetworksFromSubscriptionDatabase();
7803 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7804 defaultNetworkType, null);
7805 }
7806
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007807 private void cleanUpSmsRawTable(Context context) {
7808 ContentResolver resolver = context.getContentResolver();
7809 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7810 resolver.delete(uri, null, null);
7811 }
7812
Narayan Kamath1c496c22015-04-16 14:40:19 +01007813 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007814 public String getSimLocaleForSubscriber(int subId) {
7815 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7816 final Phone phone = getPhone(subId);
7817 if (phone == null) {
7818 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007819 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007820 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 final long identity = Binder.clearCallingIdentity();
7822 try {
chen xu5d3637b2019-01-21 23:31:38 -08007823 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007824 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007825 if (info == null) {
7826 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7827 return null;
7828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 // Try and fetch the locale from the carrier properties or from the SIM language
7830 // preferences (EF-PL and EF-LI)...
7831 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007832 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007833 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7834 if (localeFromDefaultSim != null) {
7835 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7836 if (DBG) log("Using locale from subId: " + subId + " locale: "
7837 + localeFromDefaultSim);
7838 return localeFromDefaultSim.toLanguageTag();
7839 } else {
7840 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841 }
7842 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 // The SIM language preferences only store a language (e.g. fr = French), not an
7845 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7846 // the SIM and carrier preferences does not include a country we add the country
7847 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007848 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007850 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 return mccLocale.toLanguageTag();
7852 }
7853
7854 if (DBG) log("No locale found - returning null");
7855 return null;
7856 } finally {
7857 Binder.restoreCallingIdentity(identity);
7858 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007859 }
7860
7861 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007862 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007863 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007864 }
7865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 /**
7867 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7868 */
7869 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007870 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007871 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007872 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007873
Chenjie Yu1ba97252018-01-11 18:16:20 -08007874 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007875 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007876
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007877 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007878 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7879 * representing the state of the modem.
7880 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007881 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7882 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007883 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007884 */
7885 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007886 public void requestModemActivityInfo(ResultReceiver result) {
7887 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889
7890 final long identity = Binder.clearCallingIdentity();
7891 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007892 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007893 } finally {
7894 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007895 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007896 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007897
Siddharth Rayb8114062018-06-17 15:02:38 -07007898 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7899 // less than total activity duration.
7900 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7901 if (info == null) {
7902 return false;
7903 }
7904 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007905 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7906 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7907
Siddharth Rayb8114062018-06-17 15:02:38 -07007908 return (info.isValid()
7909 && (info.getSleepTimeMillis() <= activityDurationMs)
7910 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007911 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007912 && (totalTxTimeMs <= activityDurationMs));
7913 }
7914
Jack Yu85bd38a2015-11-09 11:34:32 -08007915 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007916 * Returns the service state information on specified subscription.
7917 */
7918 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007919 public ServiceState getServiceStateForSubscriber(int subId,
7920 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7921 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007923 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007924 return null;
7925 }
7926
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007927 boolean hasFinePermission = false;
7928 boolean hasCoarsePermission = false;
7929 if (!renounceFineLocationAccess) {
7930 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7931 LocationAccessPolicy.checkLocationPermission(mApp,
7932 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7933 .setCallingPackage(callingPackage)
7934 .setCallingFeatureId(callingFeatureId)
7935 .setCallingPid(Binder.getCallingPid())
7936 .setCallingUid(Binder.getCallingUid())
7937 .setMethod("getServiceStateForSubscriber")
7938 .setLogAsInfo(true)
7939 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7940 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7941 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7942 .build());
7943 hasFinePermission =
7944 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7945 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007946
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007947 if (!renounceCoarseLocationAccess) {
7948 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7949 LocationAccessPolicy.checkLocationPermission(mApp,
7950 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7951 .setCallingPackage(callingPackage)
7952 .setCallingFeatureId(callingFeatureId)
7953 .setCallingPid(Binder.getCallingPid())
7954 .setCallingUid(Binder.getCallingUid())
7955 .setMethod("getServiceStateForSubscriber")
7956 .setLogAsInfo(true)
7957 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7958 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7959 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7960 .build());
7961 hasCoarsePermission =
7962 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7963 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007964
Jack Yu479f40e2020-10-27 21:29:25 -07007965 final Phone phone = getPhone(subId);
7966 if (phone == null) {
7967 return null;
7968 }
7969
Jordan Liu0f2bc442020-11-18 16:47:37 -08007970 final long identity = Binder.clearCallingIdentity();
7971
Jack Yu479f40e2020-10-27 21:29:25 -07007972 boolean isCallingPackageDataService = phone.getDataServicePackages()
7973 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007975 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7976 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7977 Rlog.d(LOG_TAG,
7978 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7979 return null;
7980 }
7981
Hall Liuf19c44f2018-11-27 14:38:17 -08007982 ServiceState ss = phone.getServiceState();
7983
7984 // Scrub out the location info in ServiceState depending on what level of access
7985 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007986 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007987 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7988 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 } finally {
7990 Binder.restoreCallingIdentity(identity);
7991 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007992 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007993
7994 /**
7995 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7996 *
7997 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7998 * voicemail ringtone.
7999 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8000 * PhoneAccount.
8001 */
8002 @Override
8003 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 final long identity = Binder.clearCallingIdentity();
8005 try {
8006 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8007 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008008 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
8014 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008015 }
8016
8017 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008018 * Sets the per-account voicemail ringtone.
8019 *
8020 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8021 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8022 *
8023 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8024 * voicemail ringtone.
8025 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8026 * PhoneAccount.
8027 */
8028 @Override
8029 public void setVoicemailRingtoneUri(String callingPackage,
8030 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008031 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008033 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8034 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8036 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8037 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039
8040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8043 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008044 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 }
8046 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8047 } finally {
8048 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008049 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008050 }
8051
8052 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008053 * Returns whether vibration is set for voicemail notification in Phone settings.
8054 *
8055 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8056 * voicemail vibration setting.
8057 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8058 */
8059 @Override
8060 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 final long identity = Binder.clearCallingIdentity();
8062 try {
8063 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8064 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008065 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8069 } finally {
8070 Binder.restoreCallingIdentity(identity);
8071 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008072 }
8073
Youhan Wange64578a2016-05-02 15:32:42 -07008074 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008075 * Sets the per-account voicemail vibration.
8076 *
8077 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8078 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8079 *
8080 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8081 * voicemail vibration setting.
8082 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8083 * specific PhoneAccount.
8084 */
8085 @Override
8086 public void setVoicemailVibrationEnabled(String callingPackage,
8087 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008088 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008089 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008090 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8091 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8093 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8094 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008095 }
8096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 final long identity = Binder.clearCallingIdentity();
8098 try {
8099 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8100 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008101 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 }
8103 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008106 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008107 }
8108
8109 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008110 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8111 *
8112 * @throws SecurityException if the caller does not have the required permission
8113 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008114 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008115 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008116 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008117 }
8118
8119 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008120 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8121 * permission.
8122 *
8123 * @throws SecurityException if the caller does not have the required permission
8124 */
8125 private void enforceSendSmsPermission() {
8126 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8127 }
8128
8129 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008130 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008131 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008132 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008133 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008134 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 final long identity = Binder.clearCallingIdentity();
8136 try {
8137 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008138 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 if (componentName == null) {
8140 throw new SecurityException(
8141 "Caller not current active visual voicemail package[null]");
8142 }
8143 String vvmPackage = componentName.getPackageName();
8144 if (!callingPackage.equals(vvmPackage)) {
8145 throw new SecurityException("Caller not current active visual voicemail package["
8146 + vvmPackage + "]");
8147 }
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008150 }
8151 }
8152
8153 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008154 * Return the application ID for the app type.
8155 *
8156 * @param subId the subscription ID that this request applies to.
8157 * @param appType the uicc app type.
8158 * @return Application ID for specificied app type, or null if no uicc.
8159 */
8160 @Override
8161 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008162 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008163 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164
8165 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008166 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167 if (phone == null) {
8168 return null;
8169 }
8170 String aid = null;
8171 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008172 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 .getApplicationByType(appType).getAid();
8174 } catch (Exception e) {
8175 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8176 }
8177 return aid;
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008180 }
Youhan Wange64578a2016-05-02 15:32:42 -07008181 }
8182
Youhan Wang4001d252016-05-11 10:29:41 -07008183 /**
8184 * Return the Electronic Serial Number.
8185 *
8186 * @param subId the subscription ID that this request applies to.
8187 * @return ESN or null if error.
8188 */
8189 @Override
8190 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008191 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008192 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193
8194 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008195 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 if (phone == null) {
8197 return null;
8198 }
8199 String esn = null;
8200 try {
8201 esn = phone.getEsn();
8202 } catch (Exception e) {
8203 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8204 }
8205 return esn;
8206 } finally {
8207 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008208 }
Youhan Wang4001d252016-05-11 10:29:41 -07008209 }
8210
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008211 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008212 * Return the Preferred Roaming List Version.
8213 *
8214 * @param subId the subscription ID that this request applies to.
8215 * @return PRLVersion or null if error.
8216 */
8217 @Override
8218 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008219 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008220 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221
8222 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008223 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 if (phone == null) {
8225 return null;
8226 }
8227 String cdmaPrlVersion = null;
8228 try {
8229 cdmaPrlVersion = phone.getCdmaPrlVersion();
8230 } catch (Exception e) {
8231 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8232 }
8233 return cdmaPrlVersion;
8234 } finally {
8235 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008236 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008237 }
8238
8239 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008240 * Get snapshot of Telephony histograms
8241 * @return List of Telephony histograms
8242 * @hide
8243 */
8244 @Override
8245 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8247 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248
8249 final long identity = Binder.clearCallingIdentity();
8250 try {
8251 return RIL.getTelephonyRILTimingHistograms();
8252 } finally {
8253 Binder.restoreCallingIdentity(identity);
8254 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008255 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256
8257 /**
8258 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008259 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8260 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008261 * Require system privileges. In the future we may add this to carrier APIs.
8262 *
Michele Berionne482f8202018-11-27 18:57:59 -08008263 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008264 */
8265 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008266 @TelephonyManager.SetCarrierRestrictionResult
8267 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008268 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008269 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008270
Michele Berionne482f8202018-11-27 18:57:59 -08008271 if (carrierRestrictionRules == null) {
8272 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008273 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 final long identity = Binder.clearCallingIdentity();
8276 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008277 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008278 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008282 }
8283
8284 /**
8285 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008286 * Get the allowed carrier list and the excluded carrier list, including the priority between
8287 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008288 * Require system privileges. In the future we may add this to carrier APIs.
8289 *
Michele Berionne482f8202018-11-27 18:57:59 -08008290 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008291 */
8292 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008293 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008294 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008295 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296
8297 final long identity = Binder.clearCallingIdentity();
8298 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008299 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8300 if (response instanceof CarrierRestrictionRules) {
8301 return (CarrierRestrictionRules) response;
8302 }
8303 // Response is an Exception of some kind,
8304 // which is signalled to the user as a NULL retval
8305 return null;
8306 } catch (Exception e) {
8307 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8308 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 } finally {
8310 Binder.restoreCallingIdentity(identity);
8311 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008312 }
8313
fionaxu59545b42016-05-25 15:53:37 -07008314 /**
fionaxu59545b42016-05-25 15:53:37 -07008315 * Action set from carrier signalling broadcast receivers to enable/disable radio
8316 * @param subId the subscription ID that this action applies to.
8317 * @param enabled control enable or disable radio.
8318 * {@hide}
8319 */
8320 @Override
8321 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8322 enforceModifyPermission();
8323 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324
8325 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008326 if (phone == null) {
8327 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8328 return;
8329 }
8330 try {
8331 phone.carrierActionSetRadioEnabled(enabled);
8332 } catch (Exception e) {
8333 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 } finally {
8335 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008336 }
8337 }
8338
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008339 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008340 * Enable or disable Voice over NR (VoNR)
8341 * @param subId the subscription ID that this action applies to.
8342 * @param enabled enable or disable VoNR.
8343 * @return operation result.
8344 */
8345 @Override
8346 public int setVoNrEnabled(int subId, boolean enabled) {
8347 enforceModifyPermission();
8348 final Phone phone = getPhone(subId);
8349
8350 final long identity = Binder.clearCallingIdentity();
8351 if (phone == null) {
8352 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8353 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8354 }
8355
8356 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8357 try {
8358 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8359 workSource);
8360 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008361
8362 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8363 if (DBG) {
8364 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8365 }
8366 SubscriptionManager.setSubscriptionProperty(
8367 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8368 (enabled ? "1" : "0"));
8369 }
8370
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008371 return result;
8372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
8375 }
8376
8377 /**
8378 * Is voice over NR enabled
8379 * @return true if VoNR is enabled else false
8380 */
8381 @Override
8382 public boolean isVoNrEnabled(int subId) {
8383 enforceReadPrivilegedPermission("isVoNrEnabled");
8384 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8385 final long identity = Binder.clearCallingIdentity();
8386 try {
8387 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8388 null, subId, workSource);
8389 if (DBG) log("isVoNrEnabled: " + isEnabled);
8390 return isEnabled;
8391 } finally {
8392 Binder.restoreCallingIdentity(identity);
8393 }
8394 }
8395
8396 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008397 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8398 * network status based on which carrier apps could apply actions accordingly,
8399 * enable/disable default url handler for example.
8400 *
8401 * @param subId the subscription ID that this action applies to.
8402 * @param report control start/stop reporting the default network status.
8403 * {@hide}
8404 */
8405 @Override
8406 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8407 enforceModifyPermission();
8408 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409
8410 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008411 if (phone == null) {
8412 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8413 return;
8414 }
8415 try {
8416 phone.carrierActionReportDefaultNetworkStatus(report);
8417 } catch (Exception e) {
8418 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008419 } finally {
8420 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008421 }
8422 }
8423
8424 /**
fionaxud9622282017-07-17 17:51:30 -07008425 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8426 * @param subId the subscription ID that this action applies to.
8427 * {@hide}
8428 */
8429 @Override
8430 public void carrierActionResetAll(int subId) {
8431 enforceModifyPermission();
8432 final Phone phone = getPhone(subId);
8433 if (phone == null) {
8434 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8435 return;
8436 }
8437 try {
8438 phone.carrierActionResetAll();
8439 } catch (Exception e) {
8440 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8441 }
8442 }
8443
8444 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008445 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8446 * bug report is being generated.
8447 */
8448 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008449 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008450 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8451 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008452 writer.println("Permission Denial: can't dump Phone from pid="
8453 + Binder.getCallingPid()
8454 + ", uid=" + Binder.getCallingUid()
8455 + "without permission "
8456 + android.Manifest.permission.DUMP);
8457 return;
8458 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008459 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008460 }
Jack Yueb89b242016-06-22 13:27:47 -07008461
Brad Ebingerdac2f002018-04-03 15:17:52 -07008462 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008463 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8464 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8465 @NonNull String[] args) {
8466 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8467 this, in.getFileDescriptor(), out.getFileDescriptor(),
8468 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008469 }
8470
Jack Yueb89b242016-06-22 13:27:47 -07008471 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008472 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008473 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008474 * @param reason the reason the data enable change is taking place
8475 * @param enabled True if enabling the data, otherwise disabling.
8476 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008477 */
8478 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008479 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008480 boolean enabled) {
8481 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8482 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8483 try {
8484 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008485 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008486 } catch (SecurityException se) {
8487 enforceModifyPermission();
8488 }
8489 } else {
8490 enforceModifyPermission();
8491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008492
8493 final long identity = Binder.clearCallingIdentity();
8494 try {
8495 Phone phone = getPhone(subId);
8496 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008497 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8498 phone.carrierActionSetMeteredApnsEnabled(enabled);
8499 } else {
8500 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008502 }
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008505 }
8506 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008507
8508 /**
8509 * Get Client request stats
8510 * @return List of Client Request Stats
8511 * @hide
8512 */
8513 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008514 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8515 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008517 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008518 return null;
8519 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008520 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 if (phone != null) {
8525 return phone.getClientRequestStats();
8526 }
8527
8528 return null;
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
8531 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008532 }
8533
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008534 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008535 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008536 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008537 }
Jack Yueb4124c2017-02-16 15:32:43 -08008538
8539 /**
Grace Chen70990072017-03-24 17:21:30 -07008540 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008541 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008542 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008543 * @param state State of SIM (power down, power up, pass through)
8544 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8545 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8546 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008547 *
8548 **/
8549 @Override
Grace Chen70990072017-03-24 17:21:30 -07008550 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008551 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008552 Phone phone = PhoneFactory.getPhone(slotIndex);
8553
vagdeviaf9a5b92018-08-15 16:01:53 -07008554 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008559 phone.setSimPowerState(state, null, workSource);
8560 }
8561 } finally {
8562 Binder.restoreCallingIdentity(identity);
8563 }
8564 }
8565
8566 /**
8567 * Set SIM card power state.
8568 *
8569 * @param slotIndex SIM slot id.
8570 * @param state State of SIM (power down, power up, pass through)
8571 * @param callback callback to trigger after success or failure
8572 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8573 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8574 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8575 *
8576 **/
8577 @Override
8578 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8579 IIntegerConsumer callback) {
8580 enforceModifyPermission();
8581 Phone phone = PhoneFactory.getPhone(slotIndex);
8582
8583 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8584
8585 final long identity = Binder.clearCallingIdentity();
8586 try {
8587 if (phone != null) {
8588 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8589 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590 }
8591 } finally {
8592 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008593 }
8594 }
Shuo Qiandd210312017-04-12 22:11:33 +00008595
Tyler Gunn65d45c22017-06-05 11:22:26 -07008596 private boolean isUssdApiAllowed(int subId) {
8597 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008598 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008599 if (configManager == null) {
8600 return false;
8601 }
8602 PersistableBundle pb = configManager.getConfigForSubId(subId);
8603 if (pb == null) {
8604 return false;
8605 }
8606 return pb.getBoolean(
8607 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8608 }
8609
Shuo Qiandd210312017-04-12 22:11:33 +00008610 /**
8611 * Check if phone is in emergency callback mode
8612 * @return true if phone is in emergency callback mode
8613 * @param subId sub id
8614 */
goneil9c5f4872017-12-05 14:07:56 -08008615 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008616 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008617 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008618 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619
8620 final long identity = Binder.clearCallingIdentity();
8621 try {
8622 if (phone != null) {
8623 return phone.isInEcm();
8624 } else {
8625 return false;
8626 }
8627 } finally {
8628 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008629 }
8630 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008631
8632 /**
8633 * Get the current signal strength information for the given subscription.
8634 * Because this information is not updated when the device is in a low power state
8635 * it should not be relied-upon to be current.
8636 * @param subId Subscription index
8637 * @return the most recent cached signal strength info from the modem
8638 */
8639 @Override
8640 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008641 final long identity = Binder.clearCallingIdentity();
8642 try {
8643 Phone p = getPhone(subId);
8644 if (p == null) {
8645 return null;
8646 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008648 return p.getSignalStrength();
8649 } finally {
8650 Binder.restoreCallingIdentity(identity);
8651 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008652 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008653
Pengquan Meng77b7f132018-08-22 14:49:57 -07008654 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008655 * Get the current modem radio state for the given slot.
8656 * @param slotIndex slot index.
8657 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008658 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008659 * @return the current radio power state from the modem
8660 */
8661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008662 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008663 Phone phone = PhoneFactory.getPhone(slotIndex);
8664 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8666 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008667 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8668 }
8669
8670 final long identity = Binder.clearCallingIdentity();
8671 try {
8672 return phone.getRadioPowerState();
8673 } finally {
8674 Binder.restoreCallingIdentity(identity);
8675 }
8676 }
8677 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8678 }
8679
8680 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008681 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8682 *
8683 * <p>Requires one of the following permissions:
8684 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008685 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008686 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8687 * privileges.
8688 *
8689 * @param subId subscription id
8690 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8691 * {@code false}.
8692 */
8693 @Override
8694 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008695 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008696 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008697 try {
8698 mApp.enforceCallingOrSelfPermission(
8699 android.Manifest.permission.ACCESS_NETWORK_STATE,
8700 functionName);
8701 } catch (Exception e) {
8702 mApp.enforceCallingOrSelfPermission(
8703 permission.READ_BASIC_PHONE_STATE, functionName);
8704 }
Shuo Qian093013d2020-08-13 15:42:55 -07008705 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008706 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008707 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008708 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008709
Pengquan Menga1bb6272018-09-06 09:59:22 -07008710 boolean isEnabled = false;
8711 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008712 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008713 Phone phone = getPhone(subId);
8714 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008715 } finally {
8716 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008717 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008718 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008719 }
8720
8721
8722 /**
8723 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8724 *
8725 * <p> Requires permission:
8726 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8727 * privileges.
8728 *
8729 * @param subId subscription id
8730 * @param isEnabled {@code true} means enable, {@code false} means disable.
8731 */
8732 @Override
8733 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8735 mApp, subId, "setDataRoamingEnabled");
8736
Pengquan Menga1bb6272018-09-06 09:59:22 -07008737 final long identity = Binder.clearCallingIdentity();
8738 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008739 Phone phone = getPhone(subId);
8740 if (phone != null) {
8741 phone.setDataRoamingEnabled(isEnabled);
8742 }
8743 } finally {
8744 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008745 }
8746 }
8747
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008748 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008749 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008750 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008751 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008752 mApp, subId, "isManualNetworkSelectionAllowed");
8753
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008754 boolean isAllowed = true;
8755 final long identity = Binder.clearCallingIdentity();
8756 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008757 Phone phone = getPhone(subId);
8758 if (phone != null) {
8759 isAllowed = phone.isCspPlmnEnabled();
8760 }
8761 } finally {
8762 Binder.restoreCallingIdentity(identity);
8763 }
8764 return isAllowed;
8765 }
8766
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008767 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8768 UiccProfile profile = port.getUiccProfile();
8769 if (profile == null ||
8770 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8771 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8772 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008773 }
8774 return true;
8775 }
8776
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008777 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008778 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008779 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008780 mApp.getSystemService(AppOpsManager.class)
8781 .checkPackage(Binder.getCallingUid(), callingPackage);
8782
Jordan Liu1e142fc2019-04-22 15:10:43 -07008783 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008784 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008785 try {
8786 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008787 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008788 } catch (SecurityException e) {
8789 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8790 // has carrier privileges on an active UICC
8791 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8792 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008793 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008794 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008795 }
sandeepjsb6c87872021-09-27 15:34:44 +00008796 // checking compatibility, if calling app's target SDK is T and beyond.
8797 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8798 Binder.getCallingUid())) {
8799 isIccIdAccessRestricted = true;
8800 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008801 final long identity = Binder.clearCallingIdentity();
8802 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008803 UiccController uiccController = UiccController.getInstance();
8804 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008805 if (hasReadPermission) {
8806 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008807 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008808
8809 // Remove private info if the caller doesn't have access
8810 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8811 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008812 //setting the value after compatibility check
8813 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008814 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8815 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008816 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008817 if (card == null) {
8818 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008819 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008820 continue;
8821 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008822 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8823 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008824 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008825 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008826 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008827 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8828 for (UiccPortInfo portInfo : portInfos) {
8829 UiccPort port = uiccController.getUiccPortForSlot(
8830 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8831 if (port == null) {
8832 // assume no access if port is null
8833 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8834 continue;
8835 }
8836 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8837 uiccPortInfos.add(portInfo);
8838 } else {
8839 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8840 }
8841 }
8842 filteredInfos.add(new UiccCardInfo(
8843 cardInfo.isEuicc(),
8844 cardInfo.getCardId(),
8845 null,
8846 cardInfo.getPhysicalSlotIndex(),
8847 cardInfo.isRemovable(),
8848 cardInfo.isMultipleEnabledProfilesSupported(),
8849 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008850 }
8851 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008852 } finally {
8853 Binder.restoreCallingIdentity(identity);
8854 }
8855 }
8856
sandeepjsb6c87872021-09-27 15:34:44 +00008857 /**
8858 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8859 * generally private and require carrier privileges to view.
8860 *
8861 * @hide
8862 */
8863 @NonNull
8864 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8865 List<UiccPortInfo> portinfo = new ArrayList<>();
8866 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8867 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8868 }
8869 return new UiccCardInfo(
8870 cardInfo.isEuicc(),
8871 cardInfo.getCardId(),
8872 null,
8873 cardInfo.getPhysicalSlotIndex(),
8874 cardInfo.isRemovable(),
8875 cardInfo.isMultipleEnabledProfilesSupported(),
8876 portinfo
8877 );
8878 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008879
sandeepjsb6c87872021-09-27 15:34:44 +00008880 /**
8881 * @hide
8882 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8883 * These values are generally private and require carrier privileges to view.
8884 */
8885 @NonNull
8886 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8887 return new UiccPortInfo(
8888 UiccPortInfo.ICCID_REDACTED,
8889 portInfo.getPortIndex(),
8890 portInfo.getLogicalSlotIndex(),
8891 portInfo.isActive()
8892 );
8893 }
8894 @Override
8895 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008896 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008897 mApp.getSystemService(AppOpsManager.class)
8898 .checkPackage(Binder.getCallingUid(), callingPackage);
8899
8900 boolean hasReadPermission = false;
8901 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008902
8903 try {
8904 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8905 hasReadPermission = true;
8906 } catch (SecurityException e) {
8907 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8908 // has carrier privileges on an active UICC
8909 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8910 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8911 hasReadPermission = true;
8912 }
8913 }
8914
8915 // checking compatibility, if calling app's target SDK is T and beyond.
8916 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8917 Binder.getCallingUid())) {
8918 isLogicalSlotAccessRestricted = true;
8919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 final long identity = Binder.clearCallingIdentity();
8921 try {
8922 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8923 if (slots == null) {
8924 Rlog.i(LOG_TAG, "slots is null.");
8925 return null;
8926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8928 for (int i = 0; i < slots.length; i++) {
8929 UiccSlot slot = slots[i];
8930 if (slot == null) {
8931 continue;
8932 }
8933
Jordan Liu7be7e652019-05-06 18:55:02 +00008934 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 UiccCard card = slot.getUiccCard();
8936 if (card != null) {
8937 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008938 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008939 cardId = slot.getEid();
8940 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008941 // If cardId is null, use iccId of default port as cardId. Check if has
8942 // read permission otherwise set to null.(card is null which means no
8943 // carrier permission)
8944 cardId = hasReadPermission ? slot.getIccId(
8945 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 }
8948
Jordan Liu857451f2019-05-09 16:35:35 -07008949 if (cardId != null) {
8950 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8951 // if cardId is an EID, it's all digits so this is fine
8952 cardId = IccUtils.stripTrailingFs(cardId);
8953 }
8954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008955 int cardState = 0;
8956 switch (slot.getCardState()) {
8957 case CARDSTATE_ABSENT:
8958 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8959 break;
8960 case CARDSTATE_PRESENT:
8961 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8962 break;
8963 case CARDSTATE_ERROR:
8964 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8965 break;
8966 case CARDSTATE_RESTRICTED:
8967 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8968 break;
8969 default:
8970 break;
8971
8972 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008973 List<UiccPortInfo> portInfos = new ArrayList<>();
8974 int[] portIndexes = slot.getPortList();
8975 for (int portIdx : portIndexes) {
8976 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8977 callingPackage, hasReadPermission));
8978 if (slot.isPortActive(portIdx)) {
8979 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8980 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8981 port.getPhoneId(), true));
8982 } else {
8983 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8984 }
8985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987 slot.isEuicc(),
8988 cardId,
8989 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008990 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008991 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008992 //setting the value after compatibility check
8993 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008994 }
8995 return infos;
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008998 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008999 }
9000
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009001 /* Returns null if doesn't have read permission or carrier privilege access. */
9002 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9003 boolean hasReadPermission) {
9004 String iccId = slot.getIccId(portIndex);
9005 if (hasReadPermission) { // if has read permission
9006 return iccId;
9007 } else {
9008 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9009 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9010 // if no read permission, checking carrier privilege access
9011 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9012 return iccId;
9013 }
9014 }
9015 }
9016 // No read permission or carrier privilege access.
9017 return UiccPortInfo.ICCID_REDACTED;
9018 }
9019
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009020 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009021 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009022 public boolean switchSlots(int[] physicalSlots) {
9023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009027 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9028 for (int i = 0; i < physicalSlots.length; i++) {
9029 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9030 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9031 physicalSlots[i], i));
9032 }
9033 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009037 }
Jack Yu4c988042018-02-27 15:30:01 -08009038
9039 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009040 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9041 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9042 enforceModifyPermission();
9043
9044 final long identity = Binder.clearCallingIdentity();
9045 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009046 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009047 } finally {
9048 Binder.restoreCallingIdentity(identity);
9049 }
9050 }
9051
9052 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009053 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009054 final long identity = Binder.clearCallingIdentity();
9055 try {
9056 return UiccController.getInstance().getCardIdForDefaultEuicc();
9057 } finally {
9058 Binder.restoreCallingIdentity(identity);
9059 }
9060 }
9061
Pengquan Meng85728fb2018-03-12 16:31:21 -07009062 /**
goneil47ffb6e2018-04-06 15:40:58 -07009063 * A test API to reload the UICC profile.
9064 *
9065 * <p>Requires that the calling app has permission
9066 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9067 * @hide
9068 */
9069 @Override
9070 public void refreshUiccProfile(int subId) {
9071 enforceModifyPermission();
9072
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
9075 Phone phone = getPhone(subId);
9076 if (phone == null) {
9077 return;
9078 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009079 UiccPort uiccPort = phone.getUiccPort();
9080 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009081 return;
9082 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009083 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009084 if (uiccProfile == null) {
9085 return;
9086 }
9087 uiccProfile.refresh();
9088 } finally {
9089 Binder.restoreCallingIdentity(identity);
9090 }
9091 }
9092
9093 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009094 * Returns false if the mobile data is disabled by default, otherwise return true.
9095 */
9096 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009097 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009098 }
9099
9100 /**
9101 * Returns true if the data roaming is enabled by default, i.e the system property
9102 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9103 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9104 */
9105 private boolean getDefaultDataRoamingEnabled(int subId) {
9106 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009107 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009108 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009109 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9110 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9111 return isDataRoamingEnabled;
9112 }
9113
9114 /**
9115 * Returns the default network type for the given {@code subId}, if the default network type is
9116 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9117 */
9118 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009119 List<Integer> list = TelephonyProperties.default_network();
9120 int phoneId = mSubscriptionController.getPhoneId(subId);
9121 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9122 return list.get(phoneId);
9123 }
9124 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009125 }
fionaxua13278b2018-03-21 00:08:13 -07009126
9127 @Override
9128 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009129 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009130 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131
9132 final long identity = Binder.clearCallingIdentity();
9133 try {
9134 final Phone phone = getPhone(subId);
9135 if (phone == null) {
9136 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9137 return;
9138 }
chen xueaba88a2019-03-15 13:15:10 -07009139 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9140 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009141 if (carrierPrivilegeRules == null) {
9142 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9143 } else {
9144 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009146 } finally {
9147 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009148 }
fionaxua13278b2018-03-21 00:08:13 -07009149 }
9150
9151 @Override
9152 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009153 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009154
9155 final long identity = Binder.clearCallingIdentity();
9156 try {
9157 final Phone phone = getPhone(subId);
9158 if (phone == null) {
9159 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9160 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9161 }
9162 return phone.getCarrierIdListVersion();
9163 } finally {
9164 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009165 }
fionaxua13278b2018-03-21 00:08:13 -07009166 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009167
9168 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009169 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9170 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009172 mApp, subId, callingPackage, callingFeatureId,
9173 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009174 return -1;
9175 }
9176
9177 final long identity = Binder.clearCallingIdentity();
9178 try {
9179 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9180 } finally {
9181 Binder.restoreCallingIdentity(identity);
9182 }
9183 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009184
9185 @Override
9186 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009187 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009188 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009189 mApp, subId, "getCdmaRoamingMode");
9190
9191 final long identity = Binder.clearCallingIdentity();
9192 try {
9193 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
9198
9199 @Override
9200 public boolean setCdmaRoamingMode(int subId, int mode) {
9201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9202 mApp, subId, "setCdmaRoamingMode");
9203
9204 final long identity = Binder.clearCallingIdentity();
9205 try {
9206 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9207 } finally {
9208 Binder.restoreCallingIdentity(identity);
9209 }
9210 }
9211
9212 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009213 public int getCdmaSubscriptionMode(int subId) {
9214 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009215 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009216 mApp, subId, "getCdmaSubscriptionMode");
9217
9218 final long identity = Binder.clearCallingIdentity();
9219 try {
9220 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
9225
9226 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009227 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9229 mApp, subId, "setCdmaSubscriptionMode");
9230
9231 final long identity = Binder.clearCallingIdentity();
9232 try {
9233 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9234 } finally {
9235 Binder.restoreCallingIdentity(identity);
9236 }
9237 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009238
sqianc5eccab2018-10-19 18:46:41 -07009239 @Override
sqian8c685422019-02-22 15:55:18 -08009240 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009241 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009243 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9244 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009245 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9246 }
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
sqian854d44b2018-12-12 16:48:18 -08009249 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9250 for (Phone phone: PhoneFactory.getPhones()) {
9251 if (phone.getEmergencyNumberTracker() != null
9252 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9253 emergencyNumberListInternal.put(
9254 phone.getSubId(),
9255 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9256 }
sqian11b7a0e2018-12-05 18:48:28 -08009257 }
sqian854d44b2018-12-12 16:48:18 -08009258 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009259 } finally {
9260 Binder.restoreCallingIdentity(identity);
9261 }
sqianc5eccab2018-10-19 18:46:41 -07009262 }
9263
9264 @Override
sqian8c685422019-02-22 15:55:18 -08009265 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009266 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009267 if (!exactMatch) {
9268 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009269 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009270 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009271 }
9272 final long identity = Binder.clearCallingIdentity();
9273 try {
sqian854d44b2018-12-12 16:48:18 -08009274 for (Phone phone: PhoneFactory.getPhones()) {
9275 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009276 && phone.getEmergencyNumberTracker()
9277 .isEmergencyNumber(number, exactMatch)) {
9278 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009279 }
sqian11b7a0e2018-12-05 18:48:28 -08009280 }
9281 return false;
9282 } finally {
9283 Binder.restoreCallingIdentity(identity);
9284 }
9285 }
9286
sqianf4ca7ed2019-01-15 18:32:07 -08009287 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009288 * Start emergency callback mode for GsmCdmaPhone for testing.
9289 */
9290 @Override
9291 public void startEmergencyCallbackMode() {
9292 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9293 "startEmergencyCallbackMode");
9294 enforceModifyPermission();
9295 final long identity = Binder.clearCallingIdentity();
9296 try {
9297 for (Phone phone : PhoneFactory.getPhones()) {
9298 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9299 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9300 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9301 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9302 gsmCdmaPhone.obtainMessage(
9303 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9304 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9305 }
9306 }
9307 } finally {
9308 Binder.restoreCallingIdentity(identity);
9309 }
9310 }
9311
9312 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009313 * Update emergency number list for test mode.
9314 */
9315 @Override
9316 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9317 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9318 "updateEmergencyNumberListTestMode");
9319
9320 final long identity = Binder.clearCallingIdentity();
9321 try {
9322 for (Phone phone: PhoneFactory.getPhones()) {
9323 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9324 if (tracker != null) {
9325 tracker.executeEmergencyNumberTestModeCommand(action, num);
9326 }
9327 }
9328 } finally {
9329 Binder.restoreCallingIdentity(identity);
9330 }
9331 }
9332
9333 /**
9334 * Get the full emergency number list for test mode.
9335 */
9336 @Override
9337 public List<String> getEmergencyNumberListTestMode() {
9338 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9339 "getEmergencyNumberListTestMode");
9340
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 Set<String> emergencyNumbers = new HashSet<>();
9344 for (Phone phone: PhoneFactory.getPhones()) {
9345 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9346 if (tracker != null) {
9347 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9348 emergencyNumbers.add(num.getNumber());
9349 }
9350 }
9351 }
9352 return new ArrayList<>(emergencyNumbers);
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
9357
chen xud6b45bd2018-10-30 22:27:10 -07009358 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009359 public int getEmergencyNumberDbVersion(int subId) {
9360 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9361
9362 final long identity = Binder.clearCallingIdentity();
9363 try {
9364 final Phone phone = getPhone(subId);
9365 if (phone == null) {
9366 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9367 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9368 }
9369 return phone.getEmergencyNumberDbVersion();
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 }
9374
9375 @Override
9376 public void notifyOtaEmergencyNumberDbInstalled() {
9377 enforceModifyPermission();
9378
9379 final long identity = Binder.clearCallingIdentity();
9380 try {
9381 for (Phone phone: PhoneFactory.getPhones()) {
9382 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9383 if (tracker != null) {
9384 tracker.updateOtaEmergencyNumberDatabase();
9385 }
9386 }
9387 } finally {
9388 Binder.restoreCallingIdentity(identity);
9389 }
9390 }
9391
9392 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009393 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009394 enforceActiveEmergencySessionPermission();
9395
9396 final long identity = Binder.clearCallingIdentity();
9397 try {
9398 for (Phone phone: PhoneFactory.getPhones()) {
9399 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9400 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009401 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9402 }
9403 }
9404 } finally {
9405 Binder.restoreCallingIdentity(identity);
9406 }
9407 }
9408
9409 @Override
9410 public void resetOtaEmergencyNumberDbFilePath() {
9411 enforceActiveEmergencySessionPermission();
9412
9413 final long identity = Binder.clearCallingIdentity();
9414 try {
9415 for (Phone phone: PhoneFactory.getPhones()) {
9416 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9417 if (tracker != null) {
9418 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009419 }
9420 }
9421 } finally {
9422 Binder.restoreCallingIdentity(identity);
9423 }
9424 }
9425
9426 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009427 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9428 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9429 Phone phone = getPhone(subId);
9430 if (phone == null) {
9431 return null;
9432 }
9433 final long identity = Binder.clearCallingIdentity();
9434 try {
9435 UiccProfile profile = UiccController.getInstance()
9436 .getUiccProfileForPhone(phone.getPhoneId());
9437 if (profile != null) {
9438 return profile.getCertsFromCarrierPrivilegeAccessRules();
9439 }
9440 } finally {
9441 Binder.restoreCallingIdentity(identity);
9442 }
9443 return null;
9444 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009445
9446 /**
9447 * Enable or disable a modem stack.
9448 */
9449 @Override
9450 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9451 enforceModifyPermission();
9452
9453 final long identity = Binder.clearCallingIdentity();
9454 try {
9455 Phone phone = PhoneFactory.getPhone(slotIndex);
9456 if (phone == null) {
9457 return false;
9458 } else {
9459 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9460 }
9461 } finally {
9462 Binder.restoreCallingIdentity(identity);
9463 }
9464 }
Michelecea4cf22018-12-21 15:00:11 -08009465
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009466 /**
9467 * Whether a modem stack is enabled or not.
9468 */
9469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009470 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9471 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009472 Phone phone = PhoneFactory.getPhone(slotIndex);
9473 if (phone == null) return false;
9474
9475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009476 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9477 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009478 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9479 }
9480
9481 final long identity = Binder.clearCallingIdentity();
9482 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009483 try {
9484 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9485 } catch (NoSuchElementException ex) {
9486 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9487 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009488 } finally {
9489 Binder.restoreCallingIdentity(identity);
9490 }
9491 }
9492
Michelecea4cf22018-12-21 15:00:11 -08009493 @Override
Michele0ea7d782019-03-19 14:58:42 -07009494 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009495 enforceModifyPermission();
9496
9497 final long identity = Binder.clearCallingIdentity();
9498 try {
9499 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009500 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009501 .commit();
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
9505 }
9506
9507 @Override
Michele0ea7d782019-03-19 14:58:42 -07009508 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009509 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009511 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9512 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009513 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009514 }
Michelecea4cf22018-12-21 15:00:11 -08009515
9516 final long identity = Binder.clearCallingIdentity();
9517 try {
Michele0ea7d782019-03-19 14:58:42 -07009518 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009519 } finally {
9520 Binder.restoreCallingIdentity(identity);
9521 }
9522 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009523
Michele0ea7d782019-03-19 14:58:42 -07009524 @TelephonyManager.IsMultiSimSupportedResult
9525 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009526 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9527 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9528 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009529 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9530 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009531 }
9532 // Check if the hardware supports multisim functionality. If usage of multisim is not
9533 // supported by the modem, indicate that it is restricted.
9534 PhoneCapability staticCapability =
9535 mPhoneConfigurationManager.getStaticPhoneCapability();
9536 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009537 loge("isMultiSimSupportedInternal: no static configuration available");
9538 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009539 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009540 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009541 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9542 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009543 }
9544 // Check if support of multiple SIMs is restricted by carrier
9545 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009546 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009547 }
9548
Michele0ea7d782019-03-19 14:58:42 -07009549 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009550 }
9551
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009552 /**
9553 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009554 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9555 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9556 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009557 * @param numOfSims number of active sims we want to switch to
9558 */
9559 @Override
9560 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009561 if (numOfSims == 1) {
9562 enforceModifyPermission();
9563 } else {
9564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9565 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9566 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009567 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009568
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009569 try {
Michele30b57b22019-03-01 12:01:14 -08009570 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009571 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009572 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9573 return;
9574 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009575 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9576 } finally {
9577 Binder.restoreCallingIdentity(identity);
9578 }
9579 }
9580
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009581 @Override
9582 public boolean isApplicationOnUicc(int subId, int appType) {
9583 enforceReadPrivilegedPermission("isApplicationOnUicc");
9584 Phone phone = getPhone(subId);
9585 if (phone == null) {
9586 return false;
9587 }
9588 final long identity = Binder.clearCallingIdentity();
9589 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009590 UiccPort uiccPort = phone.getUiccPort();
9591 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009592 return false;
9593 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009594 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009595 if (uiccProfile == null) {
9596 return false;
9597 }
9598 if (TelephonyManager.APPTYPE_SIM <= appType
9599 && appType <= TelephonyManager.APPTYPE_ISIM) {
9600 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9601 }
9602 return false;
9603 } finally {
9604 Binder.restoreCallingIdentity(identity);
9605 }
9606 }
9607
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009608 /**
chen xub4baa772019-04-03 10:23:41 -07009609 * Get whether making changes to modem configurations will trigger reboot.
9610 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009611 */
9612 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009613 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9614 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009616 mApp, subId, callingPackage, callingFeatureId,
9617 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009618 return false;
9619 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009620 final long identity = Binder.clearCallingIdentity();
9621 try {
9622 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
9627
Nathan Harold29f5f052019-02-15 13:41:57 -08009628 private void updateModemStateMetrics() {
9629 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9630 // TODO: check the state for each modem if the api is ready.
9631 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9632 }
9633
Pengquan Meng3889a572019-01-23 11:16:29 -08009634 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009635 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009636 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009637 // Verify that the callingPackage belongs to the calling UID
9638 mApp.getSystemService(AppOpsManager.class)
9639 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009640 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009641 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009642 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009643 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9644 if (slotInfos != null) {
9645 for (int i = 0; i < slotInfos.length; i++) {
9646 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9647 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9648 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9649 portInfo.getLogicalSlotIndex()));
9650 }
9651 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009652 }
9653 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009654 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009655 } finally {
9656 Binder.restoreCallingIdentity(identity);
9657 }
9658 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009659
9660 /**
9661 * Get the IRadio HAL Version
9662 */
9663 @Override
9664 public int getRadioHalVersion() {
9665 Phone phone = getDefaultPhone();
9666 if (phone == null) return -1;
9667 HalVersion hv = phone.getHalVersion();
9668 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9669 return hv.major * 100 + hv.minor;
9670 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009671
9672 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009673 * Get the current calling package name.
9674 * @return the current calling package name
9675 */
9676 @Override
9677 public String getCurrentPackageName() {
9678 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9679 }
9680
9681 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009682 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9683 * corresponding network requests on a subId.
9684 *
9685 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009686 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009687 * 2) APN is un-metered for this subscription, or
9688 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009689 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009690 *
9691 * @return whether data is allowed for a apn type.
9692 *
9693 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009694 */
9695 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009696 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009697 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9698 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009699
9700 // Now that all security checks passes, perform the operation as ourselves.
9701 final long identity = Binder.clearCallingIdentity();
9702 try {
9703 Phone phone = getPhone(subId);
9704 if (phone == null) return false;
9705
Jack Yu41407ee2019-05-13 16:54:09 -07009706 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009707 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
9712
9713 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009714 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009715 enforceReadPrivilegedPermission("isApnMetered");
9716
9717 // Now that all security checks passes, perform the operation as ourselves.
9718 final long identity = Binder.clearCallingIdentity();
9719 try {
9720 Phone phone = getPhone(subId);
9721 if (phone == null) return true; // By default return true.
9722
Jack Yu41407ee2019-05-13 16:54:09 -07009723 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009728
9729 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009730 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9731 int subscriptionId, IBooleanConsumer resultCallback) {
9732 enforceModifyPermission();
9733 long token = Binder.clearCallingIdentity();
9734 try {
9735 Phone phone = getPhone(subscriptionId);
9736 if (phone == null) {
9737 try {
9738 if (resultCallback != null) {
9739 resultCallback.accept(false);
9740 }
9741 } catch (RemoteException e) {
9742 // ignore
9743 }
9744 return;
9745 }
9746 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9747 Pair.create(specifiers, (x) -> {
9748 try {
9749 if (resultCallback != null) {
9750 resultCallback.accept(x);
9751 }
9752 } catch (RemoteException e) {
9753 // ignore
9754 }
9755 });
9756 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9757 } finally {
9758 Binder.restoreCallingIdentity(token);
9759 }
9760 }
9761
9762 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009763 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9764 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009765 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009766 mApp, subId, "getSystemSelectionChannels");
9767 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9768 final long identity = Binder.clearCallingIdentity();
9769 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009770 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9771 if (result instanceof IllegalStateException) {
9772 throw (IllegalStateException) result;
9773 }
9774 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009775 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9776 return specifiers;
9777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 }
9781
9782 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009783 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009784 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009785 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9786 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9787 if (iccRecords == null) {
9788 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9789 return false;
9790 }
9791 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9792 }
9793
9794 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009795 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9796 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009797 if (callingPackage == null) {
9798 callingPackage = getCurrentPackageName();
9799 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009800 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9801 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009802 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9803 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009804 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9805 }
9806 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9807 Intent intent = new Intent();
9808 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9809 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9810 // Bring up choose default SMS subscription dialog right now
9811 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9812 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9813 mApp.startActivity(intent);
9814 }
chen xud5ca2d52019-05-28 15:20:57 -07009815
9816 @Override
9817 public String getMmsUAProfUrl(int subId) {
9818 //TODO investigate if this API should require proper permission check in R b/133791609
9819 final long identity = Binder.clearCallingIdentity();
9820 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009821 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9822 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9823 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9824 return carrierUAProfUrl;
9825 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009826 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9827 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
9833 @Override
9834 public String getMmsUserAgent(int subId) {
9835 //TODO investigate if this API should require proper permission check in R b/133791609
9836 final long identity = Binder.clearCallingIdentity();
9837 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009838 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9839 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9840 if (!TextUtils.isEmpty(carrierUserAgent)) {
9841 return carrierUserAgent;
9842 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009843 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9844 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
Jack Yub07d4972019-05-28 16:12:25 -07009849
9850 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009851 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9852 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009853
Jack Yub07d4972019-05-28 16:12:25 -07009854 final long identity = Binder.clearCallingIdentity();
9855 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009856 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009857 if (phone == null) return false;
9858
Hall Liua62f5da2020-09-25 10:42:19 -07009859 switch (policy) {
9860 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9861 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9862 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9863 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9864 default:
9865 throw new IllegalArgumentException(policy + " is not a valid policy");
9866 }
Jack Yub07d4972019-05-28 16:12:25 -07009867 } finally {
9868 Binder.restoreCallingIdentity(identity);
9869 }
9870 }
9871
9872 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009873 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009874 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009875 enforceModifyPermission();
9876
changbettyd5c246e2019-12-24 15:40:37 +08009877 final long identity = Binder.clearCallingIdentity();
9878 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009879 Phone phone = getPhone(subscriptionId);
9880 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009881
Hall Liua62f5da2020-09-25 10:42:19 -07009882 switch (policy) {
9883 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9884 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9885 break;
9886 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9887 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9888 break;
9889 default:
9890 throw new IllegalArgumentException(policy + " is not a valid policy");
9891 }
changbettyd5c246e2019-12-24 15:40:37 +08009892 } finally {
9893 Binder.restoreCallingIdentity(identity);
9894 }
9895 }
9896
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009897 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009898 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009899 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9900 * otherwise.
9901 */
9902 @Override
9903 public void setCepEnabled(boolean isCepEnabled) {
9904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9905
9906 final long identity = Binder.clearCallingIdentity();
9907 try {
9908 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9909 for (Phone phone : PhoneFactory.getPhones()) {
9910 Phone defaultPhone = phone.getImsPhone();
9911 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9912 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9913 ImsPhoneCallTracker imsPhoneCallTracker =
9914 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9915 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9916 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9917 + imsPhone.getMsisdn());
9918 }
9919 }
9920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
allenwtsu46dcc572020-01-08 18:24:03 +08009924
9925 /**
9926 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9927 *
9928 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9929 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9930 * before being read.
9931 */
9932 @Override
9933 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9934 isCompressed) {
9935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9936 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9938 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9939 }
9940 if (!isImsAvailableOnDevice()) {
9941 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9942 "IMS not available on device.");
9943 }
9944
9945 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009946 try {
Hui Wang761a6682020-10-31 05:12:53 +00009947 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9948 } finally {
9949 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009950 }
9951 }
zoey chene02881a2019-12-30 16:11:23 +08009952
9953 @Override
9954 public boolean isIccLockEnabled(int subId) {
9955 enforceReadPrivilegedPermission("isIccLockEnabled");
9956
9957 // Now that all security checks passes, perform the operation as ourselves.
9958 final long identity = Binder.clearCallingIdentity();
9959 try {
9960 Phone phone = getPhone(subId);
9961 if (phone != null && phone.getIccCard() != null) {
9962 return phone.getIccCard().getIccLockEnabled();
9963 } else {
9964 return false;
9965 }
9966 } finally {
9967 Binder.restoreCallingIdentity(identity);
9968 }
9969 }
9970
9971 /**
9972 * Set the ICC pin lock enabled or disabled.
9973 *
9974 * @return an integer representing the status of IccLock enabled or disabled in the following
9975 * three cases:
9976 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9977 * successfully.
9978 * - Positive number and zero for remaining password attempts.
9979 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9980 *
9981 */
9982 @Override
9983 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9984 enforceModifyPermission();
9985
9986 Phone phone = getPhone(subId);
9987 if (phone == null) {
9988 return 0;
9989 }
9990 // Now that all security checks passes, perform the operation as ourselves.
9991 final long identity = Binder.clearCallingIdentity();
9992 try {
9993 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9994 new Pair<Boolean, String>(enabled, password), phone, null);
9995 return attemptsRemaining;
9996
9997 } catch (Exception e) {
9998 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9999 } finally {
10000 Binder.restoreCallingIdentity(identity);
10001 }
10002 return 0;
10003 }
10004
10005 /**
10006 * Change the ICC password used in ICC pin lock.
10007 *
10008 * @return an integer representing the status of IccLock changed in the following three cases:
10009 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10010 * - Positive number and zero for remaining password attempts.
10011 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10012 *
10013 */
10014 @Override
10015 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10016 enforceModifyPermission();
10017
10018 Phone phone = getPhone(subId);
10019 if (phone == null) {
10020 return 0;
10021 }
10022 // Now that all security checks passes, perform the operation as ourselves.
10023 final long identity = Binder.clearCallingIdentity();
10024 try {
10025 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10026 new Pair<String, String>(oldPassword, newPassword), phone, null);
10027 return attemptsRemaining;
10028
10029 } catch (Exception e) {
10030 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10031 } finally {
10032 Binder.restoreCallingIdentity(identity);
10033 }
10034 return 0;
10035 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010036
10037 /**
10038 * Request for receiving user activity notification
10039 */
10040 @Override
10041 public void requestUserActivityNotification() {
10042 if (!mNotifyUserActivity.get()
10043 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10044 mNotifyUserActivity.set(true);
10045 }
10046 }
10047
10048 /**
10049 * Called when userActivity is signalled in the power manager.
10050 * This is safe to call from any thread, with any window manager locks held or not.
10051 */
10052 @Override
10053 public void userActivity() {
10054 // ***************************************
10055 // * Inherited from PhoneWindowManager *
10056 // ***************************************
10057 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10058 // WITH ITS LOCKS HELD.
10059 //
10060 // This code must be VERY careful about the locks
10061 // it acquires.
10062 // In fact, the current code acquires way too many,
10063 // and probably has lurking deadlocks.
10064
10065 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10066 throw new SecurityException("Only the OS may call notifyUserActivity()");
10067 }
10068
10069 if (mNotifyUserActivity.getAndSet(false)) {
10070 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10071 USER_ACTIVITY_NOTIFICATION_DELAY);
10072 }
10073 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010074
10075 @Override
10076 public boolean canConnectTo5GInDsdsMode() {
10077 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10078 }
Jack Yud10cdd42020-09-28 20:28:01 -070010079
10080 @Override
10081 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10082 String callingFeatureId) {
10083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10084 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10085 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10086 }
10087
10088 Phone phone = getPhone(subId);
10089 if (phone == null) {
10090 throw new RuntimeException("phone is not available");
10091 }
10092 // Now that all security checks passes, perform the operation as ourselves.
10093 final long identity = Binder.clearCallingIdentity();
10094 try {
10095 return phone.getEquivalentHomePlmns();
10096 } finally {
10097 Binder.restoreCallingIdentity(identity);
10098 }
10099 }
Daniel Bright59e67312020-11-13 11:49:37 -080010100
10101 @Override
10102 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010103 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10104 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010105 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010106 if (radioInterfaceCapabilities == null) {
10107 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010108 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010109 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010110 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010111
Hui Wang641e81c2020-10-12 12:14:23 -070010112 @Override
10113 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10114 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010115 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10116 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10117 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10118 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10119 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010120 if (DBG) {
10121 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10122 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10123 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10124 }
10125
10126 if (!SubscriptionManager.isValidSubscriptionId(subId)
10127 || appType < TelephonyManager.APPTYPE_UNKNOWN
10128 || appType > TelephonyManager.APPTYPE_ISIM
10129 || nafUrl == null || securityProtocol == null || callback == null) {
10130 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10131 if (callback != null) {
10132 try {
10133 callback.onAuthenticationFailure(
10134 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10135 } catch (RemoteException exception) {
10136 log("Fail to notify onAuthenticationFailure due to " + exception);
10137 }
10138 return;
10139 }
10140 }
10141
10142 final long token = Binder.clearCallingIdentity();
10143 try {
10144 getGbaManager(subId).bootstrapAuthenticationRequest(
10145 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10146 forceBootStrapping, callback));
10147 } finally {
10148 Binder.restoreCallingIdentity(token);
10149 }
10150 }
10151
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010152 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010153 * Attempts to set the radio power state for all phones for thermal reason.
10154 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010155 * requested radio power state will actually be set. See {@link
10156 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10157 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010158 * @param enable {@code true} if trying to turn radio on.
10159 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10160 * false}.
10161 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010162 private boolean setRadioPowerForThermal(boolean enable) {
10163 boolean isPhoneAvailable = false;
10164 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10165 Phone phone = PhoneFactory.getPhone(i);
10166 if (phone != null) {
10167 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10168 isPhoneAvailable = true;
10169 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010170 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010171
10172 // return true if successfully informed the phone object about the thermal radio power
10173 // request.
10174 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010175 }
10176
10177 private int handleDataThrottlingRequest(int subId,
10178 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010179 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10180 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10181 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10182 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10183 throw new IllegalArgumentException("modem does not support data throttling");
10184 }
10185
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010186 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10187 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010188 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010189 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10190 }
10191
10192 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10193
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010194 if (isDataThrottlingSupported) {
10195 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010196 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010197 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10198 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10199 } else if (thermalMitigationResult
10200 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010201 log("Modem likely does not support data throttling on secondary carrier. Data " +
10202 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10203 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010204 }
10205 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010207
10208 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010209 }
10210
Jack Nudelman644b91a2021-03-12 14:09:48 -080010211 private static List<String> getThermalMitigationAllowlist(Context context) {
10212 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10213 for (String pckg : context.getResources()
10214 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10215 sThermalMitigationAllowlistedPackages.add(pckg);
10216 }
10217 }
10218
10219 return sThermalMitigationAllowlistedPackages;
10220 }
10221
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010222 private boolean isAnyPhoneInEmergencyState() {
10223 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10224 if (tm.isInEmergencyCall()) {
10225 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10226 return true;
10227 }
10228 for (Phone phone : PhoneFactory.getPhones()) {
10229 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10230 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10231 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10232 + phone.isInEcm());
10233 return true;
10234 }
10235 }
10236
10237 return false;
10238 }
10239
Jack Nudelman644b91a2021-03-12 14:09:48 -080010240 /**
10241 * Used by shell commands to add an authorized package name for thermal mitigation.
10242 * @param packageName name of package to be allowlisted
10243 * @param context
10244 */
10245 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10246 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10247 sThermalMitigationAllowlistedPackages.add(packageName);
10248 }
10249
10250 /**
10251 * Used by shell commands to remove an authorized package name for thermal mitigation.
10252 * @param packageName name of package to remove from allowlist
10253 * @param context
10254 */
10255 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10256 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10257 sThermalMitigationAllowlistedPackages.remove(packageName);
10258 }
10259
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010260 /**
10261 * Thermal mitigation request to control functionalities at modem.
10262 *
10263 * @param subId the id of the subscription.
10264 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010265 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 *
10267 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10268 */
10269 @Override
10270 @ThermalMitigationResult
10271 public int sendThermalMitigationRequest(
10272 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010273 ThermalMitigationRequest thermalMitigationRequest,
10274 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010275 enforceModifyPermission();
10276
Jack Nudelman644b91a2021-03-12 14:09:48 -080010277 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10278 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10279 .contains(callingPackage)) {
10280 throw new SecurityException("Calling package must be configured in the device config. "
10281 + "calling package: " + callingPackage);
10282 }
10283
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10285 final long identity = Binder.clearCallingIdentity();
10286
10287 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10288 try {
10289 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10290 switch (thermalMitigationAction) {
10291 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10292 thermalMitigationResult =
10293 handleDataThrottlingRequest(subId,
10294 thermalMitigationRequest.getDataThrottlingRequest());
10295 break;
10296 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10297 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10298 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10299 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10300 }
10301
10302 // Ensure that radio is on. If not able to power on due to phone being
10303 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010304 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010305 thermalMitigationResult =
10306 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10307 break;
10308 }
10309
10310 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10311 false);
10312 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10313 break;
10314 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10315 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10316 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10317 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10318 }
10319
10320 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10321 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010322 Phone phone = getPhone(subId);
10323 if (phone == null) {
10324 thermalMitigationResult =
10325 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10326 break;
10327 }
10328
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010329 TelephonyConnectionService service =
10330 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010331 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010332 Log.e(LOG_TAG, "An emergency call is pending");
10333 thermalMitigationResult =
10334 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10335 break;
10336 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010337 thermalMitigationResult =
10338 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10339 break;
10340 }
10341 } else {
10342 thermalMitigationResult =
10343 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10344 break;
10345 }
10346
10347 // Turn radio off. If not able to power off due to phone being unavailable,
10348 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010349 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010350 thermalMitigationResult =
10351 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10352 break;
10353 }
10354 thermalMitigationResult =
10355 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10356 break;
10357 default:
10358 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10359 + "not exist. Requested action: " + thermalMitigationAction);
10360 }
10361 } catch (IllegalArgumentException e) {
10362 throw e;
10363 } catch (Exception e) {
10364 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10365 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369
10370 if (DBG) {
10371 log("thermalMitigationRequest returning with thermalMitigationResult: "
10372 + thermalMitigationResult);
10373 }
10374
10375 return thermalMitigationResult;
10376 }
Hui Wang641e81c2020-10-12 12:14:23 -070010377
10378 /**
10379 * Set the GbaService Package Name that Telephony will bind to.
10380 *
10381 * @param subId The sim that the GbaService is associated with.
10382 * @param packageName The name of the package to be replaced with.
10383 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10384 */
10385 @Override
10386 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10387 enforceModifyPermission();
10388
10389 final long identity = Binder.clearCallingIdentity();
10390 try {
10391 return getGbaManager(subId).overrideServicePackage(packageName);
10392 } finally {
10393 Binder.restoreCallingIdentity(identity);
10394 }
10395 }
10396
10397 /**
10398 * Return the package name of the currently bound GbaService.
10399 *
10400 * @param subId The sim that the GbaService is associated with.
10401 * @return the package name of the GbaService configuration, null if GBA is not supported.
10402 */
10403 @Override
10404 public String getBoundGbaService(int subId) {
10405 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10406
10407 final long identity = Binder.clearCallingIdentity();
10408 try {
10409 return getGbaManager(subId).getServicePackage();
10410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
10415 /**
10416 * Set the release time for telephony to unbind GbaService.
10417 *
10418 * @param subId The sim that the GbaService is associated with.
10419 * @param interval The release time to unbind GbaService by millisecond.
10420 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10421 */
10422 @Override
10423 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10424 enforceModifyPermission();
10425
10426 final long identity = Binder.clearCallingIdentity();
10427 try {
10428 return getGbaManager(subId).overrideReleaseTime(interval);
10429 } finally {
10430 Binder.restoreCallingIdentity(identity);
10431 }
10432 }
10433
10434 /**
10435 * Return the release time for telephony to unbind GbaService.
10436 *
10437 * @param subId The sim that the GbaService is associated with.
10438 * @return The release time to unbind GbaService by millisecond.
10439 */
10440 @Override
10441 public int getGbaReleaseTime(int subId) {
10442 enforceReadPrivilegedPermission("getGbaReleaseTime");
10443
10444 final long identity = Binder.clearCallingIdentity();
10445 try {
10446 return getGbaManager(subId).getReleaseTime();
10447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
10450 }
10451
10452 private GbaManager getGbaManager(int subId) {
10453 GbaManager instance = GbaManager.getInstance(subId);
10454 if (instance == null) {
10455 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10456 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10457 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10458 }
10459 return instance;
10460 }
Hui Wang761a6682020-10-31 05:12:53 +000010461
10462 /**
10463 * indicate whether the device and the carrier can support
10464 * RCS VoLTE single registration.
10465 */
10466 @Override
10467 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010468 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10469 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10470 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10471 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010472
10473 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10474 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10475 }
10476
10477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10480 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010481 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10482 if (isCapable != null) {
10483 return isCapable;
10484 }
Hui Wang761a6682020-10-31 05:12:53 +000010485 }
Hui Wang67af90e2021-06-04 16:57:15 -070010486 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10487 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010488 } finally {
10489 Binder.restoreCallingIdentity(identity);
10490 }
10491 }
10492
10493 /**
10494 * Register RCS provisioning callback.
10495 */
10496 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010497 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010498 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010499 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010500 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010501 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10502 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010503
10504 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10505 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10506 }
10507 if (!isImsAvailableOnDevice()) {
10508 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10509 "IMS not available on device.");
10510 }
10511
10512 final long identity = Binder.clearCallingIdentity();
10513 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010514 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010515 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010516 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10517 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010518 }
Hui Wang761a6682020-10-31 05:12:53 +000010519 } finally {
10520 Binder.restoreCallingIdentity(identity);
10521 }
10522 }
10523
10524 /**
10525 * Unregister RCS provisioning callback.
10526 */
10527 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010528 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010529 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010530 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010531 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010532 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10533 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010534
10535 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10536 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10537 }
10538 if (!isImsAvailableOnDevice()) {
10539 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10540 "IMS not available on device.");
10541 }
10542
10543 final long identity = Binder.clearCallingIdentity();
10544 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010545 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010546 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010547 } finally {
10548 Binder.restoreCallingIdentity(identity);
10549 }
10550 }
10551
10552 /**
10553 * trigger RCS reconfiguration.
10554 */
10555 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010556 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10557 "triggerRcsReconfiguration",
10558 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010559
10560 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10561 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10562 }
10563 if (!isImsAvailableOnDevice()) {
10564 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10565 "IMS not available on device.");
10566 }
10567
10568 final long identity = Binder.clearCallingIdentity();
10569 try {
10570 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10571 } finally {
10572 Binder.restoreCallingIdentity(identity);
10573 }
10574 }
10575
10576 /**
10577 * Provide the client configuration parameters of the RCS application.
10578 */
10579 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010580 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10581 "setRcsClientConfiguration",
10582 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010583
10584 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10585 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10586 }
10587 if (!isImsAvailableOnDevice()) {
10588 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10589 "IMS not available on device.");
10590 }
10591
10592 final long identity = Binder.clearCallingIdentity();
10593
10594 try {
10595 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10596 if (configBinder == null) {
10597 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010598 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10599 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010600 } else {
10601 configBinder.setRcsClientConfiguration(rcc);
10602 }
joonhunshin3e154242021-09-17 06:33:39 +000010603
10604 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10605 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010606 } catch (RemoteException e) {
10607 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010608 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10609 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010610 } finally {
10611 Binder.restoreCallingIdentity(identity);
10612 }
10613 }
10614
10615 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010616 * Enables or disables the test mode for RCS VoLTE single registration.
10617 */
10618 @Override
10619 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10621 "setRcsSingleRegistrationTestModeEnabled");
10622
10623 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10624 }
10625
10626 /**
10627 * Gets the test mode for RCS VoLTE single registration.
10628 */
10629 @Override
10630 public boolean getRcsSingleRegistrationTestModeEnabled() {
10631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10632 "getRcsSingleRegistrationTestModeEnabled");
10633
10634 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10635 }
10636
10637 /**
Hui Wang761a6682020-10-31 05:12:53 +000010638 * Overrides the config of RCS VoLTE single registration enabled for the device.
10639 */
10640 @Override
10641 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10643 "setDeviceSingleRegistrationEnabledOverride");
10644 enforceModifyPermission();
10645
10646 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10647 : Boolean.parseBoolean(enabledStr);
10648 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010649 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010650 }
10651
10652 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010653 * Sends a device to device communication message. Only usable via shell.
10654 * @param message message to send.
10655 * @param value message value.
10656 */
10657 @Override
10658 public void sendDeviceToDeviceMessage(int message, int value) {
10659 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010660 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010661 enforceModifyPermission();
10662
10663 final long identity = Binder.clearCallingIdentity();
10664 try {
10665 TelephonyConnectionService service =
10666 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10667 if (service == null) {
10668 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10669 return;
10670 }
10671 service.sendTestDeviceToDeviceMessage(message, value);
10672 } finally {
10673 Binder.restoreCallingIdentity(identity);
10674 }
10675 }
10676
Tyler Gunnbabbda02021-02-10 11:05:02 -080010677 /**
10678 * Sets the specified device to device transport active.
10679 * @param transport The transport to set active.
10680 */
10681 @Override
10682 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10684 "setActiveDeviceToDeviceTransport");
10685 enforceModifyPermission();
10686
10687 final long identity = Binder.clearCallingIdentity();
10688 try {
10689 TelephonyConnectionService service =
10690 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10691 if (service == null) {
10692 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10693 return;
10694 }
10695 service.setActiveDeviceToDeviceTransport(transport);
10696 } finally {
10697 Binder.restoreCallingIdentity(identity);
10698 }
10699 }
Tyler Gunn92479152021-01-20 16:30:10 -080010700
Tyler Gunnd4339262021-05-03 14:46:49 -070010701 @Override
10702 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10704 "setDeviceToDeviceForceEnabled");
10705
10706 final long identity = Binder.clearCallingIdentity();
10707 try {
10708 Arrays.stream(PhoneFactory.getPhones()).forEach(
10709 p -> {
10710 Phone thePhone = p.getImsPhone();
10711 if (thePhone != null && thePhone instanceof ImsPhone) {
10712 ImsPhone imsPhone = (ImsPhone) thePhone;
10713 CallTracker tracker = imsPhone.getCallTracker();
10714 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10715 ImsPhoneCallTracker imsPhoneCallTracker =
10716 (ImsPhoneCallTracker) tracker;
10717 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10718 }
10719 }
10720 }
10721 );
10722 } finally {
10723 Binder.restoreCallingIdentity(identity);
10724 }
10725 }
10726
Tyler Gunn92479152021-01-20 16:30:10 -080010727 /**
Hui Wang761a6682020-10-31 05:12:53 +000010728 * Gets the config of RCS VoLTE single registration enabled for the device.
10729 */
10730 @Override
10731 public boolean getDeviceSingleRegistrationEnabled() {
10732 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10733 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10734 }
10735
10736 /**
10737 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10738 */
10739 @Override
10740 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10742 "setCarrierSingleRegistrationEnabledOverride");
10743 enforceModifyPermission();
10744
10745 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10746 : Boolean.parseBoolean(enabledStr);
10747 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10748 subId, enabled);
10749 }
10750
10751 /**
10752 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10753 */
10754 @Override
10755 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10756 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10757 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10758 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010759
10760 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010761 * Overrides the ims feature validation result
10762 */
10763 @Override
10764 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10766 "setImsFeatureValidationOverride");
10767
10768 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10769 : Boolean.parseBoolean(enabledStr);
10770 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10771 subId, enabled);
10772 }
10773
10774 /**
10775 * Gets the ims feature validation override value
10776 */
10777 @Override
10778 public boolean getImsFeatureValidationOverride(int subId) {
10779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10780 "getImsFeatureValidationOverride");
10781 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10782 }
10783
10784 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010785 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10786 * their mobile plan.
10787 */
10788 @Override
10789 public String getMobileProvisioningUrl() {
10790 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 return getDefaultPhone().getMobileProvisioningUrl();
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010798
James.cf Linbcdf8b32021-01-14 16:44:13 +080010799 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010800 * Get the EAB contact from the EAB database.
10801 */
10802 @Override
10803 public String getContactFromEab(String contact) {
10804 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10805 enforceModifyPermission();
10806 final long identity = Binder.clearCallingIdentity();
10807 try {
10808 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10809 } finally {
10810 Binder.restoreCallingIdentity(identity);
10811 }
10812 }
10813
10814 /**
Calvin Pana1434322021-07-01 19:27:01 +080010815 * Get the EAB capability from the EAB database.
10816 */
10817 @Override
10818 public String getCapabilityFromEab(String contact) {
10819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10820 enforceModifyPermission();
10821 final long identity = Binder.clearCallingIdentity();
10822 try {
10823 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10824 } finally {
10825 Binder.restoreCallingIdentity(identity);
10826 }
10827 }
10828
10829 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010830 * Remove the EAB contacts from the EAB database.
10831 */
10832 @Override
10833 public int removeContactFromEab(int subId, String contacts) {
10834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10835 enforceModifyPermission();
10836 final long identity = Binder.clearCallingIdentity();
10837 try {
10838 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
10843
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010844 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010845 public boolean getDeviceUceEnabled() {
10846 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10847 final long identity = Binder.clearCallingIdentity();
10848 try {
10849 return mApp.getDeviceUceEnabled();
10850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
10854
10855 @Override
10856 public void setDeviceUceEnabled(boolean isEnabled) {
10857 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10858 final long identity = Binder.clearCallingIdentity();
10859 try {
10860 mApp.setDeviceUceEnabled(isEnabled);
10861 } finally {
10862 Binder.restoreCallingIdentity(identity);
10863 }
10864 }
10865
Brad Ebinger14d467f2021-02-12 06:18:28 +000010866 /**
10867 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10868 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10869 */
10870 // Used for SHELL command only right now.
10871 @Override
10872 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10873 List<String> featureTags) {
10874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10875 "addUceRegistrationOverrideShell");
10876 final long identity = Binder.clearCallingIdentity();
10877 try {
10878 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10879 new ArraySet<>(featureTags));
10880 } catch (ImsException e) {
10881 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10882 } finally {
10883 Binder.restoreCallingIdentity(identity);
10884 }
10885 }
10886
10887 /**
10888 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10889 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10890 */
10891 // Used for SHELL command only right now.
10892 @Override
10893 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10894 List<String> featureTags) {
10895 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10896 "removeUceRegistrationOverrideShell");
10897 final long identity = Binder.clearCallingIdentity();
10898 try {
10899 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10900 new ArraySet<>(featureTags));
10901 } catch (ImsException e) {
10902 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10903 } finally {
10904 Binder.restoreCallingIdentity(identity);
10905 }
10906 }
10907
10908 /**
10909 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10910 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10911 */
10912 // Used for SHELL command only right now.
10913 @Override
10914 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10916 "clearUceRegistrationOverrideShell");
10917 final long identity = Binder.clearCallingIdentity();
10918 try {
10919 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10920 } catch (ImsException e) {
10921 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
10926
10927 /**
10928 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10929 */
10930 // Used for SHELL command only right now.
10931 @Override
10932 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10934 "getLatestRcsContactUceCapabilityShell");
10935 final long identity = Binder.clearCallingIdentity();
10936 try {
10937 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10938 } catch (ImsException e) {
10939 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10940 } finally {
10941 Binder.restoreCallingIdentity(identity);
10942 }
10943 }
10944
10945 /**
10946 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10947 * device does not have an active PUBLISH.
10948 */
10949 // Used for SHELL command only right now.
10950 @Override
10951 public String getLastUcePidfXmlShell(int subId) {
10952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
10955 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10956 } catch (ImsException e) {
10957 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
James.cf Line8713a42021-04-29 16:04:26 +080010963 /**
10964 * Remove UCE requests cannot be sent to the network status.
10965 */
10966 // Used for SHELL command only right now.
10967 @Override
10968 public boolean removeUceRequestDisallowedStatus(int subId) {
10969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
10972 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10973 } catch (ImsException e) {
10974 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10975 } finally {
10976 Binder.restoreCallingIdentity(identity);
10977 }
10978 }
10979
James.cf Lin18bb9002021-05-25 01:37:38 +080010980 /**
10981 * Remove UCE requests cannot be sent to the network status.
10982 */
10983 // Used for SHELL command only.
10984 @Override
10985 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10987 final long identity = Binder.clearCallingIdentity();
10988 try {
10989 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10990 } catch (ImsException e) {
10991 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10992 } finally {
10993 Binder.restoreCallingIdentity(identity);
10994 }
10995 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010996
James.cf Lin4b784aa2021-01-31 03:25:15 +080010997 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010998 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10999 String callingPackage) {
11000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11001 mApp, subId, "setSignalStrengthUpdateRequest");
11002
11003 final int callingUid = Binder.getCallingUid();
11004 // Verify that tha callingPackage belongs to the calling UID
11005 mApp.getSystemService(AppOpsManager.class)
11006 .checkPackage(callingUid, callingPackage);
11007
Rambo Wang3607f502021-02-01 21:51:40 -080011008 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011009
11010 final long identity = Binder.clearCallingIdentity();
11011 try {
11012 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11013 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11014
11015 if (result instanceof IllegalStateException) {
11016 throw (IllegalStateException) result;
11017 }
11018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
11022
11023 @Override
11024 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11025 String callingPackage) {
11026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11027 mApp, subId, "clearSignalStrengthUpdateRequest");
11028
11029 final int callingUid = Binder.getCallingUid();
11030 // Verify that tha callingPackage belongs to the calling UID
11031 mApp.getSystemService(AppOpsManager.class)
11032 .checkPackage(callingUid, callingPackage);
11033
11034 final long identity = Binder.clearCallingIdentity();
11035 try {
11036 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11037 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11038
11039 if (result instanceof IllegalStateException) {
11040 throw (IllegalStateException) result;
11041 }
11042 } finally {
11043 Binder.restoreCallingIdentity(identity);
11044 }
11045 }
11046
Rambo Wang3607f502021-02-01 21:51:40 -080011047 private static void validateSignalStrengthUpdateRequest(Context context,
11048 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011049 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11050 // phone/system process do not have further restriction on request
11051 return;
11052 }
11053
11054 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011055 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011056 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011057 context.enforceCallingOrSelfPermission(
11058 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11059 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011060 }
11061
11062 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11063 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11064 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11065 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11066 || info.isEnabled()) {
11067 throw new IllegalArgumentException(
11068 "Only system can set hide fields in SignalThresholdInfo");
11069 }
11070
11071 // Thresholds length for each RAN need in range. This has been validated in
11072 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11073 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11074 final int[] thresholds = info.getThresholds();
11075 Objects.requireNonNull(thresholds);
11076 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11077 || thresholds.length
11078 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11079 throw new IllegalArgumentException(
11080 "thresholds length is out of range: " + thresholds.length);
11081 }
11082 }
11083 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011084
11085 /**
11086 * Gets the current phone capability.
11087 *
11088 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11089 * @return the PhoneCapability which describes the data connection capability of modem.
11090 * It's used to evaluate possible phone config change, for example from single
11091 * SIM device to multi-SIM device.
11092 */
11093 @Override
11094 public PhoneCapability getPhoneCapability() {
11095 enforceReadPrivilegedPermission("getPhoneCapability");
11096 final long identity = Binder.clearCallingIdentity();
11097 try {
11098 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11099 } finally {
11100 Binder.restoreCallingIdentity(identity);
11101 }
11102 }
Michele Berionne5e411512020-11-13 02:36:59 +000011103
11104 /**
11105 * Prepare TelephonyManager for an unattended reboot. The reboot is
11106 * required to be done shortly after the API is invoked.
11107 */
11108 @Override
11109 @TelephonyManager.PrepareUnattendedRebootResult
11110 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011112 enforceRebootPermission();
11113
11114 final long identity = Binder.clearCallingIdentity();
11115 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011116 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011117 } finally {
11118 Binder.restoreCallingIdentity(identity);
11119 }
11120 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011121
11122 /**
11123 * Request to get the current slicing configuration including URSP rules and
11124 * NSSAIs (configured, allowed and rejected).
11125 *
11126 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11127 */
11128 @Override
11129 public void getSlicingConfig(ResultReceiver callback) {
11130 enforceReadPrivilegedPermission("getSlicingConfig");
11131
11132 final long identity = Binder.clearCallingIdentity();
11133 try {
11134 Phone phone = getDefaultPhone();
11135 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11136 } finally {
11137 Binder.restoreCallingIdentity(identity);
11138 }
11139 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011140
11141 /**
11142 * Register an IMS connection state callback
11143 */
11144 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011145 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11146 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011147 if (feature == ImsFeature.FEATURE_MMTEL) {
11148 // ImsMmTelManager
11149 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11150 TelephonyPermissions
11151 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11152 mApp, subId, "registerImsStateCallback");
11153 } else if (feature == ImsFeature.FEATURE_RCS) {
11154 // ImsRcsManager or SipDelegateManager
11155 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11156 Binder.getCallingUid(), "registerImsStateCallback",
11157 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11158 Manifest.permission.READ_PRECISE_PHONE_STATE,
11159 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11160 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11161 }
11162
11163 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11164 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11165 "IMS not available on device.");
11166 }
11167
11168 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11169 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11170 }
11171
11172 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11173 if (controller == null) {
11174 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11175 "IMS not available on device.");
11176 }
11177
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011178 if (callingPackage == null) {
11179 callingPackage = getCurrentPackageName();
11180 }
11181
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011182 final long token = Binder.clearCallingIdentity();
11183 try {
11184 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011185 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011186 } catch (ImsException e) {
11187 throw new ServiceSpecificException(e.getCode());
11188 } finally {
11189 Binder.restoreCallingIdentity(token);
11190 }
11191 }
11192
11193 /**
11194 * Unregister an IMS connection state callback
11195 */
11196 @Override
11197 public void unregisterImsStateCallback(IImsStateCallback cb) {
11198 final long token = Binder.clearCallingIdentity();
11199 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11200 if (controller == null) {
11201 return;
11202 }
11203 try {
11204 controller.unregisterImsStateCallback(cb);
11205 } finally {
11206 Binder.restoreCallingIdentity(token);
11207 }
11208 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011209
11210 /**
11211 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11212 *
11213 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11214 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11215 * SecurityException.
11216 * If there is current registered network this value will be same as the registered cell
11217 * identity. If the device goes out of service the previous cell identity is cached and
11218 * will be returned. If the cache age of the Cell identity is more than 24 hours
11219 * it will be cleared and null will be returned.
11220 *
11221 */
11222 @Override
11223 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11224 String callingFeatureId) {
11225 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11226 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11227 LocationAccessPolicy.checkLocationPermission(mApp,
11228 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11229 .setCallingPackage(callingPackage)
11230 .setCallingFeatureId(callingFeatureId)
11231 .setCallingPid(Binder.getCallingPid())
11232 .setCallingUid(Binder.getCallingUid())
11233 .setMethod("getLastKnownCellIdentity")
11234 .setLogAsInfo(true)
11235 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11236 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11237 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11238 .build());
11239
11240 boolean hasFinePermission =
11241 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11242 if (!hasFinePermission
11243 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11244 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11245 + "and BIND_CONNECTION_SERVICE permission.");
11246 }
11247
11248 final long identity = Binder.clearCallingIdentity();
11249 try {
11250 Phone phone = getPhone(subId);
11251 if (phone == null) return null;
11252 ServiceStateTracker sst = phone.getServiceStateTracker();
11253 if (sst == null) return null;
11254 return sst.getLastKnownCellIdentity();
11255 } finally {
11256 Binder.restoreCallingIdentity(identity);
11257 }
11258 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011259
11260 @Override
11261 public boolean isUsingNewDataStack() {
11262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11263 return getDefaultPhone().isUsingNewDataStack();
11264 }
jimsun3b9ccac2021-10-26 15:01:23 +080011265
11266 /**
11267 * Sets the modem service class Name that Telephony will bind to.
11268 *
11269 * @param serviceName The class name of the modem service.
11270 * @return true if the operation is succeed, otherwise false.
11271 */
11272 public boolean setModemService(String serviceName) {
11273 Log.d(LOG_TAG, "setModemService - " + serviceName);
11274 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11276 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11277 "setModemService");
11278 return mPhoneConfigurationManager.setModemService(serviceName);
11279 }
11280
11281 /**
11282 * Return the class name of the currently bounded modem service.
11283 *
11284 * @return the class name of the modem service.
11285 */
11286 public String getModemService() {
11287 String result;
11288 Log.d(LOG_TAG, "getModemService");
11289 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11290 TelephonyPermissions
11291 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11292 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11293 "getModemService");
11294 result = mPhoneConfigurationManager.getModemService();
11295 Log.d(LOG_TAG, "result = " + result);
11296 return result;
11297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011298}