blob: a8e8f7943f326b36c5c4e97409cfaa64d095f680 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
Chen Xu540470b2021-12-14 17:15:47 -080036import android.compat.Compatibility;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
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;
joonhunshincffb7fc2021-11-28 07:32:01 +0000126import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700127import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800128import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700129import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000132import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700133import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800135import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800152import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700187import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800197import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800215import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700217import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800218import com.android.services.telephony.TelecomAccountRegistry;
219import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800220import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800221
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.IOException;
225import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000229import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800230import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800231import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800232import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800233import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100234import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700236import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800238import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800239import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800240import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800241import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
243/**
244 * Implementation of the ITelephony interface.
245 */
Santos Cordon117fee72014-05-16 17:56:12 -0700246public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 private static final String LOG_TAG = "PhoneInterfaceManager";
248 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
249 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800250 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251
252 // Message codes used with mMainThreadHandler
253 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700254 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
255 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700256 private static final int CMD_OPEN_CHANNEL = 9;
257 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
258 private static final int CMD_CLOSE_CHANNEL = 11;
259 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800260 private static final int CMD_NV_READ_ITEM = 13;
261 private static final int EVENT_NV_READ_ITEM_DONE = 14;
262 private static final int CMD_NV_WRITE_ITEM = 15;
263 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
264 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
265 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700266 private static final int CMD_RESET_MODEM_CONFIG = 19;
267 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800268 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
269 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800270 private static final int CMD_SEND_ENVELOPE = 25;
271 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000272 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
273 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700274 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
275 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
276 private static final int CMD_EXCHANGE_SIM_IO = 31;
277 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800278 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
279 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700280 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
281 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700282 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
283 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700284 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
285 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
286 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
287 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700288 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
289 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
290 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
291 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700292 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800293 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
294 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000295 private static final int CMD_SWITCH_SLOTS = 50;
296 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700297 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
298 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
299 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
300 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
301 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
302 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
303 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
304 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700305 private static final int CMD_GET_ALL_CELL_INFO = 60;
306 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
307 private static final int CMD_GET_CELL_LOCATION = 62;
308 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700309 private static final int CMD_MODEM_REBOOT = 64;
310 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700311 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
312 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800313 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
314 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700315 private static final int CMD_GET_MODEM_STATUS = 70;
316 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700317 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
318 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700319 private static final int CMD_ERASE_MODEM_CONFIG = 74;
320 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800321 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
322 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
323 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
324 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800325 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
326 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800327 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800328 private static final int CMD_GET_CALL_FORWARDING = 83;
329 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
330 private static final int CMD_SET_CALL_FORWARDING = 85;
331 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
332 private static final int CMD_GET_CALL_WAITING = 87;
333 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
334 private static final int CMD_SET_CALL_WAITING = 89;
335 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700336 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
337 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
338 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
339 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700340 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
341 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800342 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
343 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800344 private static final int CMD_SET_DATA_THROTTLING = 99;
345 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800346 private static final int CMD_SET_SIM_POWER = 101;
347 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800348 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
349 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
350 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
351 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800352 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
353 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000354 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800355 private static final int CMD_GET_SLICING_CONFIG = 110;
356 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800357 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700358 private static final int CMD_ENABLE_VONR = 113;
359 private static final int EVENT_ENABLE_VONR_DONE = 114;
360 private static final int CMD_IS_VONR_ENABLED = 115;
361 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800363 // Parameters of select command.
364 private static final int SELECT_COMMAND = 0xA4;
365 private static final int SELECT_P1 = 0x04;
366 private static final int SELECT_P2 = 0;
367 private static final int SELECT_P3 = 0x10;
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 /** The singleton instance. */
370 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800371 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800375 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700376 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700378 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800380 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700382 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800383 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 /** User Activity */
386 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
388
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700389 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
390
Derek Tan97ebb422014-09-05 16:55:38 -0700391 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
392 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800393 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800394 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700395
Michelecea4cf22018-12-21 15:00:11 -0800396 // String to store multi SIM allowed
397 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
398
Derek Tan740e1672017-06-27 14:56:27 -0700399 // The AID of ISD-R.
400 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
401
yinxub1bed742017-04-17 11:45:04 -0700402 private NetworkScanRequestTracker mNetworkScanRequestTracker;
403
David Kelly5e06a7f2018-03-12 14:10:59 +0000404 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
405 private static final int MANUFACTURER_CODE_LENGTH = 8;
406
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800408 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409
Derek Tan89e89d42014-07-08 17:00:10 -0700410 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700411 * Experiment flag to enable erase modem config on reset network, default value is false
412 */
413 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
414 "reset_network_erase_modem_config_enabled";
415
Rambo Wang0f050d82021-02-12 11:43:36 -0800416 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800417
sandeepjsb6c87872021-09-27 15:34:44 +0000418 /**
419 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
420 * one ICCID active at the same time.
421 * Apps should use below API signatures if targeting SDK is T and beyond.
422 *
423 * @hide
424 */
425 @ChangeId
426 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
427 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800428
Naina Nallurid63128d2019-09-17 14:10:30 -0700429 /**
Chen Xu540470b2021-12-14 17:15:47 -0800430 * Apps targeting on Android T and beyond will get exception whenever icc close channel
431 * operation fails.
432 */
433 @ChangeId
434 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
435 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
436
437 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 * A request object to use for transmitting data to an ICC.
439 */
440 private static final class IccAPDUArgument {
441 public int channel, cla, command, p1, p2, p3;
442 public String data;
443
444 public IccAPDUArgument(int channel, int cla, int command,
445 int p1, int p2, int p3, String data) {
446 this.channel = channel;
447 this.cla = cla;
448 this.command = command;
449 this.p1 = p1;
450 this.p2 = p2;
451 this.p3 = p3;
452 this.data = data;
453 }
454 }
455
456 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700457 * A request object to use for transmitting data to an ICC.
458 */
459 private static final class ManualNetworkSelectionArgument {
460 public OperatorInfo operatorInfo;
461 public boolean persistSelection;
462
463 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
464 this.operatorInfo = operatorInfo;
465 this.persistSelection = persistSelection;
466 }
467 }
468
469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
471 * request after sending. The main thread will notify the request when it is complete.
472 */
473 private static final class MainThreadRequest {
474 /** The argument to use for the request */
475 public Object argument;
476 /** The result of the request that is run on the main thread */
477 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800478 // The subscriber id that this request applies to. Defaults to
479 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
480 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
Nathan Harold92bed182018-10-12 18:16:49 -0700482 // In cases where subId is unavailable, the caller needs to specify the phone.
483 public Phone phone;
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 public WorkSource workSource;
486
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 public MainThreadRequest(Object argument) {
488 this.argument = argument;
489 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490
Nathan Harold92bed182018-10-12 18:16:49 -0700491 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
492 this.argument = argument;
493 if (phone != null) {
494 this.phone = phone;
495 }
496 this.workSource = workSource;
497 }
498
vagdeviaf9a5b92018-08-15 16:01:53 -0700499 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800500 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800501 if (subId != null) {
502 this.subId = subId;
503 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700504 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 }
507
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800508 private static final class IncomingThirdPartyCallArgs {
509 public final ComponentName component;
510 public final String callId;
511 public final String callerDisplayName;
512
513 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
514 String callerDisplayName) {
515 this.component = component;
516 this.callId = callId;
517 this.callerDisplayName = callerDisplayName;
518 }
519 }
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 /**
522 * A handler that processes messages on the main thread in the phone process. Since many
523 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
524 * inbound binder threads to the main thread in the phone process. The Binder thread
525 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
526 * on, which will be notified when the operation completes and will contain the result of the
527 * request.
528 *
529 * <p>If a MainThreadRequest object is provided in the msg.obj field,
530 * note that request.result must be set to something non-null for the calling thread to
531 * unblock.
532 */
533 private final class MainThreadHandler extends Handler {
534 @Override
535 public void handleMessage(Message msg) {
536 MainThreadRequest request;
537 Message onCompleted;
538 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000539 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800541 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542
543 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 case CMD_HANDLE_USSD_REQUEST: {
545 request = (MainThreadRequest) msg.obj;
546 final Phone phone = getPhoneFromRequest(request);
547 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800548 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 if (!isUssdApiAllowed(request.subId)) {
552 // Carrier does not support use of this API, return failure.
553 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
554 UssdResponse response = new UssdResponse(ussdRequest, null);
555 Bundle returnData = new Bundle();
556 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
557 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700558
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 request.result = true;
560 notifyRequester(request);
561 return;
562 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700563
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 try {
565 request.result = phone != null
566 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
567 } catch (CallStateException cse) {
568 request.result = false;
569 }
570 // Wake up the requesting thread
571 notifyRequester(request);
572 break;
pkanwar32d516d2016-10-14 19:37:38 -0700573 }
574
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 final Phone phone = getPhoneFromRequest(request);
578 request.result = phone != null ?
579 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
580 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000589 uiccPort = getUiccPortFromRequest(request);
590 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800592 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800596 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000597 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800598 iccArgument.channel, iccArgument.cla, iccArgument.command,
599 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
600 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800610 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800613 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800615 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 } else {
617 loge("iccTransmitApduLogicalChannel: Unknown exception");
618 }
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
625 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000626 uiccPort = getUiccPortFromRequest(request);
627 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800629 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800635 iccArgument.cla, iccArgument.command, iccArgument.p1,
636 iccArgument.p2,
637 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 }
639 break;
640
641 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
642 ar = (AsyncResult) msg.obj;
643 request = (MainThreadRequest) ar.userObj;
644 if (ar.exception == null && ar.result != null) {
645 request.result = ar.result;
646 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800647 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 if (ar.result == null) {
649 loge("iccTransmitApduBasicChannel: Empty response");
650 } else if (ar.exception instanceof CommandException) {
651 loge("iccTransmitApduBasicChannel: CommandException: " +
652 ar.exception);
653 } else {
654 loge("iccTransmitApduBasicChannel: Unknown exception");
655 }
656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 break;
659
660 case CMD_EXCHANGE_SIM_IO:
661 request = (MainThreadRequest) msg.obj;
662 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000663 uiccPort = getUiccPortFromRequest(request);
664 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
670 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000671 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
673 iccArgument.data, onCompleted);
674 }
675 break;
676
677 case EVENT_EXCHANGE_SIM_IO_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result;
682 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 break;
687
Derek Tan4d5e5c12014-02-04 11:54:58 -0800688 case CMD_SEND_ENVELOPE:
689 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
691 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800693 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800697 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700698 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800699 break;
700
701 case EVENT_SEND_ENVELOPE_DONE:
702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800706 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800707 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700708 if (ar.result == null) {
709 loge("sendEnvelopeWithStatus: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("sendEnvelopeWithStatus: CommandException: " +
712 ar.exception);
713 } else {
714 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
715 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 break;
719
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 case CMD_OPEN_CHANNEL:
721 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800723 IccLogicalChannelRequest openChannelRequest =
724 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000725 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800727 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800728 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 } else {
731 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800732 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
733 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 break;
736
737 case EVENT_OPEN_CHANNEL_DONE:
738 ar = (AsyncResult) msg.obj;
739 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 int[] result = (int[]) ar.result;
743 int channelId = result[0];
744 byte[] selectResponse = null;
745 if (result.length > 1) {
746 selectResponse = new byte[result.length - 1];
747 for (int i = 1; i < result.length; ++i) {
748 selectResponse[i - 1] = (byte) result[i];
749 }
750 }
751 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800752 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800753
754 uiccPort = getUiccPortFromRequest(request);
755 IccLogicalChannelRequest channelRequest =
756 (IccLogicalChannelRequest) request.argument;
757 channelRequest.channel = channelId;
758 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 if (ar.result == null) {
761 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700763 if (ar.exception != null) {
764 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
765 }
766
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700767 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700768 if (ar.exception instanceof CommandException) {
769 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800770 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700771 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700772 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700773 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700774 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700775 }
776 }
777 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800778 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700780 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700781 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 break;
783
784 case CMD_CLOSE_CHANNEL:
785 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000786 uiccPort = getUiccPortFromRequest(request);
787 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700788 loge("iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800789 // before this feature is enabled, this API should only return false if
790 // the operation fails instead of throwing runtime exception for
791 // backward-compatibility.
792 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
793 request.result = new IllegalArgumentException(
794 "iccCloseLogicalChannel: No UICC");
795 } else {
796 request.result = false;
797 }
798 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 } else {
800 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000801 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700802 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 break;
804
805 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 if (ar.exception == null) {
809 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800810 uiccPort = getUiccPortFromRequest(request);
811 final int channelId = (Integer) request.argument;
812 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800813 } else {
814 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800815 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800816 if (ar.exception instanceof CommandException) {
817 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800820 if (error == CommandException.Error.INVALID_ARGUMENTS) {
821 // should only throw exceptions from the binder threads.
822 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800823 "iccCloseLogicalChannel: invalid argument ");
824 }
825 } else {
826 loge("iccCloseLogicalChannel: Unknown exception");
827 }
Chen Xue9d737e2022-01-01 23:41:31 -0800828 // before this feature is enabled, this API should only return false if
829 // the operation fails instead of throwing runtime exception for
830 // backward-compatibility.
831 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE))
832 request.result = (exception != null) ? exception :
833 new IllegalStateException(
834 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800835 }
836 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800837 break;
838
839 case CMD_NV_READ_ITEM:
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800842 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
843 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800844 break;
845
846 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800849 if (ar.exception == null && ar.result != null) {
850 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800852 request.result = "";
853 if (ar.result == null) {
854 loge("nvReadItem: Empty response");
855 } else if (ar.exception instanceof CommandException) {
856 loge("nvReadItem: CommandException: " +
857 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800859 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700860 }
861 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700862 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700863 break;
864
Jake Hambye994d462014-02-03 13:10:13 -0800865 case CMD_NV_WRITE_ITEM:
866 request = (MainThreadRequest) msg.obj;
867 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
868 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800869 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700870 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800871 break;
872
873 case EVENT_NV_WRITE_ITEM_DONE:
874 handleNullReturnEvent(msg, "nvWriteItem");
875 break;
876
877 case CMD_NV_WRITE_CDMA_PRL:
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800880 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800881 break;
882
883 case EVENT_NV_WRITE_CDMA_PRL_DONE:
884 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
885 break;
886
chen xu6dac5ab2018-10-26 17:39:23 -0700887 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800888 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700889 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800890 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
chen xu6dac5ab2018-10-26 17:39:23 -0700893 case EVENT_RESET_MODEM_CONFIG_DONE:
894 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800895 break;
896
Sooraj Sasindran37444802020-08-11 10:40:43 -0700897 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
898 request = (MainThreadRequest) msg.obj;
899 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
900 request);
901 Phone phone = getPhoneFromRequest(request);
902 if (phone != null) {
903 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
904 } else {
905 loge("isNRDualConnectivityEnabled: No phone object");
906 request.result = false;
907 notifyRequester(request);
908 }
909 break;
910 }
911
912 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 if (ar.exception == null && ar.result != null) {
916 request.result = ar.result;
917 } else {
918 // request.result must be set to something non-null
919 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700920 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700921 request.result = ar.result;
922 } else {
923 request.result = false;
924 }
925 if (ar.result == null) {
926 loge("isNRDualConnectivityEnabled: Empty response");
927 } else if (ar.exception instanceof CommandException) {
928 loge("isNRDualConnectivityEnabled: CommandException: "
929 + ar.exception);
930 } else {
931 loge("isNRDualConnectivityEnabled: Unknown exception");
932 }
933 }
934 notifyRequester(request);
935 break;
936
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700937 case CMD_IS_VONR_ENABLED: {
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
940 request);
941 Phone phone = getPhoneFromRequest(request);
942 if (phone != null) {
943 phone.isVoNrEnabled(onCompleted, request.workSource);
944 } else {
945 loge("isVoNrEnabled: No phone object");
946 request.result = false;
947 notifyRequester(request);
948 }
949 break;
950 }
951
952 case EVENT_IS_VONR_ENABLED_DONE:
953 ar = (AsyncResult) msg.obj;
954 request = (MainThreadRequest) ar.userObj;
955 if (ar.exception == null && ar.result != null) {
956 request.result = ar.result;
957 } else {
958 // request.result must be set to something non-null
959 // for the calling thread to unblock
960 if (ar.result != null) {
961 request.result = ar.result;
962 } else {
963 request.result = false;
964 }
965 if (ar.result == null) {
966 loge("isVoNrEnabled: Empty response");
967 } else if (ar.exception instanceof CommandException) {
968 loge("isVoNrEnabled: CommandException: "
969 + ar.exception);
970 } else {
971 loge("isVoNrEnabled: Unknown exception");
972 }
973 }
974 notifyRequester(request);
975 break;
976
Sooraj Sasindran37444802020-08-11 10:40:43 -0700977 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
978 request = (MainThreadRequest) msg.obj;
979 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
980 Phone phone = getPhoneFromRequest(request);
981 if (phone != null) {
982 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
983 request.workSource);
984 } else {
985 loge("enableNrDualConnectivity: No phone object");
986 request.result =
987 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
988 notifyRequester(request);
989 }
990 break;
991 }
992
993 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 if (ar.exception == null) {
997 request.result =
998 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
999 } else {
1000 request.result =
1001 TelephonyManager
1002 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1003 if (ar.exception instanceof CommandException) {
1004 CommandException.Error error =
1005 ((CommandException) (ar.exception)).getCommandError();
1006 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1007 request.result =
1008 TelephonyManager
1009 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001010 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1011 request.result =
1012 TelephonyManager
1013 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001014 }
1015 loge("enableNrDualConnectivity" + ": CommandException: "
1016 + ar.exception);
1017 } else {
1018 loge("enableNrDualConnectivity" + ": Unknown exception");
1019 }
1020 }
1021 notifyRequester(request);
1022 break;
1023 }
1024
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001025 case CMD_ENABLE_VONR: {
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1028 Phone phone = getPhoneFromRequest(request);
1029 if (phone != null) {
1030 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1031 request.workSource);
1032 } else {
1033 loge("setVoNrEnabled: No phone object");
1034 request.result =
1035 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1036 notifyRequester(request);
1037 }
1038 break;
1039 }
1040
1041 case EVENT_ENABLE_VONR_DONE: {
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 if (ar.exception == null) {
1045 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1046 } else {
1047 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1048 if (ar.exception instanceof CommandException) {
1049 CommandException.Error error =
1050 ((CommandException) (ar.exception)).getCommandError();
1051 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1052 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1053 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1054 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1055 } else {
1056 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1057 }
1058 loge("setVoNrEnabled" + ": CommandException: "
1059 + ar.exception);
1060 } else {
1061 loge("setVoNrEnabled" + ": Unknown exception");
1062 }
1063 }
1064 notifyRequester(request);
1065 break;
1066 }
1067
SongFerngWang3ef3e072020-12-21 16:41:52 +08001068 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001069 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001070 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1071 request);
1072 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001073 break;
1074
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
1078 if (ar.exception == null && ar.result != null) {
1079 request.result = ar.result; // Integer
1080 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301081 // request.result must be set to something non-null
1082 // for the calling thread to unblock
1083 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001084 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001085 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 loge("getAllowedNetworkTypesBitmask: CommandException: "
1088 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001089 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001090 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001091 }
1092 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001093 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 break;
1095
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001097 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001098 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1099 request);
1100 Pair<Integer, Long> reasonWithNetworkTypes =
1101 (Pair<Integer, Long>) request.argument;
1102 getPhoneFromRequest(request).setAllowedNetworkTypes(
1103 reasonWithNetworkTypes.first,
1104 reasonWithNetworkTypes.second,
1105 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 break;
1107
SongFerngWang3ef3e072020-12-21 16:41:52 +08001108 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1109 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 break;
1111
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001112 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1113 request = (MainThreadRequest)msg.obj;
1114 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001115 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001116 break;
1117
1118 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1119 ar = (AsyncResult)msg.obj;
1120 request = (MainThreadRequest)ar.userObj;
1121 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001122 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001123 break;
1124
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001125 case CMD_SET_VOICEMAIL_NUMBER:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1128 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001129 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1130 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001131 break;
1132
1133 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1134 handleNullReturnEvent(msg, "setVoicemailNumber");
1135 break;
1136
Stuart Scott54788802015-03-30 13:18:01 -07001137 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1140 request);
1141 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1142 break;
1143
1144 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1145 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1146 break;
1147
Shishir Agrawal302c8692015-06-19 13:49:39 -07001148 case CMD_PERFORM_NETWORK_SCAN:
1149 request = (MainThreadRequest) msg.obj;
1150 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1151 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1152 break;
1153
Hall Liu27d24262020-09-18 19:04:59 -07001154 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001157 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1158 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1159 request.argument;
1160 int callForwardingReason = args.first;
1161 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001162 break;
Hall Liu27d24262020-09-18 19:04:59 -07001163 }
1164 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001165 ar = (AsyncResult) msg.obj;
1166 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001167 TelephonyManager.CallForwardingInfoCallback callback =
1168 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1169 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001170 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001171 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001172 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1173 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1174 // Service Class is a bit mask per 3gpp 27.007. Search for
1175 // any service for voice call.
1176 if ((callForwardInfo.serviceClass
1177 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001178 callForwardingInfo = new CallForwardingInfo(
1179 callForwardInfo.status
1180 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001181 callForwardInfo.reason,
1182 callForwardInfo.number,
1183 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001184 break;
1185 }
1186 }
1187 // Didn't find a call forward info for voice call.
1188 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001189 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1190 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001191 }
Hall Liu27d24262020-09-18 19:04:59 -07001192 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001193 } else {
1194 if (ar.result == null) {
1195 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1196 }
1197 if (ar.exception != null) {
1198 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1199 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001200 int errorCode = TelephonyManager
1201 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 if (ar.exception instanceof CommandException) {
1203 CommandException.Error error =
1204 ((CommandException) (ar.exception)).getCommandError();
1205 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001206 errorCode = TelephonyManager
1207 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001209 errorCode = TelephonyManager
1210 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001211 }
1212 }
Hall Liu27d24262020-09-18 19:04:59 -07001213 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001214 }
Shuo Qian4a594052020-01-23 11:59:30 -08001215 break;
Hall Liu27d24262020-09-18 19:04:59 -07001216 }
Shuo Qian4a594052020-01-23 11:59:30 -08001217
Hall Liu27d24262020-09-18 19:04:59 -07001218 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001219 request = (MainThreadRequest) msg.obj;
1220 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001221 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001222 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001223 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1224 request.argument).first;
1225 request.phone.setCallForwardingOption(
1226 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001227 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001228 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001229 callForwardingInfoToSet.getReason(),
1230 callForwardingInfoToSet.getNumber(),
1231 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001238 Consumer<Integer> callback =
1239 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1240 request.argument).second;
1241 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001242 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001243 int errorCode = TelephonyManager.CallForwardingInfoCallback
1244 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001245 if (ar.exception instanceof CommandException) {
1246 CommandException.Error error =
1247 ((CommandException) (ar.exception)).getCommandError();
1248 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001249 errorCode = TelephonyManager.CallForwardingInfoCallback
1250 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001251 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001252 errorCode = TelephonyManager.CallForwardingInfoCallback
1253 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001254 }
1255 }
1256 callback.accept(errorCode);
1257 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001258 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260 break;
Hall Liu27d24262020-09-18 19:04:59 -07001261 }
Shuo Qian4a594052020-01-23 11:59:30 -08001262
Hall Liu27d24262020-09-18 19:04:59 -07001263 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001264 request = (MainThreadRequest) msg.obj;
1265 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1266 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1267 break;
Hall Liu27d24262020-09-18 19:04:59 -07001268 }
Shuo Qian4a594052020-01-23 11:59:30 -08001269
Hall Liu27d24262020-09-18 19:04:59 -07001270 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001271 ar = (AsyncResult) msg.obj;
1272 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001273 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001274 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001276 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 // Service Class is a bit mask per 3gpp 27.007.
1278 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001279 if (callForwardResults.length > 1
1280 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001281 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001282 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001283 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1284 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001285 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001286 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001287 }
1288 } else {
1289 if (ar.result == null) {
1290 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1291 }
1292 if (ar.exception != null) {
1293 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1294 }
1295 if (ar.exception instanceof CommandException) {
1296 CommandException.Error error =
1297 ((CommandException) (ar.exception)).getCommandError();
1298 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001299 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001300 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001301 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1302 callWaitingStatus =
1303 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001304 }
1305 }
1306 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001307 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001308 break;
Hall Liu27d24262020-09-18 19:04:59 -07001309 }
Shuo Qian4a594052020-01-23 11:59:30 -08001310
Hall Liu27d24262020-09-18 19:04:59 -07001311 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001312 request = (MainThreadRequest) msg.obj;
1313 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001314 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1315 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001316 break;
Hall Liu27d24262020-09-18 19:04:59 -07001317 }
Shuo Qian4a594052020-01-23 11:59:30 -08001318
Hall Liu27d24262020-09-18 19:04:59 -07001319 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001320 ar = (AsyncResult) msg.obj;
1321 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001322 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1323 Consumer<Integer> callback =
1324 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1325 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001326 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001327 if (ar.exception instanceof CommandException) {
1328 CommandException.Error error =
1329 ((CommandException) (ar.exception)).getCommandError();
1330 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1331 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1333 callback.accept(
1334 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001335 } else {
1336 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1337 }
1338 } else {
1339 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1340 }
1341 } else {
1342 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1343 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001344 }
Shuo Qian4a594052020-01-23 11:59:30 -08001345 break;
Hall Liu27d24262020-09-18 19:04:59 -07001346 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001347 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1348 ar = (AsyncResult) msg.obj;
1349 request = (MainThreadRequest) ar.userObj;
1350 CellNetworkScanResult cellScanResult;
1351 if (ar.exception == null && ar.result != null) {
1352 cellScanResult = new CellNetworkScanResult(
1353 CellNetworkScanResult.STATUS_SUCCESS,
1354 (List<OperatorInfo>) ar.result);
1355 } else {
1356 if (ar.result == null) {
1357 loge("getCellNetworkScanResults: Empty response");
1358 }
1359 if (ar.exception != null) {
1360 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1361 }
1362 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1363 if (ar.exception instanceof CommandException) {
1364 CommandException.Error error =
1365 ((CommandException) (ar.exception)).getCommandError();
1366 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1367 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1368 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1369 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1370 }
1371 }
1372 cellScanResult = new CellNetworkScanResult(errorCode, null);
1373 }
1374 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001375 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001376 break;
1377
1378 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1379 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001380 ManualNetworkSelectionArgument selArg =
1381 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001382 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1383 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001384 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1385 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001386 break;
1387
1388 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
1391 if (ar.exception == null) {
1392 request.result = true;
1393 } else {
1394 request.result = false;
1395 loge("setNetworkSelectionModeManual " + ar.exception);
1396 }
1397 notifyRequester(request);
1398 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001399 break;
1400
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001401 case CMD_GET_MODEM_ACTIVITY_INFO:
1402 request = (MainThreadRequest) msg.obj;
1403 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001404 if (defaultPhone != null) {
1405 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001406 } else {
1407 ResultReceiver result = (ResultReceiver) request.argument;
1408 Bundle bundle = new Bundle();
1409 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001410 new ModemActivityInfo(0, 0, 0,
1411 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001412 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001413 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001414 break;
1415
Hall Liud0f208c2020-10-14 16:54:44 -07001416 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001419 ResultReceiver result = (ResultReceiver) request.argument;
1420
Hall Liud0f208c2020-10-14 16:54:44 -07001421 ModemActivityInfo ret = null;
1422 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001423 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001424 // Update the last modem activity info and the result of the request.
1425 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1426 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001427 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001428 int[] txTimeMs = info.getTransmitTimeMillis();
1429 int[] lastModemTxTimeMs = mLastModemActivityInfo
1430 .getTransmitTimeMillis();
1431 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1432 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1433 }
Hall Liu49656c02020-10-09 19:00:11 -07001434 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1436 + mLastModemActivityInfo.getSleepTimeMillis());
1437 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1438 + mLastModemActivityInfo.getIdleTimeMillis());
1439 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1440 mLastModemActivityInfo.setReceiveTimeMillis(
1441 info.getReceiveTimeMillis()
1442 + mLastModemActivityInfo.getReceiveTimeMillis());
1443 }
Hall Liu49656c02020-10-09 19:00:11 -07001444 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001445 mLastModemActivityInfo.getSleepTimeMillis(),
1446 mLastModemActivityInfo.getIdleTimeMillis(),
1447 mLastModemActivityInfo.getTransmitTimeMillis(),
1448 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001449 } else {
1450 if (ar.result == null) {
1451 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001452 error = TelephonyManager.ModemActivityInfoException
1453 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001454 } else if (ar.exception instanceof CommandException) {
1455 loge("queryModemActivityInfo: CommandException: " +
1456 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001457 error = TelephonyManager.ModemActivityInfoException
1458 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 } else {
1460 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001461 error = TelephonyManager.ModemActivityInfoException
1462 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 }
1464 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001466 if (ret != null) {
1467 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1468 } else {
1469 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1470 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001472 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001474 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475
Meng Wang1a7c35a2016-05-05 20:56:15 -07001476 case CMD_SET_ALLOWED_CARRIERS:
1477 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001478 CarrierRestrictionRules argument =
1479 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001480 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001481 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001482 break;
1483
1484 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1485 ar = (AsyncResult) msg.obj;
1486 request = (MainThreadRequest) ar.userObj;
1487 if (ar.exception == null && ar.result != null) {
1488 request.result = ar.result;
1489 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001490 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1491 if (ar.exception instanceof CommandException) {
1492 loge("setAllowedCarriers: CommandException: " + ar.exception);
1493 CommandException.Error error =
1494 ((CommandException) (ar.exception)).getCommandError();
1495 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1496 request.result =
1497 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1498 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 } else {
1500 loge("setAllowedCarriers: Unknown exception");
1501 }
1502 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 break;
1505
1506 case CMD_GET_ALLOWED_CARRIERS:
1507 request = (MainThreadRequest) msg.obj;
1508 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001509 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001510 break;
1511
1512 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1513 ar = (AsyncResult) msg.obj;
1514 request = (MainThreadRequest) ar.userObj;
1515 if (ar.exception == null && ar.result != null) {
1516 request.result = ar.result;
1517 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001518 request.result = new IllegalStateException(
1519 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001520 if (ar.result == null) {
1521 loge("getAllowedCarriers: Empty response");
1522 } else if (ar.exception instanceof CommandException) {
1523 loge("getAllowedCarriers: CommandException: " +
1524 ar.exception);
1525 } else {
1526 loge("getAllowedCarriers: Unknown exception");
1527 }
1528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001529 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001530 break;
1531
Nathan Haroldb3014052017-01-25 15:57:32 -08001532 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 if (ar.exception == null && ar.result != null) {
1536 request.result = ar.result;
1537 } else {
1538 request.result = new IllegalArgumentException(
1539 "Failed to retrieve Forbidden Plmns");
1540 if (ar.result == null) {
1541 loge("getForbiddenPlmns: Empty response");
1542 } else {
1543 loge("getForbiddenPlmns: Unknown exception");
1544 }
1545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001546 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 break;
1548
1549 case CMD_GET_FORBIDDEN_PLMNS:
1550 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001551 uiccPort = getUiccPortFromRequest(request);
1552 if (uiccPort == null) {
1553 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001554 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001555 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001556 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001557 break;
1558 }
1559 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001560 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001561 if (uiccApp == null) {
1562 loge("getForbiddenPlmns() no app with specified type -- "
1563 + appType);
1564 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001565 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001566 break;
1567 } else {
1568 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1569 + " specified type -- " + appType);
1570 }
1571 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1572 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1573 onCompleted);
1574 break;
1575
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001576 case CMD_SWITCH_SLOTS:
1577 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001578 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001579 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001580 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001581 break;
1582
1583 case EVENT_SWITCH_SLOTS_DONE:
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
1586 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001587 notifyRequester(request);
1588 break;
1589 case CMD_GET_NETWORK_SELECTION_MODE:
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1592 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1593 break;
1594
1595 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1596 ar = (AsyncResult) msg.obj;
1597 request = (MainThreadRequest) ar.userObj;
1598 if (ar.exception != null) {
1599 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1600 } else {
1601 int mode = ((int[]) ar.result)[0];
1602 if (mode == 0) {
1603 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1604 } else {
1605 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1606 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001608 notifyRequester(request);
1609 break;
1610 case CMD_GET_CDMA_ROAMING_MODE:
1611 request = (MainThreadRequest) msg.obj;
1612 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1613 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1614 break;
1615 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 if (ar.exception != null) {
1619 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1620 } else {
1621 request.result = ((int[]) ar.result)[0];
1622 }
1623 notifyRequester(request);
1624 break;
1625 case CMD_SET_CDMA_ROAMING_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1628 int mode = (int) request.argument;
1629 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1630 break;
1631 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 request.result = ar.exception == null;
1635 notifyRequester(request);
1636 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001637 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1638 request = (MainThreadRequest) msg.obj;
1639 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1640 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1641 break;
1642 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1643 ar = (AsyncResult) msg.obj;
1644 request = (MainThreadRequest) ar.userObj;
1645 if (ar.exception != null) {
1646 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1647 } else {
1648 request.result = ((int[]) ar.result)[0];
1649 }
1650 notifyRequester(request);
1651 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001652 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1653 request = (MainThreadRequest) msg.obj;
1654 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1655 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001656 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1657 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001658 break;
1659 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 request.result = ar.exception == null;
1663 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001664 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001665 case CMD_GET_ALL_CELL_INFO:
1666 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001667 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001668 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001669 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001670 case EVENT_GET_ALL_CELL_INFO_DONE:
1671 ar = (AsyncResult) msg.obj;
1672 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001673 // If a timeout occurs, the response will be null
1674 request.result = (ar.exception == null && ar.result != null)
1675 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001676 synchronized (request) {
1677 request.notifyAll();
1678 }
1679 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001680 case CMD_REQUEST_CELL_INFO_UPDATE:
1681 request = (MainThreadRequest) msg.obj;
1682 request.phone.requestCellInfoUpdate(request.workSource,
1683 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1684 break;
1685 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1689 try {
1690 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001692 cb.onError(
1693 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1694 ar.exception.getClass().getName(),
1695 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001696 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001697 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001698 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001699 } else {
1700 // use the result as returned
1701 cb.onCellInfo((List<CellInfo>) ar.result);
1702 }
1703 } catch (RemoteException re) {
1704 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1705 }
1706 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001707 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001708 request = (MainThreadRequest) msg.obj;
1709 WorkSource ws = (WorkSource) request.argument;
1710 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001711 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001712 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001713 }
1714 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001715 ar = (AsyncResult) msg.obj;
1716 request = (MainThreadRequest) ar.userObj;
1717 if (ar.exception == null) {
1718 request.result = ar.result;
1719 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001720 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001721 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001722 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001723 }
1724
1725 synchronized (request) {
1726 request.notifyAll();
1727 }
1728 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001729 }
chen xu6dac5ab2018-10-26 17:39:23 -07001730 case CMD_MODEM_REBOOT:
1731 request = (MainThreadRequest) msg.obj;
1732 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001733 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001734 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001735 case EVENT_CMD_MODEM_REBOOT_DONE:
1736 handleNullReturnEvent(msg, "rebootModem");
1737 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001738 case CMD_REQUEST_ENABLE_MODEM:
1739 request = (MainThreadRequest) msg.obj;
1740 boolean enable = (boolean) request.argument;
1741 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001742 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001743 PhoneConfigurationManager.getInstance()
1744 .enablePhone(request.phone, enable, onCompleted);
1745 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001746 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001747 ar = (AsyncResult) msg.obj;
1748 request = (MainThreadRequest) ar.userObj;
1749 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001750 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001751 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001752 if ((boolean) request.result) {
1753 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1754 updateModemStateMetrics();
1755 } else {
1756 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1757 + ar.exception);
1758 }
1759 notifyRequester(request);
1760 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001761 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001762 case CMD_GET_MODEM_STATUS:
1763 request = (MainThreadRequest) msg.obj;
1764 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1765 PhoneConfigurationManager.getInstance()
1766 .getPhoneStatusFromModem(request.phone, onCompleted);
1767 break;
1768 case EVENT_GET_MODEM_STATUS_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
1771 int id = request.phone.getPhoneId();
1772 if (ar.exception == null && ar.result != null) {
1773 request.result = ar.result;
1774 //update the cache as modem status has changed
1775 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1776 (boolean) request.result);
1777 } else {
1778 // Return true if modem status cannot be retrieved. For most cases,
1779 // modem status is on. And for older version modems, GET_MODEM_STATUS
1780 // and disable modem are not supported. Modem is always on.
1781 // TODO: this should be fixed in R to support a third
1782 // status UNKNOWN b/131631629
1783 request.result = true;
1784 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1785 + ar.exception);
1786 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001787 notifyRequester(request);
1788 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001789 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1790 request = (MainThreadRequest) msg.obj;
1791 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1792 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1793 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1794 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1795 break;
1796 }
1797 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1798 ar = (AsyncResult) msg.obj;
1799 request = (MainThreadRequest) ar.userObj;
1800 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1801 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1802 args.second.accept(ar.exception == null);
1803 notifyRequester(request);
1804 break;
1805 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001806 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1807 request = (MainThreadRequest) msg.obj;
1808 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1809 Phone phone = getPhoneFromRequest(request);
1810 if (phone != null) {
1811 phone.getSystemSelectionChannels(onCompleted);
1812 } else {
1813 loge("getSystemSelectionChannels: No phone object");
1814 request.result = new ArrayList<RadioAccessSpecifier>();
1815 notifyRequester(request);
1816 }
1817 break;
1818 }
1819 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1820 ar = (AsyncResult) msg.obj;
1821 request = (MainThreadRequest) ar.userObj;
1822 if (ar.exception == null && ar.result != null) {
1823 request.result = ar.result;
1824 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001825 request.result = new IllegalStateException(
1826 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001827 if (ar.result == null) {
1828 loge("getSystemSelectionChannels: Empty response");
1829 } else {
1830 loge("getSystemSelectionChannels: Unknown exception");
1831 }
1832 }
1833 notifyRequester(request);
1834 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001835 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 if (ar.exception == null && ar.result != null) {
1839 request.result = ar.result;
1840 } else {
1841 request.result = -1;
1842 loge("Failed to set Forbidden Plmns");
1843 if (ar.result == null) {
1844 loge("setForbidenPlmns: Empty response");
1845 } else if (ar.exception != null) {
1846 loge("setForbiddenPlmns: Exception: " + ar.exception);
1847 request.result = -1;
1848 } else {
1849 loge("setForbiddenPlmns: Unknown exception");
1850 }
1851 }
1852 notifyRequester(request);
1853 break;
1854 case CMD_SET_FORBIDDEN_PLMNS:
1855 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001856 uiccPort = getUiccPortFromRequest(request);
1857 if (uiccPort == null) {
1858 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001859 request.result = -1;
1860 notifyRequester(request);
1861 break;
1862 }
1863 Pair<Integer, List<String>> setFplmnsArgs =
1864 (Pair<Integer, List<String>>) request.argument;
1865 appType = setFplmnsArgs.first;
1866 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001867 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001868 if (uiccApp == null) {
1869 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1870 request.result = -1;
1871 loge("Failed to get UICC App");
1872 notifyRequester(request);
1873 } else {
1874 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1875 ((SIMRecords) uiccApp.getIccRecords())
1876 .setForbiddenPlmns(onCompleted, fplmns);
1877 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001878 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001879 case CMD_ERASE_MODEM_CONFIG:
1880 request = (MainThreadRequest) msg.obj;
1881 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1882 defaultPhone.eraseModemConfig(onCompleted);
1883 break;
1884 case EVENT_ERASE_MODEM_CONFIG_DONE:
1885 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001886 break;
zoey chene02881a2019-12-30 16:11:23 +08001887
Kai Shif70f46f2021-03-03 13:59:46 -08001888 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1889 request = (MainThreadRequest) msg.obj;
1890 request.result = defaultPhone.eraseDataInSharedPreferences();
1891 notifyRequester(request);
1892 break;
1893
zoey chene02881a2019-12-30 16:11:23 +08001894 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1897 Pair<String, String> changed = (Pair<String, String>) request.argument;
1898 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1899 changed.first, changed.second, onCompleted);
1900 break;
1901 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1902 ar = (AsyncResult) msg.obj;
1903 request = (MainThreadRequest) ar.userObj;
1904 if (ar.exception == null) {
1905 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001906 // If the operation is successful, update the PIN storage
1907 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1908 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001909 UiccController.getInstance().getPinStorage()
1910 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001911 } else {
1912 request.result = msg.arg1;
1913 }
1914 notifyRequester(request);
1915 break;
1916
Michele Berionne5e411512020-11-13 02:36:59 +00001917 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001918 request = (MainThreadRequest) msg.obj;
1919 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1920 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1921 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1922 enabled.first, enabled.second, onCompleted);
1923 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001924 }
zoey chene02881a2019-12-30 16:11:23 +08001925 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1926 ar = (AsyncResult) msg.obj;
1927 request = (MainThreadRequest) ar.userObj;
1928 if (ar.exception == null) {
1929 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001930 // If the operation is successful, update the PIN storage
1931 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1932 int phoneId = getPhoneFromRequest(request).getPhoneId();
1933 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001934 UiccController.getInstance().getPinStorage()
1935 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001936 } else {
1937 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1938 }
zoey chene02881a2019-12-30 16:11:23 +08001939 } else {
1940 request.result = msg.arg1;
1941 }
Michele Berionne5e411512020-11-13 02:36:59 +00001942
1943
zoey chene02881a2019-12-30 16:11:23 +08001944 notifyRequester(request);
1945 break;
1946
Peter Wangdafb9ac2020-01-15 14:13:38 -08001947 case MSG_NOTIFY_USER_ACTIVITY:
1948 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001949 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001950 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1951 getDefaultPhone().getContext().sendBroadcastAsUser(
1952 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1953 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001954
1955 case CMD_SET_DATA_THROTTLING: {
1956 request = (MainThreadRequest) msg.obj;
1957 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1958 DataThrottlingRequest dataThrottlingRequest =
1959 (DataThrottlingRequest) request.argument;
1960 Phone phone = getPhoneFromRequest(request);
1961 if (phone != null) {
1962 phone.setDataThrottling(onCompleted,
1963 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1964 dataThrottlingRequest.getCompletionDurationMillis());
1965 } else {
1966 loge("setDataThrottling: No phone object");
1967 request.result =
1968 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1969 notifyRequester(request);
1970 }
1971
1972 break;
1973 }
1974 case EVENT_SET_DATA_THROTTLING_DONE:
1975 ar = (AsyncResult) msg.obj;
1976 request = (MainThreadRequest) ar.userObj;
1977
1978 if (ar.exception == null) {
1979 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1980 } else if (ar.exception instanceof CommandException) {
1981 loge("setDataThrottling: CommandException: " + ar.exception);
1982 CommandException.Error error =
1983 ((CommandException) (ar.exception)).getCommandError();
1984
1985 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1986 request.result = TelephonyManager
1987 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1988 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1989 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001990 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1991 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001992 } else {
1993 request.result =
1994 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1995 }
1996 } else {
1997 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1998 }
1999 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2000 notifyRequester(request);
2001 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002002
2003 case CMD_SET_SIM_POWER: {
2004 request = (MainThreadRequest) msg.obj;
2005 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2006 request = (MainThreadRequest) msg.obj;
2007 int stateToSet =
2008 ((Pair<Integer, IIntegerConsumer>)
2009 request.argument).first;
2010 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2011 break;
2012 }
2013 case EVENT_SET_SIM_POWER_DONE: {
2014 ar = (AsyncResult) msg.obj;
2015 request = (MainThreadRequest) ar.userObj;
2016 IIntegerConsumer callback =
2017 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2018 if (ar.exception != null) {
2019 loge("setSimPower exception: " + ar.exception);
2020 int errorCode = TelephonyManager.CallForwardingInfoCallback
2021 .RESULT_ERROR_UNKNOWN;
2022 if (ar.exception instanceof CommandException) {
2023 CommandException.Error error =
2024 ((CommandException) (ar.exception)).getCommandError();
2025 if (error == CommandException.Error.SIM_ERR) {
2026 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2027 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2028 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2029 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2030 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2031 } else {
2032 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2033 }
2034 }
2035 try {
2036 callback.accept(errorCode);
2037 } catch (RemoteException e) {
2038 // Ignore if the remote process is no longer available to call back.
2039 Log.w(LOG_TAG, "setSimPower: callback not available.");
2040 }
2041 } else {
2042 try {
2043 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2044 } catch (RemoteException e) {
2045 // Ignore if the remote process is no longer available to call back.
2046 Log.w(LOG_TAG, "setSimPower: callback not available.");
2047 }
2048 }
2049 break;
2050 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002051 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2052 request = (MainThreadRequest) msg.obj;
2053
2054 final Phone phone = getPhoneFromRequest(request);
2055 if (phone == null || phone.getServiceStateTracker() == null) {
2056 request.result = new IllegalStateException("Phone or SST is null");
2057 notifyRequester(request);
2058 break;
2059 }
2060
2061 Pair<Integer, SignalStrengthUpdateRequest> pair =
2062 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2063 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2064 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002065 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002066 request.subId, pair.first /*callingUid*/,
2067 pair.second /*request*/, onCompleted);
2068 break;
2069 }
2070 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2071 ar = (AsyncResult) msg.obj;
2072 request = (MainThreadRequest) ar.userObj;
2073 // request.result will be the exception of ar if present, true otherwise.
2074 // Be cautious not to leave result null which will wait() forever
2075 request.result = ar.exception != null ? ar.exception : true;
2076 notifyRequester(request);
2077 break;
2078 }
2079 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2080 request = (MainThreadRequest) msg.obj;
2081
2082 Phone phone = getPhoneFromRequest(request);
2083 if (phone == null || phone.getServiceStateTracker() == null) {
2084 request.result = new IllegalStateException("Phone or SST is null");
2085 notifyRequester(request);
2086 break;
2087 }
2088
2089 Pair<Integer, SignalStrengthUpdateRequest> pair =
2090 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2091 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2092 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002093 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002094 request.subId, pair.first /*callingUid*/,
2095 pair.second /*request*/, onCompleted);
2096 break;
2097 }
2098 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2099 ar = (AsyncResult) msg.obj;
2100 request = (MainThreadRequest) ar.userObj;
2101 request.result = ar.exception != null ? ar.exception : true;
2102 notifyRequester(request);
2103 break;
2104 }
Jordan Liu109698e2020-11-24 14:50:34 -08002105
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002106 case CMD_GET_SLICING_CONFIG: {
2107 request = (MainThreadRequest) msg.obj;
2108 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2109 request.phone.getSlicingConfig(onCompleted);
2110 break;
2111 }
2112 case EVENT_GET_SLICING_CONFIG_DONE: {
2113 ar = (AsyncResult) msg.obj;
2114 request = (MainThreadRequest) ar.userObj;
2115 ResultReceiver result = (ResultReceiver) request.argument;
2116
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002117 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002118 Bundle bundle = new Bundle();
2119 int resultCode = 0;
2120 if (ar.exception != null) {
2121 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2122 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002124 } else if (ar.result == null) {
2125 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002126 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002127 } else {
2128 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002129 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2130 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002131 }
2132
2133 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002134 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002135 }
2136 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2137 result.send(resultCode, bundle);
2138 notifyRequester(request);
2139 break;
2140 }
2141
Michele Berionne5e411512020-11-13 02:36:59 +00002142 case CMD_PREPARE_UNATTENDED_REBOOT:
2143 request = (MainThreadRequest) msg.obj;
2144 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002145 UiccController.getInstance().getPinStorage()
2146 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002147 notifyRequester(request);
2148 break;
2149
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 default:
2151 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2152 break;
2153 }
2154 }
Jake Hambye994d462014-02-03 13:10:13 -08002155
Pengquan Menga1bb6272018-09-06 09:59:22 -07002156 private void notifyRequester(MainThreadRequest request) {
2157 synchronized (request) {
2158 request.notifyAll();
2159 }
2160 }
2161
Jake Hambye994d462014-02-03 13:10:13 -08002162 private void handleNullReturnEvent(Message msg, String command) {
2163 AsyncResult ar = (AsyncResult) msg.obj;
2164 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2165 if (ar.exception == null) {
2166 request.result = true;
2167 } else {
2168 request.result = false;
2169 if (ar.exception instanceof CommandException) {
2170 loge(command + ": CommandException: " + ar.exception);
2171 } else {
2172 loge(command + ": Unknown exception");
2173 }
2174 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002175 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 }
2178
2179 /**
2180 * Posts the specified command to be executed on the main thread,
2181 * waits for the request to complete, and returns the result.
2182 * @see #sendRequestAsync
2183 */
2184 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002185 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2186 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002187 }
2188
2189 /**
2190 * Posts the specified command to be executed on the main thread,
2191 * waits for the request to complete, and returns the result.
2192 * @see #sendRequestAsync
2193 */
2194 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2195 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002196 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002197 }
2198
2199 /**
2200 * Posts the specified command to be executed on the main thread,
2201 * waits for the request to complete, and returns the result.
2202 * @see #sendRequestAsync
2203 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002204 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002205 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2206 }
2207
2208 /**
2209 * Posts the specified command to be executed on the main thread,
2210 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2211 * if not timeout or null otherwise.
2212 * @see #sendRequestAsync
2213 */
2214 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2215 long timeoutInMs) {
2216 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002217 }
2218
2219 /**
2220 * Posts the specified command to be executed on the main thread,
2221 * waits for the request to complete, and returns the result.
2222 * @see #sendRequestAsync
2223 */
Nathan Harold92bed182018-10-12 18:16:49 -07002224 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002225 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002226 }
2227
2228 /**
2229 * Posts the specified command to be executed on the main thread,
2230 * waits for the request to complete, and returns the result.
2231 * @see #sendRequestAsync
2232 */
2233 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002234 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2235 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002236 }
2237
2238 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002239 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2240 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2241 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002242 * @see #sendRequestAsync
2243 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002244 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2245 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2247 throw new RuntimeException("This method will deadlock if called from the main thread.");
2248 }
2249
Nathan Harold92bed182018-10-12 18:16:49 -07002250 MainThreadRequest request = null;
2251 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2252 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2253 } else if (phone != null) {
2254 request = new MainThreadRequest(argument, phone, workSource);
2255 } else {
2256 request = new MainThreadRequest(argument, subId, workSource);
2257 }
2258
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 Message msg = mMainThreadHandler.obtainMessage(command, request);
2260 msg.sendToTarget();
2261
Rambo Wang0f050d82021-02-12 11:43:36 -08002262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002264 if (timeoutInMs >= 0) {
2265 // Wait for at least timeoutInMs before returning null request result
2266 long now = SystemClock.elapsedRealtime();
2267 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002268 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002269 try {
2270 request.wait(deadline - now);
2271 } catch (InterruptedException e) {
2272 // Do nothing, go back and check if request is completed or timeout
2273 } finally {
2274 now = SystemClock.elapsedRealtime();
2275 }
2276 }
2277 } else {
2278 // Wait for the request to complete
2279 while (request.result == null) {
2280 try {
2281 request.wait();
2282 } catch (InterruptedException e) {
2283 // Do nothing, go back and wait until the request is complete
2284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286 }
2287 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002288 if (request.result == null) {
2289 Log.wtf(LOG_TAG,
2290 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 return request.result;
2293 }
2294
2295 /**
2296 * Asynchronous ("fire and forget") version of sendRequest():
2297 * Posts the specified command to be executed on the main thread, and
2298 * returns immediately.
2299 * @see #sendRequest
2300 */
2301 private void sendRequestAsync(int command) {
2302 mMainThreadHandler.sendEmptyMessage(command);
2303 }
2304
2305 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002306 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002307 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002308 */
2309 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002310 sendRequestAsync(command, argument, null, null);
2311 }
2312
2313 /**
2314 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2315 * @see {@link #sendRequest(int,Object)}
2316 */
2317 private void sendRequestAsync(
2318 int command, Object argument, Phone phone, WorkSource workSource) {
2319 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002320 Message msg = mMainThreadHandler.obtainMessage(command, request);
2321 msg.sendToTarget();
2322 }
2323
2324 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 * Initialize the singleton PhoneInterfaceManager instance.
2326 * This is only done once, at startup, from PhoneApp.onCreate().
2327 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002328 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 synchronized (PhoneInterfaceManager.class) {
2330 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 } else {
2333 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2334 }
2335 return sInstance;
2336 }
2337 }
2338
2339 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002340 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002343 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002344 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002346 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002348 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002349 mTelephonySharedPreferences =
2350 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002351 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002352 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002353 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002354 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002355
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 publish();
2357 }
2358
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002359 private Phone getDefaultPhone() {
2360 Phone thePhone = getPhone(getDefaultSubscription());
2361 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2362 }
2363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 private void publish() {
2365 if (DBG) log("publish: " + this);
2366
Peter Wangc035ce42020-01-08 21:00:22 -08002367 TelephonyFrameworkInitializer
2368 .getTelephonyServiceManager()
2369 .getTelephonyServiceRegisterer()
2370 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
Stuart Scott584921c2015-01-15 17:10:34 -08002373 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002374 if (request.phone != null) {
2375 return request.phone;
2376 } else {
2377 return getPhoneFromSubId(request.subId);
2378 }
2379 }
2380
2381 private Phone getPhoneFromSubId(int subId) {
2382 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2383 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002384 }
2385
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002386 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 Phone phone = getPhoneFromRequest(request);
2388 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002389 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002390 }
2391
Wink Saville36469e72014-06-11 15:17:00 -07002392 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002393 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002394 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396
Kai Shif70f46f2021-03-03 13:59:46 -08002397 private void sendEraseModemConfig(@NonNull Phone phone) {
2398 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2399 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2400 }
2401
2402 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2403 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2404 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002405 }
2406
Peter Wang44b186e2020-01-13 23:33:09 -08002407 private boolean isImsAvailableOnDevice() {
2408 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2409 if (pm == null) {
2410 // For some reason package manger is not available.. This will fail internally anyway,
2411 // so do not throw error and allow.
2412 return true;
2413 }
2414 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2415 }
2416
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002418 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002419 }
2420
Wink Savilleb564aae2014-10-23 10:18:09 -07002421 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 if (DBG) log("dial: " + number);
2423 // No permission check needed here: This is just a wrapper around the
2424 // ACTION_DIAL intent, which is available to any app since it puts up
2425 // the UI before it does anything.
2426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 String url = createTelUrl(number);
2430 if (url == null) {
2431 return;
2432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 // PENDING: should we just silently fail if phone is offhook or ringing?
2435 PhoneConstants.State state = mCM.getState(subId);
2436 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2437 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2438 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2439 mApp.startActivity(intent);
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444 }
2445
2446 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002447 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002448 }
2449
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 if (DBG) log("call: " + number);
2452
2453 // This is just a wrapper around the ACTION_CALL intent, but we still
2454 // need to do a permission check since we're calling startActivity()
2455 // from the context of the phone app.
2456 enforceCallPermission();
2457
Jordan Liu1617b712019-07-10 15:06:26 -07002458 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 != AppOpsManager.MODE_ALLOWED) {
2460 return;
2461 }
2462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 String url = createTelUrl(number);
2466 if (url == null) {
2467 return;
2468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 boolean isValid = false;
2471 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2472 if (slist != null) {
2473 for (SubscriptionInfo subInfoRecord : slist) {
2474 if (subInfoRecord.getSubscriptionId() == subId) {
2475 isValid = true;
2476 break;
2477 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002478 }
Wink Saville08874612014-08-31 19:19:58 -07002479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 if (!isValid) {
2481 return;
2482 }
Wink Saville08874612014-08-31 19:19:58 -07002483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2485 intent.putExtra(SUBSCRIPTION_KEY, subId);
2486 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2487 mApp.startActivity(intent);
2488 } finally {
2489 Binder.restoreCallingIdentity(identity);
2490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
2492
Wink Savilleb564aae2014-10-23 10:18:09 -07002493 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002494 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002495 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2496 }
2497
Wink Savilleb564aae2014-10-23 10:18:09 -07002498 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002499 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002500 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2501 }
2502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002508 Phone phone = getPhone(subId);
2509 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 checkSimPin.start();
2511 return checkSimPin.unlockSim(null, pin);
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
Wink Savilleb564aae2014-10-23 10:18:09 -07002517 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002522 Phone phone = getPhone(subId);
2523 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 checkSimPuk.start();
2525 return checkSimPuk.unlockSim(puk, pin);
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
2528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 }
2530
2531 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002532 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 * a synchronous one.
2534 */
2535 private static class UnlockSim extends Thread {
2536
2537 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002538 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
2540 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002541 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2542 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543
2544 // For replies from SimCard interface
2545 private Handler mHandler;
2546
2547 // For async handler to identify request type
2548 private static final int SUPPLY_PIN_COMPLETE = 100;
2549
Michele Berionne5e411512020-11-13 02:36:59 +00002550 UnlockSim(int phoneId, IccCard simCard) {
2551 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 mSimCard = simCard;
2553 }
2554
2555 @Override
2556 public void run() {
2557 Looper.prepare();
2558 synchronized (UnlockSim.this) {
2559 mHandler = new Handler() {
2560 @Override
2561 public void handleMessage(Message msg) {
2562 AsyncResult ar = (AsyncResult) msg.obj;
2563 switch (msg.what) {
2564 case SUPPLY_PIN_COMPLETE:
2565 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2566 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002567 mRetryCount = msg.arg1;
2568 if (ar.exception != null) {
2569 if (ar.exception instanceof CommandException &&
2570 ((CommandException)(ar.exception)).getCommandError()
2571 == CommandException.Error.PASSWORD_INCORRECT) {
2572 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002573 } //When UiccCardApp dispose,handle message and return exception
2574 else if (ar.exception instanceof CommandException &&
2575 ((CommandException) (ar.exception)).getCommandError()
2576 == CommandException.Error.ABORTED) {
2577 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002578 } else {
2579 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2580 }
2581 } else {
2582 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 mDone = true;
2585 UnlockSim.this.notifyAll();
2586 }
2587 break;
2588 }
2589 }
2590 };
2591 UnlockSim.this.notifyAll();
2592 }
2593 Looper.loop();
2594 }
2595
2596 /*
2597 * Use PIN or PUK to unlock SIM card
2598 *
2599 * If PUK is null, unlock SIM card with PIN
2600 *
2601 * If PUK is not null, unlock SIM card with PUK and set PIN code
2602 */
Wink Saville9de0f752013-10-22 19:04:03 -07002603 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604
2605 while (mHandler == null) {
2606 try {
2607 wait();
2608 } catch (InterruptedException e) {
2609 Thread.currentThread().interrupt();
2610 }
2611 }
2612 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2613
2614 if (puk == null) {
2615 mSimCard.supplyPin(pin, callback);
2616 } else {
2617 mSimCard.supplyPuk(puk, pin, callback);
2618 }
2619
2620 while (!mDone) {
2621 try {
2622 Log.d(LOG_TAG, "wait for done");
2623 wait();
2624 } catch (InterruptedException e) {
2625 // Restore the interrupted status
2626 Thread.currentThread().interrupt();
2627 }
2628 }
2629 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002630 int[] resultArray = new int[2];
2631 resultArray[0] = mResult;
2632 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002633
2634 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002635 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002636 }
2637
Wink Saville9de0f752013-10-22 19:04:03 -07002638 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 }
2640 }
2641
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002642 /**
2643 * This method has been removed due to privacy and stability concerns.
2644 */
2645 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002647 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2648 return;
Wink Saville36469e72014-06-11 15:17:00 -07002649 }
2650
Nathan Harold1f889d82020-06-04 17:05:26 -07002651 @Override
2652 public void updateServiceLocationWithPackageName(String callingPackage) {
2653 mApp.getSystemService(AppOpsManager.class)
2654 .checkPackage(Binder.getCallingUid(), callingPackage);
2655
Nathan Haroldf096d982020-11-18 17:18:06 -08002656 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002657 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2658 // Callers targeting S have no business invoking this method.
2659 return;
2660 }
2661
2662 LocationAccessPolicy.LocationPermissionResult locationResult =
2663 LocationAccessPolicy.checkLocationPermission(mApp,
2664 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2665 .setCallingPackage(callingPackage)
2666 .setCallingFeatureId(null)
2667 .setCallingPid(Binder.getCallingPid())
2668 .setCallingUid(Binder.getCallingUid())
2669 .setMethod("updateServiceLocation")
2670 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2671 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2672 .build());
2673 // Apps that lack location permission have no business calling this method;
2674 // however, because no permission was declared in the public API, denials must
2675 // all be "soft".
2676 switch (locationResult) {
2677 case DENIED_HARD: /* fall through */
2678 case DENIED_SOFT:
2679 return;
2680 }
2681
2682 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002685 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002687 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002694 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002695 @Override
2696 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002697 return isRadioOnWithFeature(callingPackage, null);
2698 }
2699
2700
2701 @Override
2702 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2703 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2704 callingFeatureId);
2705 }
2706
2707 @Deprecated
2708 @Override
2709 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2710 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002714 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2715 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002717 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002718 return false;
2719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720
2721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 return isRadioOnForSubscriber(subId);
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002727 }
2728
2729 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 final Phone phone = getPhone(subId);
2733 if (phone != null) {
2734 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2735 } else {
2736 return false;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
2743 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
Wink Saville36469e72014-06-11 15:17:00 -07002746
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 final Phone phone = getPhone(subId);
2753 if (phone != null) {
2754 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
2761 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002762 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002763 }
2764
Wink Savilleb564aae2014-10-23 10:18:09 -07002765 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 final Phone phone = getPhone(subId);
2771 if (phone == null) {
2772 return false;
2773 }
2774 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2775 toggleRadioOnOffForSubscriber(subId);
2776 }
2777 return true;
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 }
Wink Saville36469e72014-06-11 15:17:00 -07002782
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002783 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002784 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 /*
2786 * If any of the Radios are available, it will need to be
2787 * shutdown. So return true if any Radio is available.
2788 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2792 Phone phone = PhoneFactory.getPhone(i);
2793 if (phone != null && phone.isRadioAvailable()) return true;
2794 }
2795 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2796 return false;
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002799 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 }
2801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002803 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 enforceModifyPermission();
2805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2809 logv("Shutting down Phone " + i);
2810 shutdownRadioUsingPhoneId(i);
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002814 }
2815 }
2816
2817 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002818 Phone phone = PhoneFactory.getPhone(phoneId);
2819 if (phone != null && phone.isRadioAvailable()) {
2820 phone.shutdownRadio();
2821 }
2822 }
2823
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2830 if (defaultPhone != null) {
2831 defaultPhone.setRadioPower(turnOn);
2832 return true;
2833 } else {
2834 loge("There's no default phone.");
2835 return false;
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002839 }
Wink Saville36469e72014-06-11 15:17:00 -07002840 }
2841
Wink Savilleb564aae2014-10-23 10:18:09 -07002842 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844
2845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 final Phone phone = getPhone(subId);
2848 if (phone != null) {
2849 phone.setRadioPower(turnOn);
2850 return true;
2851 } else {
2852 return false;
2853 }
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
2858
Wink Saville36469e72014-06-11 15:17:00 -07002859 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 public boolean enableDataConnectivity() {
2862 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 int subId = mSubscriptionController.getDefaultDataSubId();
2867 final Phone phone = getPhone(subId);
2868 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002869 if (phone.isUsingNewDataStack()) {
2870 phone.getDataSettingsManager().setDataEnabled(
2871 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2872 } else {
2873 phone.getDataEnabledSettings().setDataEnabled(
2874 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 return true;
2877 } else {
2878 return false;
2879 }
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
Wink Saville36469e72014-06-11 15:17:00 -07002885 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 public boolean disableDataConnectivity() {
2888 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 int subId = mSubscriptionController.getDefaultDataSubId();
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002895 if (phone.isUsingNewDataStack()) {
2896 phone.getDataSettingsManager().setDataEnabled(
2897 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2898 } else {
2899 phone.getDataEnabledSettings().setDataEnabled(
2900 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 return true;
2903 } else {
2904 return false;
2905 }
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 }
2910
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002912 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 final Phone phone = getPhone(subId);
2916 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002917 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 } else {
2919 return false;
2920 }
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 }
2925
2926 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002927 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002928 }
2929
pkanwarae03a6b2016-11-06 20:37:09 -08002930 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931 enforceCallPermission();
2932
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2936 return;
2937 }
2938 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2939 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
pkanwar32d516d2016-10-14 19:37:38 -07002943 };
2944
Wink Savilleb564aae2014-10-23 10:18:09 -07002945 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2951 return false;
2952 }
2953 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 }
2958
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002959 /**
2960 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2961 * tag on getCallState Binder call.
2962 */
2963 @Deprecated
2964 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002966 if (CompatChanges.isChangeEnabled(
2967 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2968 Binder.getCallingUid())) {
2969 // Do not allow this API to be called on API version 31+, it should only be
2970 // called on old apps using this Binder call directly.
2971 throw new SecurityException("This method can only be used for applications "
2972 + "targeting API version 30 or less.");
2973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002976 Phone phone = getPhone(getDefaultSubscription());
2977 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2978 PhoneConstantConversions.convertCallState(phone.getState());
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
2985 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2986 if (CompatChanges.isChangeEnabled(
2987 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2988 Binder.getCallingUid())) {
2989 // Check READ_PHONE_STATE for API version 31+
2990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2991 featureId, "getCallStateForSubscription")) {
2992 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2993 + "targeting API level 31+.");
2994 }
2995 }
2996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3000 PhoneConstantConversions.convertCallState(phone.getState());
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003004 }
3005
Sanket Padawe356d7632015-06-22 14:03:32 -07003006 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003007 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003008 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3009 }
3010
3011 @Override
3012 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003015 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003017 if (phone.isUsingNewDataStack()) {
3018 return phone.getDataNetworkController().getInternetDataNetworkState();
3019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3021 } else {
3022 return PhoneConstantConversions.convertDataState(
3023 PhoneConstants.DataState.DISCONNECTED);
3024 }
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 }
3029
Sanket Padawe356d7632015-06-22 14:03:32 -07003030 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003031 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003032 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3033 }
3034
3035 @Override
3036 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 final long identity = Binder.clearCallingIdentity();
3038 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003039 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 if (phone != null) {
3041 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3042 } else {
3043 return TelephonyManager.DATA_ACTIVITY_NONE;
3044 }
3045 } finally {
3046 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 }
3049
3050 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003051 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003052 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003053 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003054
3055 LocationAccessPolicy.LocationPermissionResult locationResult =
3056 LocationAccessPolicy.checkLocationPermission(mApp,
3057 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3058 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003059 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003060 .setCallingPid(Binder.getCallingPid())
3061 .setCallingUid(Binder.getCallingUid())
3062 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003063 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003064 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3065 .build());
3066 switch (locationResult) {
3067 case DENIED_HARD:
3068 throw new SecurityException("Not allowed to access cell location");
3069 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003070 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3071 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 }
3073
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003074 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003078 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003079 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
Svetoslav64fad262015-04-14 14:35:21 -07003083 }
3084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003086 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003087 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3088 // registered cell info, so return a NULL country instead.
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003091 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3092 // Get default phone in this case.
3093 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3094 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003095 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003097 if (phone == null) return "";
3098 ServiceStateTracker sst = phone.getServiceStateTracker();
3099 if (sst == null) return "";
3100 LocaleTracker lt = sst.getLocaleTracker();
3101 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003102 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003106 }
3107
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003108 /**
3109 * This method was removed due to potential issues caused by performing partial
3110 * updates of service state, and lack of a credible use case.
3111 *
3112 * This has the ability to break the telephony implementation by disabling notification of
3113 * changes in device connectivity. DO NOT USE THIS!
3114 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003115 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 public void enableLocationUpdates() {
3117 mApp.enforceCallingOrSelfPermission(
3118 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 }
3120
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003121 /**
3122 * This method was removed due to potential issues caused by performing partial
3123 * updates of service state, and lack of a credible use case.
3124 *
3125 * This has the ability to break the telephony implementation by disabling notification of
3126 * changes in device connectivity. DO NOT USE THIS!
3127 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 @Override
3129 public void disableLocationUpdates() {
3130 mApp.enforceCallingOrSelfPermission(
3131 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
3134 @Override
3135 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003136 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3137 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003138 try {
3139 mApp.getSystemService(AppOpsManager.class)
3140 .checkPackage(Binder.getCallingUid(), callingPackage);
3141 } catch (SecurityException e) {
3142 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3143 throw e;
3144 }
3145
Nathan Haroldf096d982020-11-18 17:18:06 -08003146 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003147 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3148 throw new SecurityException(
3149 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3150 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003151
Jordan Liu1617b712019-07-10 15:06:26 -07003152 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3154 return null;
3155 }
Svetoslav64fad262015-04-14 14:35:21 -07003156
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003157 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003159 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003160 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161
Nathan Haroldf180aac2018-06-01 18:43:55 -07003162 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3163 for (CellInfo ci : info) {
3164 if (ci instanceof CellInfoGsm) {
3165 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3166 } else if (ci instanceof CellInfoWcdma) {
3167 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003170 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 }
3172
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003173 private List<CellInfo> getCachedCellInfo() {
3174 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3175 for (Phone phone : PhoneFactory.getPhones()) {
3176 List<CellInfo> info = phone.getAllCellInfo();
3177 if (info != null) cellInfos.addAll(info);
3178 }
3179 return cellInfos;
3180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181
3182 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003183 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003184 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003185 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003186
3187 LocationAccessPolicy.LocationPermissionResult locationResult =
3188 LocationAccessPolicy.checkLocationPermission(mApp,
3189 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3190 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003191 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003192 .setCallingPid(Binder.getCallingPid())
3193 .setCallingUid(Binder.getCallingUid())
3194 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003195 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003196 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3197 .build());
3198 switch (locationResult) {
3199 case DENIED_HARD:
3200 throw new SecurityException("Not allowed to access cell info");
3201 case DENIED_SOFT:
3202 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204
Nathan Haroldf096d982020-11-18 17:18:06 -08003205 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003206 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3207 return getCachedCellInfo();
3208 }
3209
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003210 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3215 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003216 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003217 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 if (info != null) cellInfos.addAll(info);
3219 }
3220 return cellInfos;
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003223 }
3224 }
3225
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003226 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003227 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3228 String callingFeatureId) {
3229 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3230 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003231 }
3232
3233 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003234 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3235 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003236 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003237 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003238 }
3239
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003240 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3241 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003242 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003243 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003244
3245 LocationAccessPolicy.LocationPermissionResult locationResult =
3246 LocationAccessPolicy.checkLocationPermission(mApp,
3247 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3248 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003249 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003250 .setCallingPid(Binder.getCallingPid())
3251 .setCallingUid(Binder.getCallingUid())
3252 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003253 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3254 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003255 .build());
3256 switch (locationResult) {
3257 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003258 if (TelephonyPermissions
3259 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003260 // Safetynet logging for b/154934934
3261 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3262 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003263 throw new SecurityException("Not allowed to access cell info");
3264 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003265 if (TelephonyPermissions
3266 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003267 // Safetynet logging for b/154934934
3268 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3269 }
Nathan Harold5320c422019-05-09 10:26:08 -07003270 try {
3271 cb.onCellInfo(new ArrayList<CellInfo>());
3272 } catch (RemoteException re) {
3273 // Drop without consequences
3274 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003275 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003276 }
3277
Nathan Harolda939a962019-05-09 10:13:47 -07003278
3279 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003280 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3281
3282 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3283 }
3284
3285 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003287 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289
3290 final long identity = Binder.clearCallingIdentity();
3291 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003292 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296 }
3297
Shishir Agrawala9f32182016-04-12 12:00:16 -07003298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003299 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003300 Phone phone = PhoneFactory.getPhone(slotIndex);
3301 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003302 return null;
3303 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003304 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003305 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003306 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003307 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003308 return null;
3309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 return phone.getImei();
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003317 }
3318
3319 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003320 public String getTypeAllocationCodeForSlot(int slotIndex) {
3321 Phone phone = PhoneFactory.getPhone(slotIndex);
3322 String tac = null;
3323 if (phone != null) {
3324 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003325 try {
3326 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3327 } catch (IndexOutOfBoundsException e) {
3328 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3329 return null;
3330 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003331 }
3332 return tac;
3333 }
3334
3335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003336 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003337 try {
3338 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3339 } catch (SecurityException se) {
3340 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3341 throw new SecurityException("Package " + callingPackage + " does not belong to "
3342 + Binder.getCallingUid());
3343 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003344 Phone phone = PhoneFactory.getPhone(slotIndex);
3345 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003346 return null;
3347 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348
Jeff Davidson913390f2018-02-23 17:11:49 -08003349 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003350 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003351 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003352 return null;
3353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 return phone.getMeid();
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
Jack Yu2af8d712017-03-15 17:14:14 -07003361 }
3362
3363 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003364 public String getManufacturerCodeForSlot(int slotIndex) {
3365 Phone phone = PhoneFactory.getPhone(slotIndex);
3366 String manufacturerCode = null;
3367 if (phone != null) {
3368 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003369 try {
3370 manufacturerCode =
3371 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3372 } catch (IndexOutOfBoundsException e) {
3373 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3374 return null;
3375 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003376 }
3377 return manufacturerCode;
3378 }
3379
3380 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003381 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3382 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003383 Phone phone = PhoneFactory.getPhone(slotIndex);
3384 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003385 return null;
3386 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003387 int subId = phone.getSubId();
3388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003389 mApp, subId, callingPackage, callingFeatureId,
3390 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003391 return null;
3392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 return phone.getDeviceSvn();
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003400 }
3401
fionaxu43304da2017-11-27 22:51:16 -08003402 @Override
3403 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 final Phone phone = getPhone(subId);
3407 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
fionaxu43304da2017-11-27 22:51:16 -08003411 }
3412
3413 @Override
3414 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 final Phone phone = getPhone(subId);
3418 return phone == null ? null : phone.getCarrierName();
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
fionaxu43304da2017-11-27 22:51:16 -08003422 }
3423
calvinpanffe225e2018-11-01 19:43:06 +08003424 @Override
chen xu0026ca62019-03-06 15:28:50 -08003425 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 final Phone phone = getPhone(subId);
3429 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003430 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
3436 @Override
chen xu0026ca62019-03-06 15:28:50 -08003437 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003441 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
3446
chen xu651eec72018-11-11 19:03:44 -08003447 @Override
chen xu864e11c2018-12-06 22:10:03 -08003448 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3449 if (!isSubscriptionMccMnc) {
3450 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3451 }
chen xu651eec72018-11-11 19:03:44 -08003452 final Phone phone = PhoneFactory.getPhone(slotIndex);
3453 if (phone == null) {
3454 return TelephonyManager.UNKNOWN_CARRIER_ID;
3455 }
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
3462 }
3463
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003464 //
3465 // Internal helper methods.
3466 //
3467
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003468 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003469 * Make sure the caller is the calling package itself
3470 *
3471 * @throws SecurityException if the caller is not the calling package
3472 */
3473 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3474 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003475 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3476 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003477 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003478 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003479 } catch (PackageManager.NameNotFoundException e) {
3480 // packageUid is -1
3481 }
3482 if (packageUid != callingUid) {
3483 throw new SecurityException(message + ": Package " + callingPackage
3484 + " does not belong to " + callingUid);
3485 }
3486 }
3487
3488 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003489 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3490 *
3491 * @throws SecurityException if the caller does not have the required permission
3492 */
3493 private void enforceModifyPermission() {
3494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3495 }
3496
Shuo Qian3b6ee772019-11-13 17:43:31 -08003497 private void enforceActiveEmergencySessionPermission() {
3498 mApp.enforceCallingOrSelfPermission(
3499 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3500 }
3501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003502 /**
3503 * Make sure the caller has the CALL_PHONE permission.
3504 *
3505 * @throws SecurityException if the caller does not have the required permission
3506 */
3507 private void enforceCallPermission() {
3508 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3509 }
3510
paulhu5a773602019-08-23 19:17:33 +08003511 private void enforceSettingsPermission() {
3512 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003513 }
3514
Michele Berionne5e411512020-11-13 02:36:59 +00003515 private void enforceRebootPermission() {
3516 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3517 }
3518
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 private String createTelUrl(String number) {
3520 if (TextUtils.isEmpty(number)) {
3521 return null;
3522 }
3523
Jake Hambye994d462014-02-03 13:10:13 -08003524 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 }
3526
Ihab Awadf9e92732013-12-05 18:02:52 -08003527 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3529 }
3530
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003531 private static void logv(String msg) {
3532 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3533 }
3534
Ihab Awadf9e92732013-12-05 18:02:52 -08003535 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3537 }
3538
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003539 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003540 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003541 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003542 }
3543
Sanket Padawe356d7632015-06-22 14:03:32 -07003544 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003545 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 final Phone phone = PhoneFactory.getPhone(slotIndex);
3549 if (phone == null) {
3550 return PhoneConstants.PHONE_TYPE_NONE;
3551 } else {
3552 return phone.getPhoneType();
3553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003557 }
3558
3559 /**
3560 * Returns the CDMA ERI icon index to display
3561 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003562 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003563 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3564 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3565 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003566 }
3567
Sanket Padawe356d7632015-06-22 14:03:32 -07003568 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003569 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3570 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003572 mApp, subId, callingPackage, callingFeatureId,
3573 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003574 return -1;
3575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
3577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 final Phone phone = getPhone(subId);
3580 if (phone != null) {
3581 return phone.getCdmaEriIconIndex();
3582 } else {
3583 return -1;
3584 }
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003588 }
3589
3590 /**
3591 * Returns the CDMA ERI icon mode,
3592 * 0 - ON
3593 * 1 - FLASHING
3594 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003596 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3597 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3598 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003599 }
3600
Sanket Padawe356d7632015-06-22 14:03:32 -07003601 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003602 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3603 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003605 mApp, subId, callingPackage, callingFeatureId,
3606 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003607 return -1;
3608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 final Phone phone = getPhone(subId);
3613 if (phone != null) {
3614 return phone.getCdmaEriIconMode();
3615 } else {
3616 return -1;
3617 }
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003621 }
3622
3623 /**
3624 * Returns the CDMA ERI text,
3625 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003626 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003627 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3628 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3629 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003630 }
3631
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003633 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3634 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003636 mApp, subId, callingPackage, callingFeatureId,
3637 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003638 return null;
3639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640
3641 final long identity = Binder.clearCallingIdentity();
3642 try {
3643 final Phone phone = getPhone(subId);
3644 if (phone != null) {
3645 return phone.getCdmaEriText();
3646 } else {
3647 return null;
3648 }
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003652 }
3653
3654 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003655 * Returns the CDMA MDN.
3656 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003657 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003658 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3660 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003665 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 return phone.getLine1Number();
3667 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 return null;
3670 }
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003673 }
3674 }
3675
3676 /**
3677 * Returns the CDMA MIN.
3678 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003680 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3682 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 final Phone phone = getPhone(subId);
3687 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3688 return phone.getCdmaMin();
3689 } else {
3690 return null;
3691 }
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003694 }
3695 }
3696
Hall Liud892bec2018-11-30 14:51:45 -08003697 @Override
3698 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3699 INumberVerificationCallback callback, String callingPackage) {
3700 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3701 != PERMISSION_GRANTED) {
3702 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3703 }
3704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3705
3706 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3707 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003708 throw new SecurityException("Calling package must be configured in the device config: "
3709 + "calling package: " + callingPackage
3710 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003711 }
3712
3713 if (range == null) {
3714 throw new NullPointerException("Range must be non-null");
3715 }
3716
3717 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003718 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003719
3720 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3721 }
3722
Junda Liuca05d5d2014-08-14 22:36:34 -07003723 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003724 * Returns true if CDMA provisioning needs to run.
3725 */
3726 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 final long identity = Binder.clearCallingIdentity();
3728 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003729 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003733 }
3734
3735 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003736 * Sets the voice mail number of a given subId.
3737 */
3738 @Override
3739 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003740 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3741 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3746 new Pair<String, String>(alphaTag, number), new Integer(subId));
3747 return success;
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003751 }
3752
Ta-wei Yen87c49842016-05-13 21:19:52 -07003753 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003754 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003756 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3757 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003758 if (!TextUtils.equals(callingPackage, systemDialer)) {
3759 throw new SecurityException("caller must be system dialer");
3760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3765 if (phoneAccountHandle == null) {
3766 return null;
3767 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003768 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769 } finally {
3770 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003771 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003772 }
3773
3774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003775 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3776 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003779 mApp, subId, callingPackage, callingFeatureId,
3780 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003781 return null;
3782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003784 final long identity = Binder.clearCallingIdentity();
3785 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003786 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003790 }
3791
3792 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003793 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3794 VisualVoicemailSmsFilterSettings settings) {
3795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003800 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003804 }
3805
3806 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003807 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
3810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003813 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003817 }
3818
3819 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003820 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3821 String callingPackage, int subId) {
3822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823
3824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003827 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003831 }
3832
3833 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003834 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836
3837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003840 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841 } finally {
3842 Binder.restoreCallingIdentity(identity);
3843 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003844 }
3845
3846 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003847 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3848 String callingAttributionTag, int subId, String number, int port, String text,
3849 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003850 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003851 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003852 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003853 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003854 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3855 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003856 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003857
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003858 /**
fionaxu0152e512016-11-14 13:36:14 -08003859 * Sets the voice activation state of a given subId.
3860 */
3861 @Override
3862 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3864 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865
3866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 final Phone phone = getPhone(subId);
3869 if (phone != null) {
3870 phone.setVoiceActivationState(activationState);
3871 } else {
3872 loge("setVoiceActivationState fails with invalid subId: " + subId);
3873 }
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003876 }
3877 }
3878
3879 /**
3880 * Sets the data activation state of a given subId.
3881 */
3882 @Override
3883 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3885 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886
3887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 final Phone phone = getPhone(subId);
3890 if (phone != null) {
3891 phone.setDataActivationState(activationState);
3892 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003893 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894 }
3895 } finally {
3896 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003897 }
3898 }
3899
3900 /**
3901 * Returns the voice activation state of a given subId.
3902 */
3903 @Override
3904 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906
fionaxu0152e512016-11-14 13:36:14 -08003907 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 if (phone != null) {
3911 return phone.getVoiceActivationState();
3912 } else {
3913 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3914 }
3915 } finally {
3916 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003917 }
3918 }
3919
3920 /**
3921 * Returns the data activation state of a given subId.
3922 */
3923 @Override
3924 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926
fionaxu0152e512016-11-14 13:36:14 -08003927 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 if (phone != null) {
3931 return phone.getDataActivationState();
3932 } else {
3933 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3934 }
3935 } finally {
3936 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003937 }
3938 }
3939
3940 /**
Wink Saville36469e72014-06-11 15:17:00 -07003941 * Returns the unread count of voicemails for a subId
3942 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003943 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003944 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3945 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003947 mApp, subId, callingPackage, callingFeatureId,
3948 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003949 return 0;
3950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 final Phone phone = getPhone(subId);
3954 if (phone != null) {
3955 return phone.getVoiceMessageCount();
3956 } else {
3957 return 0;
3958 }
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003962 }
3963
3964 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003965 * returns true, if the device is in a state where both voice and data
3966 * are supported simultaneously. This can change based on location or network condition.
3967 */
3968 @Override
3969 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 final long identity = Binder.clearCallingIdentity();
3971 try {
3972 final Phone phone = getPhone(subId);
3973 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3974 } finally {
3975 Binder.restoreCallingIdentity(identity);
3976 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003977 }
3978
3979 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003980 * Send the dialer code if called from the current default dialer or the caller has
3981 * carrier privilege.
3982 * @param inputCode The dialer code to send
3983 */
3984 @Override
3985 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003988 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3989 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003990 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003991 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003992 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994
3995 final long identity = Binder.clearCallingIdentity();
3996 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003997 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998 } finally {
3999 Binder.restoreCallingIdentity(identity);
4000 }
fionaxu235cc5e2017-03-06 22:25:57 -08004001 }
4002
Pengquan Menga1bb6272018-09-06 09:59:22 -07004003 @Override
4004 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004005 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004006 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004007 mApp, subId, "getNetworkSelectionMode");
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 if (!isActiveSubscription(subId)) {
4011 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4012 }
4013 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004017 }
4018
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004020 public boolean isInEmergencySmsMode() {
4021 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 for (Phone phone : PhoneFactory.getPhones()) {
4025 if (phone.isInEmergencySmsMode()) {
4026 return true;
4027 }
4028 }
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
4031 }
4032 return false;
4033 }
4034
shilu366312e2019-12-17 09:28:10 -08004035 /**
4036 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4037 * @param subId The subscription to use to check the configuration.
4038 * @param c The callback that will be used to send the result.
4039 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004040 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004041 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4042 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004043 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004044 mApp, subId, "registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 final long token = Binder.clearCallingIdentity();
4046 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004047 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
4048 manager.addRegistrationCallbackForSubscription(c, subId);
4049 return null;
4050 });
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004051 } catch (ImsException e) {
4052 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 } finally {
4054 Binder.restoreCallingIdentity(token);
4055 }
4056 }
4057
shilu366312e2019-12-17 09:28:10 -08004058 /**
4059 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4060 * @param subId The subscription to use to check the configuration.
4061 * @param c The callback that will be used to send the result.
4062 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004064 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004065 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004066 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004067 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4068 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4069 }
Meng Wangafbc5852019-09-19 17:37:13 -07004070 final long token = Binder.clearCallingIdentity();
4071 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004072 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4073 .removeRegistrationCallbackForSubscription(c, subId);
4074 } catch (ImsException e) {
4075 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4076 + "is inactive, ignoring unregister.");
4077 // If the subscription is no longer active, just return, since the callback
4078 // will already have been removed internally.
4079 } finally {
4080 Binder.restoreCallingIdentity(token);
4081 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 }
4083
Brad Ebingera34a6c22019-10-22 17:36:18 -07004084 /**
4085 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4086 */
4087 @Override
4088 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4089 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4090 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4091 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4092 "IMS not available on device.");
4093 }
4094 final long token = Binder.clearCallingIdentity();
4095 try {
4096 Phone phone = getPhone(subId);
4097 if (phone == null) {
4098 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4099 + subId + "'");
4100 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4101 }
4102 phone.getImsRegistrationState(regState -> {
4103 try {
4104 consumer.accept((regState == null)
4105 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4106 } catch (RemoteException e) {
4107 // Ignore if the remote process is no longer available to call back.
4108 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4109 }
4110 });
4111 } finally {
4112 Binder.restoreCallingIdentity(token);
4113 }
4114 }
4115
4116 /**
4117 * Get the transport type for the IMS service registration state.
4118 */
4119 @Override
4120 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004121 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004122 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004123 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4124 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4125 "IMS not available on device.");
4126 }
4127 final long token = Binder.clearCallingIdentity();
4128 try {
4129 Phone phone = getPhone(subId);
4130 if (phone == null) {
4131 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4132 + subId + "'");
4133 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4134 }
4135 phone.getImsRegistrationTech(regTech -> {
4136 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4137 int regTechConverted = (regTech == null)
4138 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4139 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4140 regTechConverted);
4141 try {
4142 consumer.accept(regTechConverted);
4143 } catch (RemoteException e) {
4144 // Ignore if the remote process is no longer available to call back.
4145 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4146 }
4147 });
4148 } finally {
4149 Binder.restoreCallingIdentity(token);
4150 }
4151 }
4152
shilu366312e2019-12-17 09:28:10 -08004153 /**
4154 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4155 * @param subId The subscription to use to check the configuration.
4156 * @param c The callback that will be used to send the result.
4157 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004159 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4160 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004161 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004162 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 final long token = Binder.clearCallingIdentity();
4164 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004165 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
4166 manager.addCapabilitiesCallbackForSubscription(c, subId);
4167 return null;
4168 });
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004169 } catch (ImsException e) {
4170 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 } finally {
4172 Binder.restoreCallingIdentity(token);
4173 }
4174 }
4175
shilu366312e2019-12-17 09:28:10 -08004176 /**
4177 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4178 * @param subId The subscription to use to check the configuration.
4179 * @param c The callback that will be used to send the result.
4180 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004182 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004183 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004184 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004185 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4186 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4187 }
Meng Wangafbc5852019-09-19 17:37:13 -07004188
4189 final long token = Binder.clearCallingIdentity();
4190 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004191 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004192 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004193 } catch (ImsException e) {
4194 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4195 + "is inactive, ignoring unregister.");
4196 // If the subscription is no longer active, just return, since the callback
4197 // will already have been removed internally.
4198 } finally {
4199 Binder.restoreCallingIdentity(token);
4200 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 }
4202
4203 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004204 public boolean isCapable(int subId, int capability, int regTech) {
4205 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 final long token = Binder.clearCallingIdentity();
4207 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004208 return runUsingImsManagerOrThrow(subId,
4209 manager -> manager.queryMmTelCapability(capability, regTech));
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004211 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4212 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 } finally {
4214 Binder.restoreCallingIdentity(token);
4215 }
4216 }
4217
4218 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004219 public boolean isAvailable(int subId, int capability, int regTech) {
4220 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 final long token = Binder.clearCallingIdentity();
4222 try {
4223 Phone phone = getPhone(subId);
4224 if (phone == null) return false;
4225 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004226 } catch (com.android.ims.ImsException e) {
4227 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4228 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(token);
4231 }
4232 }
4233
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004234 /**
4235 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4236 * subscription.
4237 * @param subId The subscription to use to check the configuration.
4238 * @param callback The callback that will be used to send the result.
4239 * @param capability The MmTelFeature capability that will be used to send the result.
4240 * @param transportType The transport type of the MmTelFeature capability.
4241 */
4242 @Override
4243 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4244 int transportType) {
4245 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004246 final long token = Binder.clearCallingIdentity();
4247 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004248 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
4249 manager.isSupported(capability, transportType, aBoolean -> {
4250 try {
4251 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4252 } catch (RemoteException e) {
4253 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4254 + "running. Ignore");
4255 }
4256 });
4257 return null;
4258 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 } catch (ImsException e) {
4260 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004261 } finally {
4262 Binder.restoreCallingIdentity(token);
4263 }
4264 }
4265
shilu366312e2019-12-17 09:28:10 -08004266 /**
4267 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4268 * @param subId The subscription to use to check the configuration.
4269 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 @Override
4271 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004272 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004273 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004274
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 final long token = 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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004280 } catch (ImsException e) {
4281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 } finally {
4283 Binder.restoreCallingIdentity(token);
4284 }
4285 }
4286
4287 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004288 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004290 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 final long identity = Binder.clearCallingIdentity();
4292 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004293 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004294 // This setting doesn't require an active ImsService connection, so do not verify. The
4295 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004297 } catch (ImsException e) {
4298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
4302 }
4303
shilu366312e2019-12-17 09:28:10 -08004304 /**
4305 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4306 * @param subId The subscription to use to check the configuration.
4307 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004309 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004310 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004311 mApp, subId, "isVtSettingEnabled");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
4324 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004325 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004327 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 final long identity = Binder.clearCallingIdentity();
4329 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004330 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004331 // This setting doesn't require an active ImsService connection, so do not verify. The
4332 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004333 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004334 } catch (ImsException e) {
4335 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
4339 }
4340
shilu366312e2019-12-17 09:28:10 -08004341 /**
4342 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4343 * @param subId The subscription to use to check the configuration.
4344 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 @Override
4346 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004347 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004348 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 final long identity = Binder.clearCallingIdentity();
4350 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004351 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004352 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (ImsException e) {
4355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
4359 }
4360
4361 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004362 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004364 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004367 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004368 // This setting doesn't require an active ImsService connection, so do not verify. The
4369 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004371 } catch (ImsException e) {
4372 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
4376 }
4377
shilu366312e2019-12-17 09:28:10 -08004378 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004379 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4380 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4381 * @param subId The subscription to use to check the configuration.
4382 */
4383 @Override
4384 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004385 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004386 mApp, subId, "isCrossSimCallingEnabledByUser");
4387 final long identity = Binder.clearCallingIdentity();
4388 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004389 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004390 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004391 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004392 } catch (ImsException e) {
4393 throw new ServiceSpecificException(e.getCode());
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
4397 }
4398
4399 /**
4400 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4401 * Requires MODIFY_PHONE_STATE permission.
4402 * @param subId The subscription to use to check the configuration.
4403 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4404 * false otherwise
4405 */
4406 @Override
4407 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4409 "setCrossSimCallingEnabled");
4410 final long identity = Binder.clearCallingIdentity();
4411 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004413 // This setting doesn't require an active ImsService connection, so do not verify. The
4414 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004415 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004416 } catch (ImsException e) {
4417 throw new ServiceSpecificException(e.getCode());
4418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
4421 }
4422
4423 /**
shilu366312e2019-12-17 09:28:10 -08004424 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4425 * @param subId The subscription to use to check the configuration.
4426 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004428
Brad Ebinger35c841c2018-10-01 10:40:55 -07004429 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004430 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004431 mApp, subId, "isVoWiFiRoamingSettingEnabled");
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).isWfcRoamingEnabledByUser();
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
Brad Ebinger1c162042019-02-21 14:49:10 -08004445 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004447 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 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).setWfcRoamingSetting(isEnabled);
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 void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4464 "setVoWiFiNonPersistent");
4465 final long identity = Binder.clearCallingIdentity();
4466 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004467 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004468 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004469 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004470 } catch (ImsException e) {
4471 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
4475 }
4476
shilu366312e2019-12-17 09:28:10 -08004477 /**
4478 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4479 * @param subId The subscription to use to check the configuration.
4480 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 @Override
4482 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004483 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004484 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 final long identity = Binder.clearCallingIdentity();
4486 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004488 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004489 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (ImsException e) {
4491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
4495 }
4496
4497 @Override
4498 public void setVoWiFiModeSetting(int subId, int mode) {
4499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4500 "setVoWiFiModeSetting");
4501 final long identity = Binder.clearCallingIdentity();
4502 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004503 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004504 // This setting doesn't require an active ImsService connection, so do not verify. The
4505 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004506 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004507 } catch (ImsException e) {
4508 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
4512 }
4513
4514 @Override
4515 public int getVoWiFiRoamingModeSetting(int subId) {
4516 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4517 final long identity = Binder.clearCallingIdentity();
4518 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004519 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004520 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004521 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004522 } catch (ImsException e) {
4523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
4529 @Override
4530 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4532 "setVoWiFiRoamingModeSetting");
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004535 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004536 // This setting doesn't require an active ImsService connection, so do not verify. The
4537 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004539 } catch (ImsException e) {
4540 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004541 } finally {
4542 Binder.restoreCallingIdentity(identity);
4543 }
4544 }
4545
4546 @Override
4547 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4549 "setRttCapabilityEnabled");
4550 final long identity = Binder.clearCallingIdentity();
4551 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004552 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004553 // This setting doesn't require an active ImsService connection, so do not verify. The
4554 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004555 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004556 } catch (ImsException e) {
4557 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
4561 }
4562
shilu366312e2019-12-17 09:28:10 -08004563 /**
4564 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4565 * @param subId The subscription to use to check the configuration.
4566 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004567 @Override
4568 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004569 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004570 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004571 final long identity = Binder.clearCallingIdentity();
4572 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004573 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004574 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004576 } catch (ImsException e) {
4577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
4581 }
4582
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004583 @Override
4584 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4585 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004586
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004587 final long identity = Binder.clearCallingIdentity();
4588 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004589 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
4590 manager.addProvisioningCallbackForSubscription(callback, subId);
4591 return null;
4592 });
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004593 } catch (ImsException e) {
4594 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
4598 }
4599
4600 @Override
4601 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4602 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004603
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004604 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4606 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4607 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004609 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004610 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004611 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004612 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4613 + "is inactive, ignoring unregister.");
4614 // If the subscription is no longer active, just return, since the callback will already
4615 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 } finally {
4617 Binder.restoreCallingIdentity(identity);
4618 }
4619 }
4620
joonhunshincffb7fc2021-11-28 07:32:01 +00004621 @Override
4622 public void registerFeatureProvisioningChangedCallback(int subId,
4623 IFeatureProvisioningCallback callback) {
4624 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4625 mApp, subId, "registerFeatureProvisioningChangedCallback");
4626
4627 final long identity = Binder.clearCallingIdentity();
4628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4629 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4630 }
4631
4632 ImsProvisioningController.getInstance()
4633 .addFeatureProvisioningChangedCallback(subId, callback);
4634
4635 Binder.restoreCallingIdentity(identity);
4636 }
4637
4638 @Override
4639 public void unregisterFeatureProvisioningChangedCallback(int subId,
4640 IFeatureProvisioningCallback callback) {
4641 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4642 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4643
4644 final long identity = Binder.clearCallingIdentity();
4645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4646 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4647 }
4648
4649 ImsProvisioningController.getInstance()
4650 .removeFeatureProvisioningChangedCallback(subId, callback);
4651
4652 Binder.restoreCallingIdentity(identity);
4653 }
allenwtsu99c623b2020-01-03 18:24:23 +08004654
4655 private void checkModifyPhoneStatePermission(int subId, String message) {
4656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4657 message);
4658 }
4659
4660 private boolean isImsProvisioningRequired(int subId, int capability,
4661 boolean isMmtelCapability) {
4662 Phone phone = getPhone(subId);
4663 if (phone == null) {
4664 loge("phone instance null for subid " + subId);
4665 return false;
4666 }
4667 if (isMmtelCapability) {
4668 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4669 return false;
4670 }
4671 } else {
4672 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4673 return false;
4674 }
4675 }
4676 return true;
4677 }
4678
4679 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004680 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004681 boolean isProvisioned) {
4682 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4683
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004686 ImsProvisioningController.getInstance()
4687 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4688 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
allenwtsu99c623b2020-01-03 18:24:23 +08004692 }
4693
4694
4695 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004696 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4697 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4698 mApp, subId, "getRcsProvisioningStatusForCapability");
4699
allenwtsu99c623b2020-01-03 18:24:23 +08004700 final long identity = Binder.clearCallingIdentity();
4701 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004702 return ImsProvisioningController.getInstance()
4703 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004704 } finally {
4705 Binder.restoreCallingIdentity(identity);
4706 }
4707 }
4708
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004709 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004710 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4711 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004712 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004713
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 final long identity = Binder.clearCallingIdentity();
4715 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004716 ImsProvisioningController.getInstance()
4717 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
4721 }
4722
4723 @Override
4724 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004725 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4726 mApp, subId, "getProvisioningStatusForCapability");
4727
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004728 final long identity = Binder.clearCallingIdentity();
4729 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004730 return ImsProvisioningController.getInstance()
4731 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004732
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
4736 }
4737
4738 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004739 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4740 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4741 mApp, subId, "isProvisioningRequiredForCapability");
4742
4743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 return ImsProvisioningController.getInstance()
4746 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004750 }
4751
4752 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004753 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4754 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4755 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756
joonhunshincffb7fc2021-11-28 07:32:01 +00004757 final long identity = Binder.clearCallingIdentity();
4758 try {
4759 return ImsProvisioningController.getInstance()
4760 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4761 } finally {
4762 Binder.restoreCallingIdentity(identity);
4763 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004764 }
4765
4766 private static String getMmTelProvisioningKey(int subId, int tech) {
4767 // resulting key is provision_ims_mmtel_{subId}_{tech}
4768 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4769 }
4770
4771 /**
4772 * Query CarrierConfig to see if the specified capability requires provisioning for the
4773 * carrier associated with the subscription id.
4774 */
4775 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4776 int capability) {
4777 CarrierConfigManager configManager = new CarrierConfigManager(context);
4778 PersistableBundle c = configManager.getConfigForSubId(subId);
4779 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004780 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004781 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4782 false);
4783 boolean requireVoiceVtProvisioning = c.getBoolean(
4784 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4785
4786 // First check to make sure that the capability requires provisioning.
4787 switch (capability) {
4788 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4789 // intentional fallthrough
4790 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4791 if (requireVoiceVtProvisioning) {
4792 // Voice and Video requires provisioning
4793 return true;
4794 }
4795 break;
4796 }
4797 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4798 if (requireUtProvisioning) {
4799 // UT requires provisioning
4800 return true;
4801 }
4802 break;
4803 }
4804 }
4805 return false;
4806 }
4807
allenwtsu99c623b2020-01-03 18:24:23 +08004808 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4809 int capability) {
4810 CarrierConfigManager configManager = new CarrierConfigManager(context);
4811 PersistableBundle c = configManager.getConfigForSubId(subId);
4812
4813 boolean requireRcsProvisioning = c.getBoolean(
4814 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4815
4816 // First check to make sure that the capability requires provisioning.
4817 switch (capability) {
4818 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4819 // intentional fallthrough
4820 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4821 if (requireRcsProvisioning) {
4822 // OPTION or PRESENCE requires provisioning
4823 return true;
4824 }
4825 break;
4826 }
4827 }
4828 return false;
4829 }
4830
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004832 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4834 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4835 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004836 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4837 mApp, subId, "getImsProvisioningInt");
4838
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004839 final long identity = Binder.clearCallingIdentity();
4840 try {
4841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004842 int slotId = getSlotIndex(subId);
4843 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4844 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4845 + subId + "' for key:" + key);
4846 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4847 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004848
4849 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4850 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4851 return retVal;
4852 }
4853
calvinpanb5a34062021-02-08 19:59:36 +08004854 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004855 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004856 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4857 + subId + "' for key:" + key);
4858 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004859 } finally {
4860 Binder.restoreCallingIdentity(identity);
4861 }
4862 }
4863
4864 @Override
4865 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004866 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4867 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4868 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004869 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4870 mApp, subId, "getImsProvisioningString");
4871
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004872 final long identity = Binder.clearCallingIdentity();
4873 try {
4874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004875 int slotId = getSlotIndex(subId);
4876 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4877 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4878 + subId + "' for key:" + key);
4879 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4880 }
calvinpanb5a34062021-02-08 19:59:36 +08004881 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004882 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4884 + subId + "' for key:" + key);
4885 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004886 } finally {
4887 Binder.restoreCallingIdentity(identity);
4888 }
4889 }
4890
4891 @Override
4892 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004893 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4894 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4895 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4897 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004898
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004899 final long identity = Binder.clearCallingIdentity();
4900 try {
4901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 int slotId = getSlotIndex(subId);
4903 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4904 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4905 + subId + "' for key:" + key);
4906 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4907 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004908
4909 int retVal = ImsProvisioningController.getInstance()
4910 .setProvisioningValue(subId, key, value);
4911 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4912 return retVal;
4913 }
4914
calvinpanb5a34062021-02-08 19:59:36 +08004915 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4916 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004918 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
4925 @Override
4926 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4928 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4929 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4931 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004935 int slotId = getSlotIndex(subId);
4936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4937 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4938 + subId + "' for key:" + key);
4939 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4940 }
calvinpanb5a34062021-02-08 19:59:36 +08004941 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4942 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004944 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
Brad Ebinger919631e2021-06-02 17:46:35 -07004951 /**
4952 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4953 * for the given slot ID or no ImsResolver instance has been created.
4954 * @param slotId The slot ID that the IMS service is created for.
4955 * @throws ImsException If there is no ImsService configured for this slot.
4956 */
4957 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4958 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4959 ImsFeature.FEATURE_MMTEL)) {
4960 throw new ImsException("This subscription does not support MMTEL over IMS",
4961 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4962 }
4963 }
4964
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08004965 //
4966
4967 /**
4968 * Functional interface for encapsulating IMS related commands that should be sent to
4969 * ImsManager for processing.
4970 * @param <V> The return type
4971 */
4972 private interface ImsFunction<V> {
4973 V call(ImsManager manager) throws Exception;
4974 }
4975
4976 /**
4977 * Run the specified command on the ImsManager for the subscription specified or throw an
4978 * {@link ImsException} if the IMS is not available for any reason.
4979 * @param subId The subscription to use
4980 * @param func The function to run on the given ImsManager instance.
4981 * @param <V> The return type of the function
4982 * @return The result of the evaluated command
4983 * @throws ImsException if the IMS service is not available for any reason.
4984 */
4985 private <V> V runUsingImsManagerOrThrow(int subId, ImsFunction<V> func) throws ImsException {
4986 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4987 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4988 "IMS not available on device.");
4989 }
4990 int slotId = getSlotIndexOrException(subId);
4991 verifyImsMmTelConfiguredOrThrow(slotId);
4992 ImsManager manager = ImsManager.getInstance(mApp, slotId);
4993 if (manager.getSubId() != subId || !manager.isServiceReady()) {
4994 Log.w(LOG_TAG, "getImsManagerForSubIdOrThrow: couldn't resolve ImsManager, ready= "
4995 + manager.isServiceReady() + ", manager subId= " + manager.getSubId()
4996 + ", request subId= " + subId);
4997 // if we have hit this point, getSlotIndexOrException has already checked that the subId
4998 // is active for a phone, but ImsManager currently doesn't have the correct subId set or
4999 // the ImsService has crashed/is not ready. The caller will have to wait for the service
5000 // to be available before calling again.
5001 throw new ImsException("The ImsService is not available for the subId specified.",
5002 ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5003 }
5004 try {
5005 return func.call(manager);
5006 } catch (Exception e) {
5007 // Some methods internally report RuntimeExceptions. Repackage those exceptions as well
5008 // defined ImsExceptions.
5009 throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5010 }
5011 }
5012
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005013 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005014 int slotId = SubscriptionManager.getSlotIndex(subId);
5015 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005016 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5017 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005018 }
5019 return slotId;
5020 }
5021
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005022 private int getSlotIndex(int subId) {
5023 int slotId = SubscriptionManager.getSlotIndex(subId);
5024 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5025 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5026 }
5027 return slotId;
5028 }
5029
Wink Saville36469e72014-06-11 15:17:00 -07005030 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005031 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005032 */
5033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005034 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5035 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005036 try {
5037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5038 } catch (SecurityException se) {
5039 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5040 throw new SecurityException("Package " + callingPackage + " does not belong to "
5041 + Binder.getCallingUid());
5042 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005043 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005044 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005045 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005046 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005047 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005048 mApp, subId, callingPackage, callingFeatureId,
5049 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005050 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5051 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
5055 final Phone phone = getPhone(subId);
5056 if (phone != null) {
5057 return phone.getServiceState().getDataNetworkType();
5058 } else {
5059 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5060 }
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005064 }
5065
5066 /**
5067 * Returns the data network type
5068 */
5069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005070 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005071 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5072 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005073 }
5074
5075 /**
5076 * Returns the data network type for a subId
5077 */
5078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005079 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5080 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005081 String functionName = "getDataNetworkTypeForSubscriber";
5082 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5083 mApp, functionName)) {
5084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5085 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5086 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5087 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005088 }
5089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 final Phone phone = getPhone(subId);
5093 if (phone != null) {
5094 return phone.getServiceState().getDataNetworkType();
5095 } else {
5096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005101 }
5102
5103 /**
Wink Saville36469e72014-06-11 15:17:00 -07005104 * Returns the Voice network type for a subId
5105 */
5106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005107 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5108 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005109 String functionName = "getVoiceNetworkTypeForSubscriber";
5110 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5111 mApp, functionName)) {
5112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5113 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5114 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5115 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005116 }
5117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 final Phone phone = getPhone(subId);
5121 if (phone != null) {
5122 return phone.getServiceState().getVoiceNetworkType();
5123 } else {
5124 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5125 }
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005129 }
5130
5131 /**
5132 * @return true if a ICC card is present
5133 */
5134 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005135 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005136 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5137 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005138 }
5139
5140 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005141 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005142 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005143 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005144 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 final Phone phone = PhoneFactory.getPhone(slotIndex);
5148 if (phone != null) {
5149 return phone.getIccCard().hasIccCard();
5150 } else {
5151 return false;
5152 }
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005156 }
5157
5158 /**
5159 * Return if the current radio is LTE on CDMA. This
5160 * is a tri-state return value as for a period of time
5161 * the mode may be unknown.
5162 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005163 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005164 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005165 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005166 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005168 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5169 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5170 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005171 }
5172
Sanket Padawe356d7632015-06-22 14:03:32 -07005173 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005174 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5175 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005176 try {
5177 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5178 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005179 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5180 }
5181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 final long identity = Binder.clearCallingIdentity();
5183 try {
5184 final Phone phone = getPhone(subId);
5185 if (phone == null) {
5186 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5187 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005188 return TelephonyProperties.lte_on_cdma_device()
5189 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 }
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005193 }
Wink Saville36469e72014-06-11 15:17:00 -07005194 }
5195
Wink Saville36469e72014-06-11 15:17:00 -07005196 /**
5197 * {@hide}
5198 * Returns Default subId, 0 in the case of single standby.
5199 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005200 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005201 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005202 }
5203
Shishir Agrawala9f32182016-04-12 12:00:16 -07005204 private int getSlotForDefaultSubscription() {
5205 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5206 }
5207
Wink Savilleb564aae2014-10-23 10:18:09 -07005208 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005209 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005210 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005211
Pengquan Menge92a50d2018-09-21 15:54:48 -07005212 private boolean isActiveSubscription(int subId) {
5213 return mSubscriptionController.isActiveSubId(subId);
5214 }
5215
Ihab Awadf2177b72013-11-25 13:33:23 -08005216 /**
5217 * @see android.telephony.TelephonyManager.WifiCallingChoices
5218 */
5219 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 final long identity = Binder.clearCallingIdentity();
5221 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005222 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5224 getWhenToMakeWifiCallsDefaultPreference());
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005228 }
5229
5230 /**
5231 * @see android.telephony.TelephonyManager.WifiCallingChoices
5232 */
5233 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 final long identity = Binder.clearCallingIdentity();
5235 try {
5236 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005237 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005242 }
5243
Sailesh Nepald1e68152013-12-12 19:08:02 -08005244 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005245 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005246 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005247 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005248
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005249 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5250 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5251 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005252 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005253 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5254 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005255 }
5256 return PhoneFactory.getPhone(phoneId);
5257 }
5258
Shishir Agrawal566b7612013-10-28 14:41:00 -07005259 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005260 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005261 @NonNull IccLogicalChannelRequest request) {
5262 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5263 /*message=*/ "iccOpenLogicalChannel");
5264
5265 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5266 // Verify that the callingPackage in the request belongs to the calling UID
5267 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5268
5269 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005270 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005271
Rambo Wanga1782702021-11-10 20:15:19 -08005272 private Phone getPhoneFromValidIccLogicalChannelRequest(
5273 @NonNull IccLogicalChannelRequest request, String message) {
5274 Phone phone;
5275 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5277 mApp, request.subId, message);
5278 phone = getPhoneFromSubId(request.subId);
5279 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5280 enforceModifyPermission();
5281 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5282 } else {
5283 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005284 }
Rambo Wanga1782702021-11-10 20:15:19 -08005285 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005286 }
5287
5288 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005289 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 final long identity = Binder.clearCallingIdentity();
5291 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005292 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005294 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5295 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005296 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5297 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 loge("The calling package is not allowed to access ISD-R.");
5299 throw new SecurityException(
5300 "The calling package is not allowed to access ISD-R.");
5301 }
Derek Tan740e1672017-06-27 14:56:27 -07005302 }
Derek Tan740e1672017-06-27 14:56:27 -07005303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005305 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5306 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 return response;
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005311 }
5312
5313 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005314 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5315 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5316 /*message=*/"iccCloseLogicalChannel");
5317
5318 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5319
5320 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005321 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322
Rambo Wanga1782702021-11-10 20:15:19 -08005323 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5324 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 final long identity = Binder.clearCallingIdentity();
5326 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005327 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005328 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 }
Chen Xue9d737e2022-01-01 23:41:31 -08005330 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005331 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005332 Boolean success = false;
5333 if (result instanceof RuntimeException) {
5334 // if there is an exception returned, throw from the binder thread here.
5335 throw (RuntimeException) result;
5336 } else if (result instanceof Boolean) {
5337 success = (Boolean) result;
5338 } else {
5339 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5340 }
Rambo Wanga1782702021-11-10 20:15:19 -08005341 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 return success;
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005345 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005346 }
5347
5348 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005349 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005350 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5352 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005353 if (DBG) {
5354 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5355 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5356 + p3 + " data=" + data);
5357 }
5358 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5359 command, p1, p2, p3, data);
5360 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005361
Jordan Liu4c733742019-02-28 12:03:40 -08005362 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005363 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5364 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005365 enforceModifyPermission();
5366 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005367 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5368 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5369 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005370 }
5371 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005372 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5373 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005374 }
5375
5376 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5377 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 final long identity = Binder.clearCallingIdentity();
5379 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005380 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005381 return "";
5382 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005385 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5386 null /* workSource */);
5387 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 // Append the returned status code to the end of the response payload.
5390 String s = Integer.toHexString(
5391 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5392 if (response.payload != null) {
5393 s = IccUtils.bytesToHexString(response.payload) + s;
5394 }
5395 return s;
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005398 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005399 }
Jake Hambye994d462014-02-03 13:10:13 -08005400
Evan Charltonc66da362014-05-16 14:06:40 -07005401 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005402 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5403 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5405 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005407 if (DBG) {
5408 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5409 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5410 }
5411 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5412 cla, command, p1, p2, p3, data);
5413 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005414
Jordan Liu4c733742019-02-28 12:03:40 -08005415 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005416 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5417 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005418 enforceModifyPermission();
5419 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5420 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005421 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5422 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5423 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005424 }
5425
5426 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005427 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5428 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005429 }
5430
5431 // open APDU basic channel assuming the caller has sufficient permissions
5432 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5433 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 final long identity = Binder.clearCallingIdentity();
5435 try {
5436 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5437 && TextUtils.equals(ISDR_AID, data)) {
5438 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005439 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5440 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 if (bestComponent == null
5442 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5443 loge("The calling package is not allowed to select ISD-R.");
5444 throw new SecurityException(
5445 "The calling package is not allowed to select ISD-R.");
5446 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005447 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005450 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5451 null /* workSource */);
5452 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005453
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 // Append the returned status code to the end of the response payload.
5455 String s = Integer.toHexString(
5456 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5457 if (response.payload != null) {
5458 s = IccUtils.bytesToHexString(response.payload) + s;
5459 }
5460 return s;
5461 } finally {
5462 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005463 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005464 }
5465
5466 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005467 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005468 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5470 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 final long identity = Binder.clearCallingIdentity();
5473 try {
5474 if (DBG) {
5475 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5476 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5477 }
5478
5479 IccIoResult response =
5480 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5481 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5482 subId);
5483
5484 if (DBG) {
5485 log("Exchange SIM_IO [R]" + response);
5486 }
5487
5488 byte[] result = null;
5489 int length = 2;
5490 if (response.payload != null) {
5491 length = 2 + response.payload.length;
5492 result = new byte[length];
5493 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5494 } else {
5495 result = new byte[length];
5496 }
5497
5498 result[length - 1] = (byte) response.sw2;
5499 result[length - 2] = (byte) response.sw1;
5500 return result;
5501 } finally {
5502 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005503 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005504 }
5505
Nathan Haroldb3014052017-01-25 15:57:32 -08005506 /**
5507 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5508 * on a particular subscription
5509 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005510 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5511 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005512 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005513 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005514 return null;
5515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 if (appType != TelephonyManager.APPTYPE_USIM
5520 && appType != TelephonyManager.APPTYPE_SIM) {
5521 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5522 return null;
5523 }
5524 Object response = sendRequest(
5525 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5526 if (response instanceof String[]) {
5527 return (String[]) response;
5528 }
yincheng zhao2737e882019-09-06 17:06:54 -07005529 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005531 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005534 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005535 }
5536
yincheng zhao2737e882019-09-06 17:06:54 -07005537 /**
5538 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5539 * subscription.
5540 *
5541 * @param subId the id of the subscription.
5542 * @param appType the uicc app type, must be USIM or SIM.
5543 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5544 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005545 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005546 * @return number of fplmns that is successfully written to the SIM.
5547 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005548 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5549 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5551 mApp, subId, "setForbiddenPlmns");
5552
yincheng zhao2737e882019-09-06 17:06:54 -07005553 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5554 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5555 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5556 }
5557 if (fplmns == null) {
5558 throw new IllegalArgumentException("Fplmn List provided is null");
5559 }
5560 for (String fplmn : fplmns) {
5561 if (!CellIdentity.isValidPlmn(fplmn)) {
5562 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5563 }
5564 }
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 Object response = sendRequest(
5568 CMD_SET_FORBIDDEN_PLMNS,
5569 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5570 subId);
5571 return (int) response;
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
5575 }
5576
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005577 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005578 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5580 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 final long identity = Binder.clearCallingIdentity();
5583 try {
5584 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5585 if (response.payload == null) {
5586 return "";
5587 }
Evan Charltonc66da362014-05-16 14:06:40 -07005588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 // Append the returned status code to the end of the response payload.
5590 String s = Integer.toHexString(
5591 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5592 s = IccUtils.bytesToHexString(response.payload) + s;
5593 return s;
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Evan Charltonc66da362014-05-16 14:06:40 -07005597 }
5598
Jake Hambye994d462014-02-03 13:10:13 -08005599 /**
5600 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5601 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5602 *
5603 * @param itemID the ID of the item to read
5604 * @return the NV item as a String, or null on error.
5605 */
5606 @Override
5607 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005608 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5610 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611
5612 final long identity = Binder.clearCallingIdentity();
5613 try {
5614 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005615 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5617 return value;
5618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
Jake Hambye994d462014-02-03 13:10:13 -08005621 }
5622
5623 /**
5624 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5625 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5626 *
5627 * @param itemID the ID of the item to read
5628 * @param itemValue the value to write, as a String
5629 * @return true on success; false on any failure
5630 */
5631 @Override
5632 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005633 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5640 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005641 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5643 return success;
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Jake Hambye994d462014-02-03 13:10:13 -08005647 }
5648
5649 /**
5650 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5651 * Used for device configuration by some CDMA operators.
5652 *
5653 * @param preferredRoamingList byte array containing the new PRL
5654 * @return true on success; false on any failure
5655 */
5656 @Override
5657 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5659 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5664 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5665 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5666 return success;
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Jake Hambye994d462014-02-03 13:10:13 -08005670 }
5671
5672 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005673 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005674 * Used for device configuration by some CDMA operators.
5675 *
chen xu6dac5ab2018-10-26 17:39:23 -07005676 * @param slotIndex - device slot.
5677 *
Jake Hambye994d462014-02-03 13:10:13 -08005678 * @return true on success; false on any failure
5679 */
5680 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005681 public boolean resetModemConfig(int slotIndex) {
5682 Phone phone = PhoneFactory.getPhone(slotIndex);
5683 if (phone != null) {
5684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5685 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686
chen xu6dac5ab2018-10-26 17:39:23 -07005687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5690 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5691 return success;
5692 } finally {
5693 Binder.restoreCallingIdentity(identity);
5694 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 }
chen xu6dac5ab2018-10-26 17:39:23 -07005696 return false;
5697 }
5698
5699 /**
5700 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5701 *
5702 * @param slotIndex - device slot.
5703 *
5704 * @return true on success; false on any failure
5705 */
5706 @Override
5707 public boolean rebootModem(int slotIndex) {
5708 Phone phone = PhoneFactory.getPhone(slotIndex);
5709 if (phone != null) {
5710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5711 mApp, phone.getSubId(), "rebootModem");
5712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5716 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5717 return success;
5718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
5721 }
5722 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005723 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005724
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005725 public String[] getPcscfAddress(String apnType, String callingPackage,
5726 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5729 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005730 return new String[0];
5731 }
5732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 final long identity = Binder.clearCallingIdentity();
5734 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005735 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
Wink Saville36469e72014-06-11 15:17:00 -07005739 }
5740
Brad Ebinger51f743a2017-01-23 13:50:20 -08005741 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005742 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5743 * {@link #disableIms(int)}.
5744 * @param slotIndex device slot.
5745 */
5746 public void resetIms(int slotIndex) {
5747 enforceModifyPermission();
5748
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
5751 if (mImsResolver == null) {
5752 // may happen if the does not support IMS.
5753 return;
5754 }
5755 mImsResolver.disableIms(slotIndex);
5756 mImsResolver.enableIms(slotIndex);
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
5760 }
5761
5762 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005763 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5764 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005765 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005766 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005767 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768
5769 final long identity = Binder.clearCallingIdentity();
5770 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005771 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005772 // may happen if the device does not support IMS.
5773 return;
5774 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005775 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005779 }
5780
5781 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005782 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5783 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005784 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005785 public void disableIms(int slotId) {
5786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787
5788 final long identity = Binder.clearCallingIdentity();
5789 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005791 // may happen if the device does not support IMS.
5792 return;
5793 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005798 }
5799
5800 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005801 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5802 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005803 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005804 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005805 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005811 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5812 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005813 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005814 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005818 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005819 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005820 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5821 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005822 @Override
5823 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005824 enforceModifyPermission();
5825
5826 final long identity = Binder.clearCallingIdentity();
5827 try {
5828 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005829 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005830 } finally {
5831 Binder.restoreCallingIdentity(identity);
5832 }
5833 }
5834
5835 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005836 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005837 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005838 */
5839 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5840 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841
5842 final long identity = Binder.clearCallingIdentity();
5843 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005845 // may happen if the device does not support IMS.
5846 return null;
5847 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005848 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005852 }
5853
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005854 /**
5855 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005856 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005857 */
5858 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005864 // may happen if the device does not support IMS.
5865 return null;
5866 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005871 }
5872
Brad Ebinger884c07b2018-02-15 16:17:40 -08005873 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 * Sets the ImsService Package Name that Telephony will bind to.
5875 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 * @param slotIndex the slot ID that the ImsService should bind for.
5877 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005878 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005879 * @param featureTypes An integer array of feature types associated with a packageName.
5880 * @param packageName The name of the package that the current configuration will be replaced
5881 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005882 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005883 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005884 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5885 int[] featureTypes, String packageName) {
5886 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5889 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 final long identity = Binder.clearCallingIdentity();
5893 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005895 // may happen if the device does not support IMS.
5896 return false;
5897 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 Map<Integer, String> featureConfig = new HashMap<>();
5899 for (int featureType : featureTypes) {
5900 featureConfig.put(featureType, packageName);
5901 }
5902 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5903 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904 } finally {
5905 Binder.restoreCallingIdentity(identity);
5906 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005907 }
5908
5909 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005910 * Clears any carrier ImsService overrides for the slot index specified that were previously
5911 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5912 *
5913 * This should only be used for testing.
5914 *
5915 * @param slotIndex the slot ID that the ImsService should bind for.
5916 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5917 */
5918 @Override
5919 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5920 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5921 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5922 "clearCarrierImsServiceOverride");
5923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5924 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5925 "clearCarrierImsServiceOverride");
5926
5927 final long identity = Binder.clearCallingIdentity();
5928 try {
5929 if (mImsResolver == null) {
5930 // may happen if the device does not support IMS.
5931 return false;
5932 }
5933 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
5937 }
5938
5939 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005940 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005941 *
5942 * @param slotId The slot that the ImsService is associated with.
5943 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5944 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005945 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005946 * @return the package name of the ImsService configuration.
5947 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005948 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5949 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005950 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005952 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005953 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5954 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 final long identity = Binder.clearCallingIdentity();
5957 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005958 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005959 // may happen if the device does not support IMS.
5960 return "";
5961 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005962 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005963 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5964 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
5967 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005968 }
5969
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005970 /**
5971 * Get the MmTelFeature state associated with the requested subscription id.
5972 * @param subId The subscription that the MmTelFeature is associated with.
5973 * @param callback A callback with an integer containing the
5974 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5975 */
5976 @Override
5977 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5978 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005979 final long token = Binder.clearCallingIdentity();
5980 try {
Brad Ebinger3d1bfb82022-02-16 11:45:26 -08005981 runUsingImsManagerOrThrow(subId, (ImsFunction<Void>) manager -> {
5982 manager.getImsServiceState(anInteger -> {
5983 try {
5984 callback.accept(anInteger == null
5985 ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5986 } catch (RemoteException e) {
5987 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer "
5988 + "running. Ignore");
5989 }
5990 });
5991 return null;
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005992 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005993 } catch (ImsException e) {
5994 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005995 } finally {
5996 Binder.restoreCallingIdentity(token);
5997 }
5998 }
5999
Daniel Brightbb5840b2021-01-12 15:48:18 -08006000 /**
6001 * Sets the ims registration state on all valid {@link Phone}s.
6002 */
6003 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005
6006 final long identity = Binder.clearCallingIdentity();
6007 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006008 // NOTE: Before S, this method only set the default phone.
6009 for (final Phone phone : PhoneFactory.getPhones()) {
6010 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6011 phone.setImsRegistrationState(registered);
6012 }
6013 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
Wink Saville36469e72014-06-11 15:17:00 -07006017 }
6018
6019 /**
Stuart Scott54788802015-03-30 13:18:01 -07006020 * Set the network selection mode to automatic.
6021 *
6022 */
6023 @Override
6024 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6026 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
shilufc958392020-01-20 11:36:01 -08006030 if (!isActiveSubscription(subId)) {
6031 return;
6032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006034 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6035 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
Stuart Scott54788802015-03-30 13:18:01 -07006039 }
6040
Jack Yud10cdd42020-09-28 20:28:01 -07006041 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006042 * Ask the radio to connect to the input network and change selection mode to manual.
6043 *
6044 * @param subId the id of the subscription.
6045 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6046 * the operator to attach to.
6047 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6048 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6049 * normal network selection next time.
6050 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006051 */
6052 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006053 public boolean setNetworkSelectionModeManual(
6054 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6056 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006057
6058 if (!isActiveSubscription(subId)) {
6059 return false;
6060 }
6061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 final long identity = Binder.clearCallingIdentity();
6063 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006064 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006066 if (DBG) {
6067 log("setNetworkSelectionModeManual: subId: " + subId
6068 + " operator: " + operatorInfo);
6069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006074 }
shilu84f6e8b2019-12-19 13:58:01 -08006075 /**
6076 * Get the manual network selection
6077 *
6078 * @param subId the id of the subscription.
6079 *
6080 * @return the previously saved user selected PLMN
6081 */
6082 @Override
6083 public String getManualNetworkSelectionPlmn(int subId) {
6084 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006085 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006086 mApp, subId, "getManualNetworkSelectionPlmn");
6087
6088 final long identity = Binder.clearCallingIdentity();
6089 try {
6090 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006091 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006092 }
6093
6094 final Phone phone = getPhone(subId);
6095 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006096 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006097 }
6098 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6099 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6100 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006105
6106 /**
6107 * Scans for available networks.
6108 */
6109 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006110 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6111 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6113 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006114 LocationAccessPolicy.LocationPermissionResult locationResult =
6115 LocationAccessPolicy.checkLocationPermission(mApp,
6116 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6117 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006118 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006119 .setCallingPid(Binder.getCallingPid())
6120 .setCallingUid(Binder.getCallingUid())
6121 .setMethod("getCellNetworkScanResults")
6122 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006123 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6124 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006125 .build());
6126 switch (locationResult) {
6127 case DENIED_HARD:
6128 throw new SecurityException("Not allowed to access scan results -- location");
6129 case DENIED_SOFT:
6130 return null;
6131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132
Pengquan Menga1bb6272018-09-06 09:59:22 -07006133 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 try {
6135 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006136 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 } finally {
6139 Binder.restoreCallingIdentity(identity);
6140 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006141 }
6142
6143 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006144 * Get the call forwarding info, given the call forwarding reason.
6145 */
6146 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006147 public void getCallForwarding(int subId, int callForwardingReason,
6148 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006149 enforceReadPrivilegedPermission("getCallForwarding");
6150 long identity = Binder.clearCallingIdentity();
6151 try {
6152 if (DBG) {
6153 log("getCallForwarding: subId " + subId
6154 + " callForwardingReason" + callForwardingReason);
6155 }
Hall Liu27d24262020-09-18 19:04:59 -07006156
6157 Phone phone = getPhone(subId);
6158 if (phone == null) {
6159 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006160 callback.onError(
6161 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006162 } catch (RemoteException e) {
6163 // ignore
6164 }
6165 return;
6166 }
6167
6168 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6169 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6170 @Override
6171 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6172 try {
6173 callback.onCallForwardingInfoAvailable(info);
6174 } catch (RemoteException e) {
6175 // ignore
6176 }
6177 }
6178
6179 @Override
6180 public void onError(int error) {
6181 try {
6182 callback.onError(error);
6183 } catch (RemoteException e) {
6184 // ignore
6185 }
6186 }
6187 });
6188 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
6193
6194 /**
6195 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6196 * reason, the number to forward, and the timeout before the forwarding is attempted.
6197 */
6198 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006199 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6200 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006201 enforceModifyPermission();
6202 long identity = Binder.clearCallingIdentity();
6203 try {
6204 if (DBG) {
6205 log("setCallForwarding: subId " + subId
6206 + " callForwardingInfo" + callForwardingInfo);
6207 }
Hall Liu27d24262020-09-18 19:04:59 -07006208
6209 Phone phone = getPhone(subId);
6210 if (phone == null) {
6211 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006212 callback.accept(
6213 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006214 } catch (RemoteException e) {
6215 // ignore
6216 }
6217 return;
6218 }
6219
6220 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6221 FunctionalUtils.ignoreRemoteException(callback::accept));
6222
6223 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
6227 }
6228
6229 /**
Hall Liu27d24262020-09-18 19:04:59 -07006230 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006231 */
6232 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006233 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006234 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006235 long identity = Binder.clearCallingIdentity();
6236 try {
Hall Liu27d24262020-09-18 19:04:59 -07006237 Phone phone = getPhone(subId);
6238 if (phone == null) {
6239 try {
6240 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6241 } catch (RemoteException e) {
6242 // ignore
6243 }
6244 return;
6245 }
SongFerngWang0e767992021-03-31 22:08:45 +08006246 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6247 PersistableBundle c = configManager.getConfigForSubId(subId);
6248 boolean requireUssd = c.getBoolean(
6249 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006250
Shuo Qian4a594052020-01-23 11:59:30 -08006251 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006252 if (requireUssd) {
6253 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6254 getSubscriptionCarrierId(subId));
6255 String newUssdCommand = "";
6256 try {
6257 newUssdCommand = carrierXmlParser.getFeature(
6258 CarrierXmlParser.FEATURE_CALL_WAITING)
6259 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6260 } catch (NullPointerException e) {
6261 loge("Failed to generate USSD number" + e);
6262 }
6263 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6264 mMainThreadHandler, callback, carrierXmlParser,
6265 CarrierXmlParser.SsEntry.SSAction.QUERY);
6266 final String ussdCommand = newUssdCommand;
6267 Executors.newSingleThreadExecutor().execute(() -> {
6268 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6269 });
6270 } else {
6271 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6272 callback::accept);
6273 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6274 }
Shuo Qian4a594052020-01-23 11:59:30 -08006275 } finally {
6276 Binder.restoreCallingIdentity(identity);
6277 }
6278 }
6279
6280 /**
Hall Liu27d24262020-09-18 19:04:59 -07006281 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006282 */
6283 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006284 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006285 enforceModifyPermission();
6286 long identity = Binder.clearCallingIdentity();
6287 try {
Hall Liu27d24262020-09-18 19:04:59 -07006288 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6289
6290 Phone phone = getPhone(subId);
6291 if (phone == null) {
6292 try {
6293 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6294 } catch (RemoteException e) {
6295 // ignore
6296 }
6297 return;
6298 }
6299
SongFerngWang0e767992021-03-31 22:08:45 +08006300 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6301 PersistableBundle c = configManager.getConfigForSubId(subId);
6302 boolean requireUssd = c.getBoolean(
6303 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006304
SongFerngWang0e767992021-03-31 22:08:45 +08006305 if (DBG) log("getCallWaitingStatus: subId " + subId);
6306 if (requireUssd) {
6307 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6308 getSubscriptionCarrierId(subId));
6309 CarrierXmlParser.SsEntry.SSAction ssAction =
6310 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6311 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6312 String newUssdCommand = "";
6313 try {
6314 newUssdCommand = carrierXmlParser.getFeature(
6315 CarrierXmlParser.FEATURE_CALL_WAITING)
6316 .makeCommand(ssAction, null);
6317 } catch (NullPointerException e) {
6318 loge("Failed to generate USSD number" + e);
6319 }
6320 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6321 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6322 final String ussdCommand = newUssdCommand;
6323 Executors.newSingleThreadExecutor().execute(() -> {
6324 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6325 });
6326 } else {
6327 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6328 FunctionalUtils.ignoreRemoteException(callback::accept));
6329
6330 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6331 }
Shuo Qian4a594052020-01-23 11:59:30 -08006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
6335 }
6336
6337 /**
yinxub1bed742017-04-17 11:45:04 -07006338 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006339 *
yinxub1bed742017-04-17 11:45:04 -07006340 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006341 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6342 * location related information which will be sent if the caller already possess
6343 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006344 * @param request contains the radio access networks with bands/channels to scan
6345 * @param messenger callback messenger for scan results or errors
6346 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006347 * @return the id of the requested scan which can be used to stop the scan.
6348 */
6349 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006350 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6351 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006352 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6354 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006355 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006356 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6357 if (!renounceFineLocationAccess) {
6358 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6359 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6360 .setCallingPackage(callingPackage)
6361 .setCallingFeatureId(callingFeatureId)
6362 .setCallingPid(Binder.getCallingPid())
6363 .setCallingUid(Binder.getCallingUid())
6364 .setMethod("requestNetworkScan")
6365 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6366 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6367 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6368 .build());
6369 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006370 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006371 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6372 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006373 if (e != null) {
6374 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6375 throw e;
6376 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006377 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006378 return TelephonyScanManager.INVALID_SCAN_ID;
6379 }
6380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 }
Hall Liu912dfd32019-04-25 14:02:26 -07006382 int callingUid = Binder.getCallingUid();
6383 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006387 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006388 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
yinxu504e1392017-04-12 16:03:22 -07006392 }
6393
Hall Liub2ac8ef2019-02-28 15:56:23 -08006394 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006395 NetworkScanRequest request, int subId, String callingPackage) {
6396 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006397 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6398 boolean hasNetworkScanPermission =
6399 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6400 == PERMISSION_GRANTED;
6401
6402 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6403 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6404 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006405 }
6406
6407 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6408 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006409 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6410 return new SecurityException("Specific channels must not be"
6411 + " scanned without location access.");
6412 }
6413 }
6414 }
6415
Hall Liub2ac8ef2019-02-28 15:56:23 -08006416 return null;
6417 }
6418
yinxu504e1392017-04-12 16:03:22 -07006419 /**
6420 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006421 *
6422 * @param subId id of the subscription
6423 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006424 */
6425 @Override
6426 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6428 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
Hall Liu912dfd32019-04-25 14:02:26 -07006430 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431 final long identity = Binder.clearCallingIdentity();
6432 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006433 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
yinxu504e1392017-04-12 16:03:22 -07006437 }
6438
6439 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006440 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006441 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006442 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006443 */
6444 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006445 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006446 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006447 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006448 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006452 if (DBG) log("getAllowedNetworkTypesBitmask");
6453 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6454 int networkTypesBitmask = (result != null ? result[0] : -1);
6455 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6456 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006460 }
6461
6462 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006463 * Get the allowed network types for certain reason.
6464 *
6465 * @param subId the id of the subscription.
6466 * @param reason the reason the allowed network type change is taking place
6467 * @return the allowed network types.
6468 */
6469 @Override
6470 public long getAllowedNetworkTypesForReason(int subId,
6471 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006472 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006473 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006474 final long identity = Binder.clearCallingIdentity();
6475 try {
6476 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6477 } finally {
6478 Binder.restoreCallingIdentity(identity);
6479 }
6480 }
6481
6482 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006483 * Enable/Disable E-UTRA-NR Dual Connectivity
6484 * @param subId subscription id of the sim card
6485 * @param nrDualConnectivityState expected NR dual connectivity state
6486 * This can be passed following states
6487 * <ol>
6488 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6489 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6490 * <li>Disable NR dual connectivity and force secondary cell to be released
6491 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6492 * </ol>
6493 * @return operation result.
6494 */
6495 @Override
6496 public int setNrDualConnectivityState(int subId,
6497 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6499 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006500 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006501 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6502 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6503 }
6504
Sooraj Sasindran37444802020-08-11 10:40:43 -07006505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6509 nrDualConnectivityState, subId,
6510 workSource);
6511 if (DBG) log("enableNRDualConnectivity result: " + result);
6512 return result;
6513 } finally {
6514 Binder.restoreCallingIdentity(identity);
6515 }
6516 }
6517
6518 /**
6519 * Is E-UTRA-NR Dual Connectivity enabled
6520 * @return true if dual connectivity is enabled else false
6521 */
6522 @Override
6523 public boolean isNrDualConnectivityEnabled(int subId) {
6524 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006525 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006526 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006527 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006528 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6529 return false;
6530 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6535 null, subId, workSource);
6536 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6537 return isEnabled;
6538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
6541 }
6542
6543 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006544 * Set the allowed network types of the device and
6545 * provide the reason triggering the allowed network change.
6546 *
6547 * @param subId the id of the subscription.
6548 * @param reason the reason the allowed network type change is taking place
6549 * @param allowedNetworkTypes the allowed network types.
6550 * @return true on success; false on any failure.
6551 */
6552 @Override
6553 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 @TelephonyManager.AllowedNetworkTypesReason int reason,
6555 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6557 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006558 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006559 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6560 return false;
6561 }
6562 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6563 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006564 return false;
6565 }
6566
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006567 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6568 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6569
6570
6571 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6572 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6573 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006574 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006575
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006576 final long identity = Binder.clearCallingIdentity();
6577 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006578 Boolean success = (Boolean) sendRequest(
6579 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6580 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6581
6582 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6583 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006584 } finally {
6585 Binder.restoreCallingIdentity(identity);
6586 }
6587 }
6588
6589 /**
Miaoa84611c2019-03-15 09:21:10 +08006590 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006591 *
Miaoa84611c2019-03-15 09:21:10 +08006592 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006593 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006594 * @hide
6595 */
6596 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006597 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006598 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006600 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 try {
Miaoa84611c2019-03-15 09:21:10 +08006602 if (phone != null) {
6603 return phone.hasMatchedTetherApnSetting();
6604 } else {
6605 return false;
6606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 } finally {
6608 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006609 }
Junda Liu475951f2014-11-07 16:45:03 -08006610 }
6611
6612 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006613 * Get the user enabled state of Mobile Data.
6614 *
6615 * TODO: remove and use isUserDataEnabled.
6616 * This can't be removed now because some vendor codes
6617 * calls through ITelephony directly while they should
6618 * use TelephonyManager.
6619 *
6620 * @return true on enabled
6621 */
6622 @Override
6623 public boolean getDataEnabled(int subId) {
6624 return isUserDataEnabled(subId);
6625 }
6626
6627 /**
6628 * Get whether mobile data is enabled per user setting.
6629 *
6630 * There are other factors deciding whether mobile data is actually enabled, but they are
6631 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006632 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6634 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006635 *
6636 * @return {@code true} if data is enabled else {@code false}
6637 */
6638 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006639 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006640 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006641 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006642 try {
6643 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6644 functionName);
6645 } catch (Exception e) {
6646 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6647 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006648 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006650 mApp, subId, functionName);
6651
Robert Greenwalt646120a2014-05-23 11:54:03 -07006652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653
6654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 int phoneId = mSubscriptionController.getPhoneId(subId);
6657 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6658 Phone phone = PhoneFactory.getPhone(phoneId);
6659 if (phone != null) {
6660 boolean retVal = phone.isUserDataEnabled();
6661 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6662 return retVal;
6663 } else {
6664 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6665 return false;
6666 }
6667 } finally {
6668 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006669 }
6670 }
6671
6672 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006673 * Checks if the device is capable of mobile data by considering whether whether the
6674 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6675 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006676 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006677 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006678 */
6679 @Override
6680 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006681 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 try {
6683 try {
6684 mApp.enforceCallingOrSelfPermission(
6685 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006686 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006687 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006688 try {
6689 mApp.enforceCallingOrSelfPermission(
6690 android.Manifest.permission.READ_PHONE_STATE,
6691 functionName);
6692 } catch (Exception e2) {
6693 mApp.enforceCallingOrSelfPermission(
6694 permission.READ_BASIC_PHONE_STATE, functionName);
6695 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006696 }
6697 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006698 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700
6701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 Phone phone = PhoneFactory.getPhone(phoneId);
6705 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006706 boolean retVal;
6707 if (phone.isUsingNewDataStack()) {
6708 retVal = phone.getDataNetworkController().getDataSettingsManager()
6709 .isDataEnabled();
6710 } else {
6711 retVal = phone.getDataEnabledSettings().isDataEnabled();
6712 }
6713 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 return retVal;
6715 } else {
6716 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6717 return false;
6718 }
6719 } finally {
6720 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006721 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006722 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006723
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006724 /**
6725 * Check if data is enabled for a specific reason
6726 * @param subId Subscription index
6727 * @param reason the reason the data enable change is taking place
6728 * @return {@code true} if the overall data is enabled; {@code false} if not.
6729 */
6730 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006731 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006732 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006733 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006735 try {
6736 mApp.enforceCallingOrSelfPermission(
6737 android.Manifest.permission.ACCESS_NETWORK_STATE,
6738 functionName);
6739 } catch (Exception e) {
6740 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6741 functionName);
6742 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006743 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006744 try {
6745 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006746 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006747 } catch (Exception e2) {
6748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006749 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006750 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006751 }
6752
6753
6754 final long identity = Binder.clearCallingIdentity();
6755 try {
6756 int phoneId = mSubscriptionController.getPhoneId(subId);
6757 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006758 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006759 + " reason=" + reason);
6760 }
6761 Phone phone = PhoneFactory.getPhone(phoneId);
6762 if (phone != null) {
6763 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006764 if (phone.isUsingNewDataStack()) {
6765 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006766 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006767 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6768 retVal = phone.isUserDataEnabled();
6769 } else {
6770 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6771 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006772 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006773 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006774 return retVal;
6775 } else {
6776 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006777 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006778 + subId + " retVal=false");
6779 }
6780 return false;
6781 }
6782 } finally {
6783 Binder.restoreCallingIdentity(identity);
6784 }
6785 }
6786
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006787 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006788 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006789 if (uid == Process.PHONE_UID) {
6790 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6791 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6793 }
6794
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006795 //load access rules from carrier configs, and check those as well: b/139133814
6796 SubscriptionController subController = SubscriptionController.getInstance();
6797 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6798 || subController == null) return privilegeFromSim;
6799
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006800 PackageManager pkgMgr = phone.getContext().getPackageManager();
6801 String[] packages = pkgMgr.getPackagesForUid(uid);
6802
6803 final long identity = Binder.clearCallingIdentity();
6804 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006805 int subId = phone.getSubId();
6806 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6807 // A test override is in place for the privileges for this subId, so don't try to
6808 // read the subscription privileges.
6809 return privilegeFromSim;
6810 }
6811 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006812 SubscriptionManager subManager = (SubscriptionManager)
6813 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6814 for (String pkg : packages) {
6815 if (subManager.canManageSubscription(subInfo, pkg)) {
6816 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6817 }
6818 }
6819 return privilegeFromSim;
6820 } finally {
6821 Binder.restoreCallingIdentity(identity);
6822 }
6823 }
6824
6825 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6826 String pkgName) {
6827 //load access rules from carrier configs, and check those as well: b/139133814
6828 SubscriptionController subController = SubscriptionController.getInstance();
6829 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6830 || subController == null) return privilegeFromSim;
6831
6832 final long identity = Binder.clearCallingIdentity();
6833 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006834 int subId = phone.getSubId();
6835 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6836 // A test override is in place for the privileges for this subId, so don't try to
6837 // read the subscription privileges.
6838 return privilegeFromSim;
6839 }
6840 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006841 SubscriptionManager subManager = (SubscriptionManager)
6842 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6843 return subManager.canManageSubscription(subInfo, pkgName)
6844 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
6847 }
6848 }
6849
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006850 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006851 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006852 // No permission needed; this only lets the caller inspect their own status.
6853 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006854 }
Junda Liu29340342014-07-10 15:23:27 -07006855
6856 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006857 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006858 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006859 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6860 }
6861
6862 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6863 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006864 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006865 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006866 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6867 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006868 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6869 if (cpt == null) {
6870 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006871 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6872 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006873 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006874 }
6875
6876 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006877 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006878 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006879 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006880 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006881 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006882 Phone phone = getPhone(subId);
6883 if (phone == null) {
6884 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6885 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6886 }
6887 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6888 if (cpt == null) {
6889 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006890 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6891 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006892 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006893 }
6894
6895 @Override
6896 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006897 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
6898 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006900 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006901 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006902 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6903 Phone phone = PhoneFactory.getPhone(phoneId);
6904 if (phone == null) {
6905 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006906 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006907 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6908 if (cpt == null) {
6909 continue;
6910 }
6911 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006912 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6913 break;
6914 }
6915 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006916 return result;
Junda Liu29340342014-07-10 15:23:27 -07006917 }
Derek Tan89e89d42014-07-08 17:00:10 -07006918
6919 @Override
Junda Liue64de782015-04-16 17:19:16 -07006920 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006921 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006922 Phone phone = PhoneFactory.getPhone(phoneId);
6923 if (phone == null) {
6924 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006925 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006926 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6927 if (cpt == null) {
6928 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006929 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006930 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006931 }
6932
Amith Yamasani6e118872016-02-19 12:53:51 -08006933 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006934 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006935 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006936 Phone phone = PhoneFactory.getPhone(phoneId);
6937 if (phone == null) {
6938 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006939 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006940 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6941 if (cpt == null) {
6942 return Collections.emptyList();
6943 }
6944 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006945 }
6946
chen xuf7e9fe82019-05-09 19:31:02 -07006947 @Override
6948 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006949 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006950 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006951 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006952 try {
6953 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6954 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6955 }
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006958 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006959 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006960 }
6961
Wink Savilleb564aae2014-10-23 10:18:09 -07006962 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006963 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006964 UiccPort port = phone == null ? null : phone.getUiccPort();
6965 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006966 return null;
6967 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006968 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006969 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006970 return null;
6971 }
6972 return iccId;
6973 }
6974
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006975 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006976 public void setCallComposerStatus(int subId, int status) {
6977 enforceModifyPermission();
6978
6979 final long identity = Binder.clearCallingIdentity();
6980 try {
6981 Phone phone = getPhone(subId);
6982 if (phone != null) {
6983 Phone defaultPhone = phone.getImsPhone();
6984 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6985 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6986 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006987 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6988 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006989 }
6990 }
Shuo Qian284ae752020-12-22 19:10:14 -08006991 } catch (ImsException e) {
6992 throw new ServiceSpecificException(e.getCode());
6993 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006994 Binder.restoreCallingIdentity(identity);
6995 }
6996 }
6997
6998 @Override
6999 public int getCallComposerStatus(int subId) {
7000 enforceReadPrivilegedPermission("getCallComposerStatus");
7001
7002 final long identity = Binder.clearCallingIdentity();
7003 try {
7004 Phone phone = getPhone(subId);
7005 if (phone != null) {
7006 Phone defaultPhone = phone.getImsPhone();
7007 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7008 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7009 return imsPhone.getCallComposerStatus();
7010 }
7011 }
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
7014 }
7015 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7016 }
7017
7018 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007019 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7020 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007021 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007022 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 final String iccId = getIccId(subId);
7027 final Phone phone = getPhone(subId);
7028 if (phone == null) {
7029 return false;
7030 }
7031 final String subscriberId = phone.getSubscriberId();
7032
7033 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007034 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 + subscriberId + " to " + number);
7036 }
7037
7038 if (TextUtils.isEmpty(iccId)) {
7039 return false;
7040 }
7041
7042 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7043
7044 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7045 if (alphaTag == null) {
7046 editor.remove(alphaTagPrefKey);
7047 } else {
7048 editor.putString(alphaTagPrefKey, alphaTag);
7049 }
7050
7051 // Record both the line number and IMSI for this ICCID, since we need to
7052 // track all merged IMSIs based on line number
7053 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7054 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7055 if (number == null) {
7056 editor.remove(numberPrefKey);
7057 editor.remove(subscriberPrefKey);
7058 } else {
7059 editor.putString(numberPrefKey, number);
7060 editor.putString(subscriberPrefKey, subscriberId);
7061 }
7062
7063 editor.commit();
7064 return true;
7065 } finally {
7066 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007067 }
Derek Tan7226c842014-07-02 17:42:23 -07007068 }
7069
7070 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007071 public String getLine1NumberForDisplay(int subId, String callingPackage,
7072 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007073 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007075 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007076 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007077 return null;
7078 }
Derek Tan97ebb422014-09-05 16:55:38 -07007079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 final long identity = Binder.clearCallingIdentity();
7081 try {
7082 String iccId = getIccId(subId);
7083 if (iccId != null) {
7084 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7085 if (DBG_MERGE) {
7086 log("getLine1NumberForDisplay returning "
7087 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7088 }
7089 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7092 return null;
7093 } finally {
7094 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007095 }
Derek Tan7226c842014-07-02 17:42:23 -07007096 }
7097
7098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007099 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7100 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007102 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007103 return null;
7104 }
Derek Tan97ebb422014-09-05 16:55:38 -07007105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 String iccId = getIccId(subId);
7109 if (iccId != null) {
7110 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7111 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7112 }
7113 return null;
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007116 }
Derek Tan7226c842014-07-02 17:42:23 -07007117 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007118
7119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007120 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7121 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007122 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7123 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007125 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007127 return null;
7128 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007129
Jordan Liub49b04b2019-05-06 14:45:15 -07007130 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7131 // the process, where TelephonyManager was instantiated.
7132 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007133 final long identity = Binder.clearCallingIdentity();
7134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007135 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 final TelephonyManager tele = TelephonyManager.from(context);
7137 final SubscriptionManager sub = SubscriptionManager.from(context);
7138
7139 // Figure out what subscribers are currently active
7140 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141
Jordan Liub49b04b2019-05-06 14:45:15 -07007142 // Only consider subs which match the current subId
7143 // This logic can be simplified. See b/131189269 for progress.
7144 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007145 activeSubscriberIds.add(tele.getSubscriberId(subId));
7146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147
7148 // First pass, find a number override for an active subscriber
7149 String mergeNumber = null;
7150 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7151 for (String key : prefs.keySet()) {
7152 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7153 final String subscriberId = (String) prefs.get(key);
7154 if (activeSubscriberIds.contains(subscriberId)) {
7155 final String iccId = key.substring(
7156 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7157 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7158 mergeNumber = (String) prefs.get(numberKey);
7159 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007160 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 + " for active subscriber " + subscriberId);
7162 }
7163 if (!TextUtils.isEmpty(mergeNumber)) {
7164 break;
7165 }
7166 }
7167 }
7168 }
7169
7170 // Shortcut when no active merged subscribers
7171 if (TextUtils.isEmpty(mergeNumber)) {
7172 return null;
7173 }
7174
7175 // Second pass, find all subscribers under that line override
7176 final ArraySet<String> result = new ArraySet<>();
7177 for (String key : prefs.keySet()) {
7178 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7179 final String number = (String) prefs.get(key);
7180 if (mergeNumber.equals(number)) {
7181 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7182 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7183 final String subscriberId = (String) prefs.get(subscriberKey);
7184 if (!TextUtils.isEmpty(subscriberId)) {
7185 result.add(subscriberId);
7186 }
7187 }
7188 }
7189 }
7190
7191 final String[] resultArray = result.toArray(new String[result.size()]);
7192 Arrays.sort(resultArray);
7193 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007194 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7196 }
7197 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007198 } finally {
7199 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007200 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007201 }
7202
7203 @Override
zoey chen38003472019-12-13 17:16:31 +08007204 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7205 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007206
7207 final long identity = Binder.clearCallingIdentity();
7208 try {
7209 final TelephonyManager telephonyManager = mApp.getSystemService(
7210 TelephonyManager.class);
7211 String subscriberId = telephonyManager.getSubscriberId(subId);
7212 if (subscriberId == null) {
7213 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007214 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007215 + subId);
7216 }
7217 return null;
7218 }
7219
7220 final SubscriptionInfo info = SubscriptionController.getInstance()
7221 .getSubscriptionInfo(subId);
7222 final ParcelUuid groupUuid = info.getGroupUuid();
7223 // If it doesn't belong to any group, return just subscriberId of itself.
7224 if (groupUuid == null) {
7225 return new String[]{subscriberId};
7226 }
7227
7228 // Get all subscriberIds from the group.
7229 final List<String> mergedSubscriberIds = new ArrayList<>();
7230 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007231 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007232 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007233 for (SubscriptionInfo subInfo : groupInfos) {
7234 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7235 if (subscriberId != null) {
7236 mergedSubscriberIds.add(subscriberId);
7237 }
7238 }
7239
7240 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243
7244 }
7245 }
7246
7247 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007248 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007249 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007250 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251
7252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 final Phone phone = getPhone(subId);
7255 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007259 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007260
7261 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007262 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007263 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7264 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007265 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7266 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007267
7268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 final Phone phone = getPhone(subId);
7271 if (phone == null) {
7272 return false;
7273 }
7274 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7275 cdmaNonRoamingList);
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007278 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007279 }
7280
7281 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007282 @Deprecated
7283 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7284 enforceModifyPermission();
7285
7286 int returnValue = 0;
7287 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007288 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007289 if(result.exception == null) {
7290 if (result.result != null) {
7291 byte[] responseData = (byte[])(result.result);
7292 if(responseData.length > oemResp.length) {
7293 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7294 responseData.length + "bytes. Buffer Size is " +
7295 oemResp.length + "bytes.");
7296 }
7297 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7298 returnValue = responseData.length;
7299 }
7300 } else {
7301 CommandException ex = (CommandException) result.exception;
7302 returnValue = ex.getCommandError().ordinal();
7303 if(returnValue > 0) returnValue *= -1;
7304 }
7305 } catch (RuntimeException e) {
7306 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7307 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7308 if(returnValue > 0) returnValue *= -1;
7309 }
7310
7311 return returnValue;
7312 }
7313
7314 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007315 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007316 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007317 try {
7318 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007319 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007320 mApp, phone.getSubId(), "getRadioAccessFamily");
7321 } catch (SecurityException e) {
7322 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7323 throw e;
7324 }
chen xub97461a2018-10-26 14:17:57 -07007325 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007326 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007327 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 final long identity = Binder.clearCallingIdentity();
7330 try {
chen xub97461a2018-10-26 14:17:57 -07007331 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007332 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007333 mApp, phone.getSubId(), "getRadioAccessFamily");
7334 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 } finally {
7336 Binder.restoreCallingIdentity(identity);
7337 }
chen xub97461a2018-10-26 14:17:57 -07007338 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007339 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007340
7341 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007342 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007343 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007344 try {
7345 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7346 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007347 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007348 }
7349 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007350 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007351 }
7352 RoleManager rm = mApp.getSystemService(RoleManager.class);
7353 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7354 if (!dialerRoleHolders.contains(callingPackage)) {
7355 throw new SecurityException("App must be the dialer role holder to"
7356 + " upload a call composer pic");
7357 }
7358
7359 Executors.newSingleThreadExecutor().execute(() -> {
7360 ByteArrayOutputStream output = new ByteArrayOutputStream(
7361 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7362 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7363 boolean readUntilEnd = false;
7364 int totalBytesRead = 0;
7365 byte[] buffer = new byte[16 * 1024];
7366 while (true) {
7367 int numRead;
7368 try {
7369 numRead = input.read(buffer);
7370 } catch (IOException e) {
7371 try {
7372 fd.checkError();
7373 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7374 null);
7375 } catch (IOException e1) {
7376 // This means that the other side closed explicitly with an error. If this
7377 // happens, log and ignore.
7378 loge("Remote end of call composer picture pipe closed: " + e1);
7379 }
7380 break;
7381 }
7382 if (numRead == -1) {
7383 readUntilEnd = true;
7384 break;
7385 }
7386 totalBytesRead += numRead;
7387 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7388 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7389 try {
7390 input.close();
7391 } catch (IOException e) {
7392 // ignore
7393 }
7394 break;
7395 }
7396 output.write(buffer, 0, numRead);
7397 }
7398 // Generally, the remote end will close the file descriptors. The only case where we
7399 // close is above, where the picture size is too big.
7400
7401 try {
7402 fd.checkError();
7403 } catch (IOException e) {
7404 loge("Remote end for call composer closed with an error: " + e);
7405 return;
7406 }
7407
Hall Liuaa4211e2021-01-20 15:43:39 -08007408 if (!readUntilEnd) {
7409 loge("Did not finish reading entire image; aborting");
7410 return;
7411 }
Hall Liu82694d52020-12-11 18:22:04 -08007412
Hall Liuaa4211e2021-01-20 15:43:39 -08007413 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7414 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7415 new CallComposerPictureTransfer.Factory() {},
7416 imageData,
7417 (result) -> {
7418 if (result.first != null) {
7419 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7420 Bundle outputResult = new Bundle();
7421 outputResult.putParcelable(
7422 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7423 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7424 outputResult);
7425 } else {
7426 callback.send(result.second, null);
7427 }
7428 }
7429 );
Hall Liu82694d52020-12-11 18:22:04 -08007430 });
7431 }
7432
7433 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007434 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437
7438 final long identity = Binder.clearCallingIdentity();
7439 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007440 ImsManager.getInstance(defaultPhone.getContext(),
7441 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 } finally {
7443 Binder.restoreCallingIdentity(identity);
7444 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007445 }
7446
7447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007448 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7451 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007452 return false;
7453 }
Svet Ganovb320e182015-04-16 12:30:10 -07007454
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455 final long identity = Binder.clearCallingIdentity();
7456 try {
7457 // Check the user preference and the system-level IMS setting. Even if the user has
7458 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7459 // In the long run, we may instead need to check if there exists a connection service
7460 // which can support video calling.
7461 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007462 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 return imsManager.isVtEnabledByPlatform()
7464 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7465 && imsManager.isVtEnabledByUser();
7466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007469 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007470
Andrew Leea1239f22015-03-02 17:44:07 -08007471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007472 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7473 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007475 mApp, subId, callingPackage, callingFeatureId,
7476 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 return false;
7478 }
7479
7480 final long identity = Binder.clearCallingIdentity();
7481 try {
7482 CarrierConfigManager configManager =
7483 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007484 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
Andrew Leea1239f22015-03-02 17:44:07 -08007489 }
7490
7491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007492 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007494 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 return false;
7496 }
7497
7498 final long identity = Binder.clearCallingIdentity();
7499 try {
7500 CarrierConfigManager configManager =
7501 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007502 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
Andrew Leea1239f22015-03-02 17:44:07 -08007507 }
7508
Andrew Lee9431b832015-03-09 18:46:45 -07007509 @Override
7510 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007511 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007512 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007513 }
7514
7515 @Override
7516 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 final long identity = Binder.clearCallingIdentity();
7518 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007519 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
Andrew Lee9431b832015-03-09 18:46:45 -07007523 }
7524
Hall Liuf6668912018-10-31 17:05:23 -07007525 /**
7526 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7527 * support for the feature and device firmware support.
7528 *
7529 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7530 */
7531 @Override
7532 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007534 final Phone phone = getPhone(subscriptionId);
7535 if (phone == null) {
7536 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7537 return false;
7538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7542 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 return isCarrierSupported && isDeviceSupported;
7545 } finally {
7546 Binder.restoreCallingIdentity(identity);
7547 }
Hall Liu98187582018-01-22 19:15:32 -08007548 }
7549
Hall Liuf6668912018-10-31 17:05:23 -07007550 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007551 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7552 * RTT setting, will return true if the device and carrier both support RTT.
7553 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007554 */
7555 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
7557 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007558 boolean isRttSupported = isRttSupported(subscriptionId);
7559 boolean isUserRttSettingOn = Settings.Secure.getInt(
7560 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7561 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7562 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7563 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007567 }
7568
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007569 @Deprecated
7570 @Override
7571 public String getDeviceId(String callingPackage) {
7572 return getDeviceIdWithFeature(callingPackage, null);
7573 }
7574
Sanket Padawe7310cc72015-01-14 09:53:20 -08007575 /**
7576 * Returns the unique device ID of phone, for example, the IMEI for
7577 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7578 *
7579 * <p>Requires Permission:
7580 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7581 */
7582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007583 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007584 try {
7585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7586 } catch (SecurityException se) {
7587 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7588 throw new SecurityException("Package " + callingPackage + " does not belong to "
7589 + Binder.getCallingUid());
7590 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007591 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007592 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007593 return null;
7594 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007595 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007596 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007597 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007598 return null;
7599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600
7601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 return phone.getDeviceId();
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
7606 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007607 }
7608
Ping Sunc67b7c22016-03-02 19:16:45 +08007609 /**
7610 * {@hide}
7611 * Returns the IMS Registration Status on a particular subid
7612 *
7613 * @param subId
7614 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007615 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007616 Phone phone = getPhone(subId);
7617 if (phone != null) {
7618 return phone.isImsRegistered();
7619 } else {
7620 return false;
7621 }
7622 }
7623
Santos Cordon7a1885b2015-02-03 11:15:19 -08007624 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007625 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007626 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007628 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007629 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7630 }
7631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
7636 }
7637 }
7638
7639 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007640 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007641 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007642 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007643 mApp,
7644 subscriptionId,
7645 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 Phone phone = getPhone(subscriptionId);
7649 if (phone == null) {
7650 return null;
7651 }
7652 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
7655 }
7656 }
7657
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007658 /**
7659 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007660 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007661 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 Phone phone = getPhone(subId);
7665 if (phone != null) {
7666 return phone.isWifiCallingEnabled();
7667 } else {
7668 return false;
7669 }
7670 } finally {
7671 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007672 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007673 }
7674
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007675 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007676 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007677 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007678 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 Phone phone = getPhone(subId);
7682 if (phone != null) {
7683 return phone.isVideoEnabled();
7684 } else {
7685 return false;
7686 }
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007689 }
7690 }
7691
7692 /**
7693 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7694 * defined in {@link ImsRegistrationImplBase}.
7695 */
7696 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 final long identity = Binder.clearCallingIdentity();
7698 try {
7699 Phone phone = getPhone(subId);
7700 if (phone != null) {
7701 return phone.getImsRegistrationTech();
7702 } else {
7703 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7704 }
7705 } finally {
7706 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007707 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007708 }
7709
Stuart Scott8eef64f2015-04-08 15:13:54 -07007710 @Override
7711 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007712 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007713 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7714 return;
7715 }
Kai Shif70f46f2021-03-03 13:59:46 -08007716 Phone defaultPhone = getDefaultPhone();
7717 if (defaultPhone != null) {
7718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7719 mApp, getDefaultPhone().getSubId(), "factoryReset");
7720 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007721 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007722
Svet Ganovcc087f82015-05-12 20:35:54 -07007723 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007724 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7725 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007726 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007727 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007728 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007729 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007730 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007731 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007732 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007733 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007734 // There has been issues when Sms raw table somehow stores orphan
7735 // fragments. They lead to garbled message when new fragments come
7736 // in and combined with those stale ones. In case this happens again,
7737 // user can reset all network settings which will clean up this table.
7738 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007739 // Clean up IMS settings as well here.
7740 int slotId = getSlotIndex(subId);
7741 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7742 ImsManager.getInstance(mApp, slotId).factoryReset();
7743 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007744
Kai Shif70f46f2021-03-03 13:59:46 -08007745 if (defaultPhone == null) {
7746 return;
7747 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007748 // Erase modem config if erase modem on network setting is enabled.
7749 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7750 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7751 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007752 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007753 }
Kai Shif70f46f2021-03-03 13:59:46 -08007754
7755 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007756 } finally {
7757 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007758 }
7759 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007760
SongFerngWangfd89b102021-05-27 22:44:54 +08007761 @VisibleForTesting
7762 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7763 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7764 return;
7765 }
7766 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7767 RILConstants.PREFERRED_NETWORK_MODE);
7768 SubscriptionManager.setSubscriptionProperty(subId,
7769 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7770 "user=" + defaultNetworkType);
7771 phone.loadAllowedNetworksFromSubscriptionDatabase();
7772 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7773 defaultNetworkType, null);
7774 }
7775
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007776 private void cleanUpSmsRawTable(Context context) {
7777 ContentResolver resolver = context.getContentResolver();
7778 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7779 resolver.delete(uri, null, null);
7780 }
7781
Narayan Kamath1c496c22015-04-16 14:40:19 +01007782 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007783 public String getSimLocaleForSubscriber(int subId) {
7784 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7785 final Phone phone = getPhone(subId);
7786 if (phone == null) {
7787 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007788 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 final long identity = Binder.clearCallingIdentity();
7791 try {
chen xu5d3637b2019-01-21 23:31:38 -08007792 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007793 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007794 if (info == null) {
7795 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7796 return null;
7797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 // Try and fetch the locale from the carrier properties or from the SIM language
7799 // preferences (EF-PL and EF-LI)...
7800 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007802 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7803 if (localeFromDefaultSim != null) {
7804 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7805 if (DBG) log("Using locale from subId: " + subId + " locale: "
7806 + localeFromDefaultSim);
7807 return localeFromDefaultSim.toLanguageTag();
7808 } else {
7809 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 }
7811 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 // The SIM language preferences only store a language (e.g. fr = French), not an
7814 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7815 // the SIM and carrier preferences does not include a country we add the country
7816 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007817 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007819 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 return mccLocale.toLanguageTag();
7821 }
7822
7823 if (DBG) log("No locale found - returning null");
7824 return null;
7825 } finally {
7826 Binder.restoreCallingIdentity(identity);
7827 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007828 }
7829
7830 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007831 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007832 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007833 }
7834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835 /**
7836 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7837 */
7838 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007839 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007840 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007841 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007842
Chenjie Yu1ba97252018-01-11 18:16:20 -08007843 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007844 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007845
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007846 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007847 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7848 * representing the state of the modem.
7849 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007850 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7851 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007852 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007853 */
7854 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007855 public void requestModemActivityInfo(ResultReceiver result) {
7856 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007857 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858
7859 final long identity = Binder.clearCallingIdentity();
7860 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007861 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007862 } finally {
7863 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007865 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007866
Siddharth Rayb8114062018-06-17 15:02:38 -07007867 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7868 // less than total activity duration.
7869 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7870 if (info == null) {
7871 return false;
7872 }
7873 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007874 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7875 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7876
Siddharth Rayb8114062018-06-17 15:02:38 -07007877 return (info.isValid()
7878 && (info.getSleepTimeMillis() <= activityDurationMs)
7879 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007880 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007881 && (totalTxTimeMs <= activityDurationMs));
7882 }
7883
Jack Yu85bd38a2015-11-09 11:34:32 -08007884 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007885 * Returns the service state information on specified subscription.
7886 */
7887 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007888 public ServiceState getServiceStateForSubscriber(int subId,
7889 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7890 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007892 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007893 return null;
7894 }
7895
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007896 boolean hasFinePermission = false;
7897 boolean hasCoarsePermission = false;
7898 if (!renounceFineLocationAccess) {
7899 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7900 LocationAccessPolicy.checkLocationPermission(mApp,
7901 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7902 .setCallingPackage(callingPackage)
7903 .setCallingFeatureId(callingFeatureId)
7904 .setCallingPid(Binder.getCallingPid())
7905 .setCallingUid(Binder.getCallingUid())
7906 .setMethod("getServiceStateForSubscriber")
7907 .setLogAsInfo(true)
7908 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7909 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7910 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7911 .build());
7912 hasFinePermission =
7913 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7914 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007915
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007916 if (!renounceCoarseLocationAccess) {
7917 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7918 LocationAccessPolicy.checkLocationPermission(mApp,
7919 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7920 .setCallingPackage(callingPackage)
7921 .setCallingFeatureId(callingFeatureId)
7922 .setCallingPid(Binder.getCallingPid())
7923 .setCallingUid(Binder.getCallingUid())
7924 .setMethod("getServiceStateForSubscriber")
7925 .setLogAsInfo(true)
7926 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7927 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7928 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7929 .build());
7930 hasCoarsePermission =
7931 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7932 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007933
Jack Yu479f40e2020-10-27 21:29:25 -07007934 final Phone phone = getPhone(subId);
7935 if (phone == null) {
7936 return null;
7937 }
7938
Jordan Liu0f2bc442020-11-18 16:47:37 -08007939 final long identity = Binder.clearCallingIdentity();
7940
Jack Yu479f40e2020-10-27 21:29:25 -07007941 boolean isCallingPackageDataService = phone.getDataServicePackages()
7942 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007944 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7945 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7946 Rlog.d(LOG_TAG,
7947 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7948 return null;
7949 }
7950
Hall Liuf19c44f2018-11-27 14:38:17 -08007951 ServiceState ss = phone.getServiceState();
7952
7953 // Scrub out the location info in ServiceState depending on what level of access
7954 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007955 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007956 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7957 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 } finally {
7959 Binder.restoreCallingIdentity(identity);
7960 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007962
7963 /**
7964 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7965 *
7966 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7967 * voicemail ringtone.
7968 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7969 * PhoneAccount.
7970 */
7971 @Override
7972 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7976 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007977 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007984 }
7985
7986 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007987 * Sets the per-account voicemail ringtone.
7988 *
7989 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7990 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7991 *
7992 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7993 * voicemail ringtone.
7994 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7995 * PhoneAccount.
7996 */
7997 @Override
7998 public void setVoicemailRingtoneUri(String callingPackage,
7999 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008002 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8003 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8005 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8006 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008
8009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008013 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 }
8015 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008018 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 }
8020
8021 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008022 * Returns whether vibration is set for voicemail notification in Phone settings.
8023 *
8024 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8025 * voicemail vibration setting.
8026 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8027 */
8028 @Override
8029 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8033 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008034 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008041 }
8042
Youhan Wange64578a2016-05-02 15:32:42 -07008043 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008044 * Sets the per-account voicemail vibration.
8045 *
8046 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8047 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8048 *
8049 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8050 * voicemail vibration setting.
8051 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8052 * specific PhoneAccount.
8053 */
8054 @Override
8055 public void setVoicemailVibrationEnabled(String callingPackage,
8056 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008057 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008059 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8060 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8062 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8063 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008064 }
8065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8069 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008070 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 }
8072 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008075 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008076 }
8077
8078 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008079 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8080 *
8081 * @throws SecurityException if the caller does not have the required permission
8082 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008083 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008084 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008085 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008086 }
8087
8088 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008089 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8090 * permission.
8091 *
8092 * @throws SecurityException if the caller does not have the required permission
8093 */
8094 private void enforceSendSmsPermission() {
8095 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8096 }
8097
8098 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008099 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008100 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008101 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008102 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008103 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008107 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 if (componentName == null) {
8109 throw new SecurityException(
8110 "Caller not current active visual voicemail package[null]");
8111 }
8112 String vvmPackage = componentName.getPackageName();
8113 if (!callingPackage.equals(vvmPackage)) {
8114 throw new SecurityException("Caller not current active visual voicemail package["
8115 + vvmPackage + "]");
8116 }
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008119 }
8120 }
8121
8122 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008123 * Return the application ID for the app type.
8124 *
8125 * @param subId the subscription ID that this request applies to.
8126 * @param appType the uicc app type.
8127 * @return Application ID for specificied app type, or null if no uicc.
8128 */
8129 @Override
8130 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008131 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008132 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133
8134 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008135 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 if (phone == null) {
8137 return null;
8138 }
8139 String aid = null;
8140 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008141 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142 .getApplicationByType(appType).getAid();
8143 } catch (Exception e) {
8144 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8145 }
8146 return aid;
8147 } finally {
8148 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008149 }
Youhan Wange64578a2016-05-02 15:32:42 -07008150 }
8151
Youhan Wang4001d252016-05-11 10:29:41 -07008152 /**
8153 * Return the Electronic Serial Number.
8154 *
8155 * @param subId the subscription ID that this request applies to.
8156 * @return ESN or null if error.
8157 */
8158 @Override
8159 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008160 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008161 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162
8163 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008164 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165 if (phone == null) {
8166 return null;
8167 }
8168 String esn = null;
8169 try {
8170 esn = phone.getEsn();
8171 } catch (Exception e) {
8172 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8173 }
8174 return esn;
8175 } finally {
8176 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008177 }
Youhan Wang4001d252016-05-11 10:29:41 -07008178 }
8179
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008180 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008181 * Return the Preferred Roaming List Version.
8182 *
8183 * @param subId the subscription ID that this request applies to.
8184 * @return PRLVersion or null if error.
8185 */
8186 @Override
8187 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008188 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190
8191 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008192 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193 if (phone == null) {
8194 return null;
8195 }
8196 String cdmaPrlVersion = null;
8197 try {
8198 cdmaPrlVersion = phone.getCdmaPrlVersion();
8199 } catch (Exception e) {
8200 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8201 }
8202 return cdmaPrlVersion;
8203 } finally {
8204 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008205 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008206 }
8207
8208 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008209 * Get snapshot of Telephony histograms
8210 * @return List of Telephony histograms
8211 * @hide
8212 */
8213 @Override
8214 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8216 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217
8218 final long identity = Binder.clearCallingIdentity();
8219 try {
8220 return RIL.getTelephonyRILTimingHistograms();
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008224 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008225
8226 /**
8227 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008228 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8229 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008230 * Require system privileges. In the future we may add this to carrier APIs.
8231 *
Michele Berionne482f8202018-11-27 18:57:59 -08008232 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008233 */
8234 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008235 @TelephonyManager.SetCarrierRestrictionResult
8236 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008237 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008238 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008239
Michele Berionne482f8202018-11-27 18:57:59 -08008240 if (carrierRestrictionRules == null) {
8241 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008242 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 final long identity = Binder.clearCallingIdentity();
8245 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008246 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008247 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008251 }
8252
8253 /**
8254 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008255 * Get the allowed carrier list and the excluded carrier list, including the priority between
8256 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008257 * Require system privileges. In the future we may add this to carrier APIs.
8258 *
Michele Berionne482f8202018-11-27 18:57:59 -08008259 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008260 */
8261 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008262 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008263 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265
8266 final long identity = Binder.clearCallingIdentity();
8267 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008268 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8269 if (response instanceof CarrierRestrictionRules) {
8270 return (CarrierRestrictionRules) response;
8271 }
8272 // Response is an Exception of some kind,
8273 // which is signalled to the user as a NULL retval
8274 return null;
8275 } catch (Exception e) {
8276 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8277 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008281 }
8282
fionaxu59545b42016-05-25 15:53:37 -07008283 /**
fionaxu59545b42016-05-25 15:53:37 -07008284 * Action set from carrier signalling broadcast receivers to enable/disable radio
8285 * @param subId the subscription ID that this action applies to.
8286 * @param enabled control enable or disable radio.
8287 * {@hide}
8288 */
8289 @Override
8290 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8291 enforceModifyPermission();
8292 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293
8294 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008295 if (phone == null) {
8296 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8297 return;
8298 }
8299 try {
8300 phone.carrierActionSetRadioEnabled(enabled);
8301 } catch (Exception e) {
8302 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 } finally {
8304 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008305 }
8306 }
8307
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008308 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008309 * Enable or disable Voice over NR (VoNR)
8310 * @param subId the subscription ID that this action applies to.
8311 * @param enabled enable or disable VoNR.
8312 * @return operation result.
8313 */
8314 @Override
8315 public int setVoNrEnabled(int subId, boolean enabled) {
8316 enforceModifyPermission();
8317 final Phone phone = getPhone(subId);
8318
8319 final long identity = Binder.clearCallingIdentity();
8320 if (phone == null) {
8321 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8322 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8323 }
8324
8325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8326 try {
8327 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8328 workSource);
8329 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008330
8331 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8332 if (DBG) {
8333 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8334 }
8335 SubscriptionManager.setSubscriptionProperty(
8336 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8337 (enabled ? "1" : "0"));
8338 }
8339
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008340 return result;
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
8344 }
8345
8346 /**
8347 * Is voice over NR enabled
8348 * @return true if VoNR is enabled else false
8349 */
8350 @Override
8351 public boolean isVoNrEnabled(int subId) {
8352 enforceReadPrivilegedPermission("isVoNrEnabled");
8353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8354 final long identity = Binder.clearCallingIdentity();
8355 try {
8356 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8357 null, subId, workSource);
8358 if (DBG) log("isVoNrEnabled: " + isEnabled);
8359 return isEnabled;
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
8363 }
8364
8365 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008366 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8367 * network status based on which carrier apps could apply actions accordingly,
8368 * enable/disable default url handler for example.
8369 *
8370 * @param subId the subscription ID that this action applies to.
8371 * @param report control start/stop reporting the default network status.
8372 * {@hide}
8373 */
8374 @Override
8375 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8376 enforceModifyPermission();
8377 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378
8379 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008380 if (phone == null) {
8381 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8382 return;
8383 }
8384 try {
8385 phone.carrierActionReportDefaultNetworkStatus(report);
8386 } catch (Exception e) {
8387 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 } finally {
8389 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008390 }
8391 }
8392
8393 /**
fionaxud9622282017-07-17 17:51:30 -07008394 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8395 * @param subId the subscription ID that this action applies to.
8396 * {@hide}
8397 */
8398 @Override
8399 public void carrierActionResetAll(int subId) {
8400 enforceModifyPermission();
8401 final Phone phone = getPhone(subId);
8402 if (phone == null) {
8403 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8404 return;
8405 }
8406 try {
8407 phone.carrierActionResetAll();
8408 } catch (Exception e) {
8409 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8410 }
8411 }
8412
8413 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008414 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8415 * bug report is being generated.
8416 */
8417 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008418 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008419 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8420 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008421 writer.println("Permission Denial: can't dump Phone from pid="
8422 + Binder.getCallingPid()
8423 + ", uid=" + Binder.getCallingUid()
8424 + "without permission "
8425 + android.Manifest.permission.DUMP);
8426 return;
8427 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008428 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008429 }
Jack Yueb89b242016-06-22 13:27:47 -07008430
Brad Ebingerdac2f002018-04-03 15:17:52 -07008431 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008432 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8433 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8434 @NonNull String[] args) {
8435 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8436 this, in.getFileDescriptor(), out.getFileDescriptor(),
8437 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008438 }
8439
Jack Yueb89b242016-06-22 13:27:47 -07008440 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008441 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008442 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008443 * @param reason the reason the data enable change is taking place
8444 * @param enabled True if enabling the data, otherwise disabling.
8445 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008446 */
8447 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008448 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008449 boolean enabled) {
8450 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8451 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8452 try {
8453 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008454 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008455 } catch (SecurityException se) {
8456 enforceModifyPermission();
8457 }
8458 } else {
8459 enforceModifyPermission();
8460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 Phone phone = getPhone(subId);
8465 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008466 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8467 phone.carrierActionSetMeteredApnsEnabled(enabled);
8468 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008469 if (phone.isUsingNewDataStack()) {
8470 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8471 } else {
8472 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8473 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008475 }
8476 } finally {
8477 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008478 }
8479 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008480
8481 /**
8482 * Get Client request stats
8483 * @return List of Client Request Stats
8484 * @hide
8485 */
8486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008487 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8488 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008490 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008491 return null;
8492 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008493 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 if (phone != null) {
8498 return phone.getClientRequestStats();
8499 }
8500
8501 return null;
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
8504 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008505 }
8506
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008507 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008508 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008509 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008510 }
Jack Yueb4124c2017-02-16 15:32:43 -08008511
8512 /**
Grace Chen70990072017-03-24 17:21:30 -07008513 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008514 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008515 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008516 * @param state State of SIM (power down, power up, pass through)
8517 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8518 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8519 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008520 *
8521 **/
8522 @Override
Grace Chen70990072017-03-24 17:21:30 -07008523 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008524 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008525 Phone phone = PhoneFactory.getPhone(slotIndex);
8526
vagdeviaf9a5b92018-08-15 16:01:53 -07008527 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008532 phone.setSimPowerState(state, null, workSource);
8533 }
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
8536 }
8537 }
8538
8539 /**
8540 * Set SIM card power state.
8541 *
8542 * @param slotIndex SIM slot id.
8543 * @param state State of SIM (power down, power up, pass through)
8544 * @param callback callback to trigger after success or failure
8545 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8546 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8547 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8548 *
8549 **/
8550 @Override
8551 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8552 IIntegerConsumer callback) {
8553 enforceModifyPermission();
8554 Phone phone = PhoneFactory.getPhone(slotIndex);
8555
8556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8557
8558 final long identity = Binder.clearCallingIdentity();
8559 try {
8560 if (phone != null) {
8561 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8562 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563 }
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008566 }
8567 }
Shuo Qiandd210312017-04-12 22:11:33 +00008568
Tyler Gunn65d45c22017-06-05 11:22:26 -07008569 private boolean isUssdApiAllowed(int subId) {
8570 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008571 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008572 if (configManager == null) {
8573 return false;
8574 }
8575 PersistableBundle pb = configManager.getConfigForSubId(subId);
8576 if (pb == null) {
8577 return false;
8578 }
8579 return pb.getBoolean(
8580 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8581 }
8582
Shuo Qiandd210312017-04-12 22:11:33 +00008583 /**
8584 * Check if phone is in emergency callback mode
8585 * @return true if phone is in emergency callback mode
8586 * @param subId sub id
8587 */
goneil9c5f4872017-12-05 14:07:56 -08008588 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008589 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008590 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008591 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008592
8593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 if (phone != null) {
8596 return phone.isInEcm();
8597 } else {
8598 return false;
8599 }
8600 } finally {
8601 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008602 }
8603 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008604
8605 /**
8606 * Get the current signal strength information for the given subscription.
8607 * Because this information is not updated when the device is in a low power state
8608 * it should not be relied-upon to be current.
8609 * @param subId Subscription index
8610 * @return the most recent cached signal strength info from the modem
8611 */
8612 @Override
8613 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 final long identity = Binder.clearCallingIdentity();
8615 try {
8616 Phone p = getPhone(subId);
8617 if (p == null) {
8618 return null;
8619 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008621 return p.getSignalStrength();
8622 } finally {
8623 Binder.restoreCallingIdentity(identity);
8624 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008625 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008626
Pengquan Meng77b7f132018-08-22 14:49:57 -07008627 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008628 * Get the current modem radio state for the given slot.
8629 * @param slotIndex slot index.
8630 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008631 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008632 * @return the current radio power state from the modem
8633 */
8634 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008635 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008636 Phone phone = PhoneFactory.getPhone(slotIndex);
8637 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8639 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008640 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8641 }
8642
8643 final long identity = Binder.clearCallingIdentity();
8644 try {
8645 return phone.getRadioPowerState();
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
8650 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8651 }
8652
8653 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008654 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8655 *
8656 * <p>Requires one of the following permissions:
8657 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008658 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008659 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8660 * privileges.
8661 *
8662 * @param subId subscription id
8663 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8664 * {@code false}.
8665 */
8666 @Override
8667 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008668 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008669 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008670 try {
8671 mApp.enforceCallingOrSelfPermission(
8672 android.Manifest.permission.ACCESS_NETWORK_STATE,
8673 functionName);
8674 } catch (Exception e) {
8675 mApp.enforceCallingOrSelfPermission(
8676 permission.READ_BASIC_PHONE_STATE, functionName);
8677 }
Shuo Qian093013d2020-08-13 15:42:55 -07008678 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008679 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008680 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008681 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008682
Pengquan Menga1bb6272018-09-06 09:59:22 -07008683 boolean isEnabled = false;
8684 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008685 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008686 Phone phone = getPhone(subId);
8687 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008688 } finally {
8689 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008691 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008692 }
8693
8694
8695 /**
8696 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8697 *
8698 * <p> Requires permission:
8699 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8700 * privileges.
8701 *
8702 * @param subId subscription id
8703 * @param isEnabled {@code true} means enable, {@code false} means disable.
8704 */
8705 @Override
8706 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8708 mApp, subId, "setDataRoamingEnabled");
8709
Pengquan Menga1bb6272018-09-06 09:59:22 -07008710 final long identity = Binder.clearCallingIdentity();
8711 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008712 Phone phone = getPhone(subId);
8713 if (phone != null) {
8714 phone.setDataRoamingEnabled(isEnabled);
8715 }
8716 } finally {
8717 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008718 }
8719 }
8720
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008721 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008722 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008723 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008724 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008725 mApp, subId, "isManualNetworkSelectionAllowed");
8726
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008727 boolean isAllowed = true;
8728 final long identity = Binder.clearCallingIdentity();
8729 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008730 Phone phone = getPhone(subId);
8731 if (phone != null) {
8732 isAllowed = phone.isCspPlmnEnabled();
8733 }
8734 } finally {
8735 Binder.restoreCallingIdentity(identity);
8736 }
8737 return isAllowed;
8738 }
8739
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008740 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8741 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008742 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008743 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008744 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008745 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8746 if (phone == null) {
8747 return false;
8748 }
8749 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8750 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8751 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008752 }
8753
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008754 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008755 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008756 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008757 mApp.getSystemService(AppOpsManager.class)
8758 .checkPackage(Binder.getCallingUid(), callingPackage);
8759
Jordan Liu1e142fc2019-04-22 15:10:43 -07008760 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008761 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008762 try {
8763 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008764 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008765 } catch (SecurityException e) {
8766 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8767 // has carrier privileges on an active UICC
8768 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8769 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008770 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008771 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008772 }
sandeepjsb6c87872021-09-27 15:34:44 +00008773 // checking compatibility, if calling app's target SDK is T and beyond.
8774 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8775 Binder.getCallingUid())) {
8776 isIccIdAccessRestricted = true;
8777 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008778 final long identity = Binder.clearCallingIdentity();
8779 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008780 UiccController uiccController = UiccController.getInstance();
8781 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008782 if (hasReadPermission) {
8783 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008784 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008785
8786 // Remove private info if the caller doesn't have access
8787 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8788 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008789 //setting the value after compatibility check
8790 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008791 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8792 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008793 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008794 if (card == null) {
8795 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008796 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008797 continue;
8798 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008799 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8800 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008801 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008802 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008803 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008804 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8805 for (UiccPortInfo portInfo : portInfos) {
8806 UiccPort port = uiccController.getUiccPortForSlot(
8807 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8808 if (port == null) {
8809 // assume no access if port is null
8810 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8811 continue;
8812 }
8813 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8814 uiccPortInfos.add(portInfo);
8815 } else {
8816 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8817 }
8818 }
8819 filteredInfos.add(new UiccCardInfo(
8820 cardInfo.isEuicc(),
8821 cardInfo.getCardId(),
8822 null,
8823 cardInfo.getPhysicalSlotIndex(),
8824 cardInfo.isRemovable(),
8825 cardInfo.isMultipleEnabledProfilesSupported(),
8826 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008827 }
8828 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 }
8833
sandeepjsb6c87872021-09-27 15:34:44 +00008834 /**
8835 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8836 * generally private and require carrier privileges to view.
8837 *
8838 * @hide
8839 */
8840 @NonNull
8841 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8842 List<UiccPortInfo> portinfo = new ArrayList<>();
8843 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8844 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8845 }
8846 return new UiccCardInfo(
8847 cardInfo.isEuicc(),
8848 cardInfo.getCardId(),
8849 null,
8850 cardInfo.getPhysicalSlotIndex(),
8851 cardInfo.isRemovable(),
8852 cardInfo.isMultipleEnabledProfilesSupported(),
8853 portinfo
8854 );
8855 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008856
sandeepjsb6c87872021-09-27 15:34:44 +00008857 /**
8858 * @hide
8859 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8860 * These values are generally private and require carrier privileges to view.
8861 */
8862 @NonNull
8863 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8864 return new UiccPortInfo(
8865 UiccPortInfo.ICCID_REDACTED,
8866 portInfo.getPortIndex(),
8867 portInfo.getLogicalSlotIndex(),
8868 portInfo.isActive()
8869 );
8870 }
8871 @Override
8872 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008873 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008874 mApp.getSystemService(AppOpsManager.class)
8875 .checkPackage(Binder.getCallingUid(), callingPackage);
8876
8877 boolean hasReadPermission = false;
8878 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008879
8880 try {
8881 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8882 hasReadPermission = true;
8883 } catch (SecurityException e) {
8884 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8885 // has carrier privileges on an active UICC
8886 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8887 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8888 hasReadPermission = true;
8889 }
8890 }
8891
8892 // checking compatibility, if calling app's target SDK is T and beyond.
8893 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8894 Binder.getCallingUid())) {
8895 isLogicalSlotAccessRestricted = true;
8896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 final long identity = Binder.clearCallingIdentity();
8898 try {
8899 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008900 if (slots == null || slots.length == 0) {
8901 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008902 return null;
8903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008904 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8905 for (int i = 0; i < slots.length; i++) {
8906 UiccSlot slot = slots[i];
8907 if (slot == null) {
8908 continue;
8909 }
8910
Jordan Liu7be7e652019-05-06 18:55:02 +00008911 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 UiccCard card = slot.getUiccCard();
8913 if (card != null) {
8914 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008915 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008916 cardId = slot.getEid();
8917 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008918 // If cardId is null, use iccId of default port as cardId. Check if has
8919 // read permission otherwise set to null.(card is null which means no
8920 // carrier permission)
8921 cardId = hasReadPermission ? slot.getIccId(
8922 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008924 }
8925
Jordan Liu857451f2019-05-09 16:35:35 -07008926 if (cardId != null) {
8927 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8928 // if cardId is an EID, it's all digits so this is fine
8929 cardId = IccUtils.stripTrailingFs(cardId);
8930 }
8931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008932 int cardState = 0;
8933 switch (slot.getCardState()) {
8934 case CARDSTATE_ABSENT:
8935 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8936 break;
8937 case CARDSTATE_PRESENT:
8938 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8939 break;
8940 case CARDSTATE_ERROR:
8941 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8942 break;
8943 case CARDSTATE_RESTRICTED:
8944 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8945 break;
8946 default:
8947 break;
8948
8949 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008950 List<UiccPortInfo> portInfos = new ArrayList<>();
8951 int[] portIndexes = slot.getPortList();
8952 for (int portIdx : portIndexes) {
8953 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8954 callingPackage, hasReadPermission));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008955 portInfos.add(new UiccPortInfo(iccId, portIdx,
8956 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008958 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959 slot.isEuicc(),
8960 cardId,
8961 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008962 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008963 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008964 //setting the value after compatibility check
8965 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008966 }
8967 return infos;
8968 } finally {
8969 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008970 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008971 }
8972
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008973 /* Returns null if doesn't have read permission or carrier privilege access. */
8974 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8975 boolean hasReadPermission) {
8976 String iccId = slot.getIccId(portIndex);
8977 if (hasReadPermission) { // if has read permission
8978 return iccId;
8979 } else {
8980 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8981 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8982 // if no read permission, checking carrier privilege access
8983 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8984 return iccId;
8985 }
8986 }
8987 }
8988 // No read permission or carrier privilege access.
8989 return UiccPortInfo.ICCID_REDACTED;
8990 }
8991
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008992 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008993 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008994 public boolean switchSlots(int[] physicalSlots) {
8995 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008996
8997 final long identity = Binder.clearCallingIdentity();
8998 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008999 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9000 for (int i = 0; i < physicalSlots.length; i++) {
9001 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9002 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9003 physicalSlots[i], i));
9004 }
9005 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009006 } finally {
9007 Binder.restoreCallingIdentity(identity);
9008 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009009 }
Jack Yu4c988042018-02-27 15:30:01 -08009010
9011 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009012 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9013 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9014 enforceModifyPermission();
9015
9016 final long identity = Binder.clearCallingIdentity();
9017 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009018 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009019 } finally {
9020 Binder.restoreCallingIdentity(identity);
9021 }
9022 }
9023
9024 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009025 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009026 final long identity = Binder.clearCallingIdentity();
9027 try {
9028 return UiccController.getInstance().getCardIdForDefaultEuicc();
9029 } finally {
9030 Binder.restoreCallingIdentity(identity);
9031 }
9032 }
9033
Pengquan Meng85728fb2018-03-12 16:31:21 -07009034 /**
goneil47ffb6e2018-04-06 15:40:58 -07009035 * A test API to reload the UICC profile.
9036 *
9037 * <p>Requires that the calling app has permission
9038 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9039 * @hide
9040 */
9041 @Override
9042 public void refreshUiccProfile(int subId) {
9043 enforceModifyPermission();
9044
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 Phone phone = getPhone(subId);
9048 if (phone == null) {
9049 return;
9050 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009051 UiccPort uiccPort = phone.getUiccPort();
9052 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009053 return;
9054 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009055 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009056 if (uiccProfile == null) {
9057 return;
9058 }
9059 uiccProfile.refresh();
9060 } finally {
9061 Binder.restoreCallingIdentity(identity);
9062 }
9063 }
9064
9065 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009066 * Returns false if the mobile data is disabled by default, otherwise return true.
9067 */
9068 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009069 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009070 }
9071
9072 /**
9073 * Returns true if the data roaming is enabled by default, i.e the system property
9074 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9075 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9076 */
9077 private boolean getDefaultDataRoamingEnabled(int subId) {
9078 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009079 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009080 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009081 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9082 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9083 return isDataRoamingEnabled;
9084 }
9085
9086 /**
9087 * Returns the default network type for the given {@code subId}, if the default network type is
9088 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9089 */
9090 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009091 List<Integer> list = TelephonyProperties.default_network();
9092 int phoneId = mSubscriptionController.getPhoneId(subId);
9093 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9094 return list.get(phoneId);
9095 }
9096 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009097 }
fionaxua13278b2018-03-21 00:08:13 -07009098
9099 @Override
9100 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009101 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009102 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009103
9104 final long identity = Binder.clearCallingIdentity();
9105 try {
9106 final Phone phone = getPhone(subId);
9107 if (phone == null) {
9108 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9109 return;
9110 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009111 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9112 if (cpt != null) {
9113 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9114 }
9115 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009116 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9117 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009118 if (carrierPrivilegeRules == null) {
9119 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9120 } else {
9121 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9122 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009123 } finally {
9124 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009125 }
fionaxua13278b2018-03-21 00:08:13 -07009126 }
9127
9128 @Override
9129 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009130 enforceReadPrivilegedPermission("getCarrierIdListVersion");
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("getCarrierIdListVersion fails with invalid subId: " + subId);
9137 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9138 }
9139 return phone.getCarrierIdListVersion();
9140 } finally {
9141 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009142 }
fionaxua13278b2018-03-21 00:08:13 -07009143 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009144
9145 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009146 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9147 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009149 mApp, subId, callingPackage, callingFeatureId,
9150 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009151 return -1;
9152 }
9153
9154 final long identity = Binder.clearCallingIdentity();
9155 try {
9156 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
9159 }
9160 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009161
9162 @Override
9163 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009164 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009165 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009166 mApp, subId, "getCdmaRoamingMode");
9167
9168 final long identity = Binder.clearCallingIdentity();
9169 try {
9170 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
9175
9176 @Override
9177 public boolean setCdmaRoamingMode(int subId, int mode) {
9178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9179 mApp, subId, "setCdmaRoamingMode");
9180
9181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 }
9188
9189 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009190 public int getCdmaSubscriptionMode(int subId) {
9191 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009192 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009193 mApp, subId, "getCdmaSubscriptionMode");
9194
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9198 } finally {
9199 Binder.restoreCallingIdentity(identity);
9200 }
9201 }
9202
9203 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009204 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9206 mApp, subId, "setCdmaSubscriptionMode");
9207
9208 final long identity = Binder.clearCallingIdentity();
9209 try {
9210 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009215
sqianc5eccab2018-10-19 18:46:41 -07009216 @Override
sqian8c685422019-02-22 15:55:18 -08009217 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009218 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009220 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9221 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009222 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9223 }
9224 final long identity = Binder.clearCallingIdentity();
9225 try {
sqian854d44b2018-12-12 16:48:18 -08009226 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9227 for (Phone phone: PhoneFactory.getPhones()) {
9228 if (phone.getEmergencyNumberTracker() != null
9229 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9230 emergencyNumberListInternal.put(
9231 phone.getSubId(),
9232 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9233 }
sqian11b7a0e2018-12-05 18:48:28 -08009234 }
sqian854d44b2018-12-12 16:48:18 -08009235 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009236 } finally {
9237 Binder.restoreCallingIdentity(identity);
9238 }
sqianc5eccab2018-10-19 18:46:41 -07009239 }
9240
9241 @Override
sqian8c685422019-02-22 15:55:18 -08009242 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009243 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009244 if (!exactMatch) {
9245 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009246 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009247 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009248 }
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
sqian854d44b2018-12-12 16:48:18 -08009251 for (Phone phone: PhoneFactory.getPhones()) {
9252 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009253 && phone.getEmergencyNumberTracker()
9254 .isEmergencyNumber(number, exactMatch)) {
9255 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009256 }
sqian11b7a0e2018-12-05 18:48:28 -08009257 }
9258 return false;
9259 } finally {
9260 Binder.restoreCallingIdentity(identity);
9261 }
9262 }
9263
sqianf4ca7ed2019-01-15 18:32:07 -08009264 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009265 * Start emergency callback mode for GsmCdmaPhone for testing.
9266 */
9267 @Override
9268 public void startEmergencyCallbackMode() {
9269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9270 "startEmergencyCallbackMode");
9271 enforceModifyPermission();
9272 final long identity = Binder.clearCallingIdentity();
9273 try {
9274 for (Phone phone : PhoneFactory.getPhones()) {
9275 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9276 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9277 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9278 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9279 gsmCdmaPhone.obtainMessage(
9280 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9281 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9282 }
9283 }
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
9289 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009290 * Update emergency number list for test mode.
9291 */
9292 @Override
9293 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9294 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9295 "updateEmergencyNumberListTestMode");
9296
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
9299 for (Phone phone: PhoneFactory.getPhones()) {
9300 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9301 if (tracker != null) {
9302 tracker.executeEmergencyNumberTestModeCommand(action, num);
9303 }
9304 }
9305 } finally {
9306 Binder.restoreCallingIdentity(identity);
9307 }
9308 }
9309
9310 /**
9311 * Get the full emergency number list for test mode.
9312 */
9313 @Override
9314 public List<String> getEmergencyNumberListTestMode() {
9315 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9316 "getEmergencyNumberListTestMode");
9317
9318 final long identity = Binder.clearCallingIdentity();
9319 try {
9320 Set<String> emergencyNumbers = new HashSet<>();
9321 for (Phone phone: PhoneFactory.getPhones()) {
9322 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9323 if (tracker != null) {
9324 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9325 emergencyNumbers.add(num.getNumber());
9326 }
9327 }
9328 }
9329 return new ArrayList<>(emergencyNumbers);
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
9334
chen xud6b45bd2018-10-30 22:27:10 -07009335 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009336 public int getEmergencyNumberDbVersion(int subId) {
9337 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9338
9339 final long identity = Binder.clearCallingIdentity();
9340 try {
9341 final Phone phone = getPhone(subId);
9342 if (phone == null) {
9343 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9344 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9345 }
9346 return phone.getEmergencyNumberDbVersion();
9347 } finally {
9348 Binder.restoreCallingIdentity(identity);
9349 }
9350 }
9351
9352 @Override
9353 public void notifyOtaEmergencyNumberDbInstalled() {
9354 enforceModifyPermission();
9355
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
9358 for (Phone phone: PhoneFactory.getPhones()) {
9359 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9360 if (tracker != null) {
9361 tracker.updateOtaEmergencyNumberDatabase();
9362 }
9363 }
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
9368
9369 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009370 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009371 enforceActiveEmergencySessionPermission();
9372
9373 final long identity = Binder.clearCallingIdentity();
9374 try {
9375 for (Phone phone: PhoneFactory.getPhones()) {
9376 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9377 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009378 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9379 }
9380 }
9381 } finally {
9382 Binder.restoreCallingIdentity(identity);
9383 }
9384 }
9385
9386 @Override
9387 public void resetOtaEmergencyNumberDbFilePath() {
9388 enforceActiveEmergencySessionPermission();
9389
9390 final long identity = Binder.clearCallingIdentity();
9391 try {
9392 for (Phone phone: PhoneFactory.getPhones()) {
9393 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9394 if (tracker != null) {
9395 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009396 }
9397 }
9398 } finally {
9399 Binder.restoreCallingIdentity(identity);
9400 }
9401 }
9402
9403 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009404 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9405 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9406 Phone phone = getPhone(subId);
9407 if (phone == null) {
9408 return null;
9409 }
9410 final long identity = Binder.clearCallingIdentity();
9411 try {
9412 UiccProfile profile = UiccController.getInstance()
9413 .getUiccProfileForPhone(phone.getPhoneId());
9414 if (profile != null) {
9415 return profile.getCertsFromCarrierPrivilegeAccessRules();
9416 }
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 return null;
9421 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009422
9423 /**
9424 * Enable or disable a modem stack.
9425 */
9426 @Override
9427 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9428 enforceModifyPermission();
9429
9430 final long identity = Binder.clearCallingIdentity();
9431 try {
9432 Phone phone = PhoneFactory.getPhone(slotIndex);
9433 if (phone == null) {
9434 return false;
9435 } else {
9436 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9437 }
9438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441 }
Michelecea4cf22018-12-21 15:00:11 -08009442
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009443 /**
9444 * Whether a modem stack is enabled or not.
9445 */
9446 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009447 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9448 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009449 Phone phone = PhoneFactory.getPhone(slotIndex);
9450 if (phone == null) return false;
9451
9452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009453 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9454 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009455 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9456 }
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009460 try {
9461 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9462 } catch (NoSuchElementException ex) {
9463 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9464 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009465 } finally {
9466 Binder.restoreCallingIdentity(identity);
9467 }
9468 }
9469
Michelecea4cf22018-12-21 15:00:11 -08009470 @Override
Michele0ea7d782019-03-19 14:58:42 -07009471 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009472 enforceModifyPermission();
9473
9474 final long identity = Binder.clearCallingIdentity();
9475 try {
9476 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009477 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009478 .commit();
9479 } finally {
9480 Binder.restoreCallingIdentity(identity);
9481 }
9482 }
9483
9484 @Override
Michele0ea7d782019-03-19 14:58:42 -07009485 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009486 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009488 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9489 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009490 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009491 }
Michelecea4cf22018-12-21 15:00:11 -08009492
9493 final long identity = Binder.clearCallingIdentity();
9494 try {
Michele0ea7d782019-03-19 14:58:42 -07009495 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009496 } finally {
9497 Binder.restoreCallingIdentity(identity);
9498 }
9499 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009500
Michele0ea7d782019-03-19 14:58:42 -07009501 @TelephonyManager.IsMultiSimSupportedResult
9502 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009503 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9504 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9505 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009506 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9507 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009508 }
9509 // Check if the hardware supports multisim functionality. If usage of multisim is not
9510 // supported by the modem, indicate that it is restricted.
9511 PhoneCapability staticCapability =
9512 mPhoneConfigurationManager.getStaticPhoneCapability();
9513 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009514 loge("isMultiSimSupportedInternal: no static configuration available");
9515 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009516 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009517 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009518 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9519 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009520 }
9521 // Check if support of multiple SIMs is restricted by carrier
9522 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009523 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009524 }
9525
Michele0ea7d782019-03-19 14:58:42 -07009526 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009527 }
9528
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009529 /**
9530 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009531 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9532 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9533 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009534 * @param numOfSims number of active sims we want to switch to
9535 */
9536 @Override
9537 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009538 if (numOfSims == 1) {
9539 enforceModifyPermission();
9540 } else {
9541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9542 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9543 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009544 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009545
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009546 try {
Michele30b57b22019-03-01 12:01:14 -08009547 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009548 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009549 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9550 return;
9551 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009552 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009558 @Override
9559 public boolean isApplicationOnUicc(int subId, int appType) {
9560 enforceReadPrivilegedPermission("isApplicationOnUicc");
9561 Phone phone = getPhone(subId);
9562 if (phone == null) {
9563 return false;
9564 }
9565 final long identity = Binder.clearCallingIdentity();
9566 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009567 UiccPort uiccPort = phone.getUiccPort();
9568 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009569 return false;
9570 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009571 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009572 if (uiccProfile == null) {
9573 return false;
9574 }
9575 if (TelephonyManager.APPTYPE_SIM <= appType
9576 && appType <= TelephonyManager.APPTYPE_ISIM) {
9577 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9578 }
9579 return false;
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
9582 }
9583 }
9584
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009585 /**
chen xub4baa772019-04-03 10:23:41 -07009586 * Get whether making changes to modem configurations will trigger reboot.
9587 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009588 */
9589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009590 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9591 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009593 mApp, subId, callingPackage, callingFeatureId,
9594 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009595 return false;
9596 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009597 final long identity = Binder.clearCallingIdentity();
9598 try {
9599 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
9604
Nathan Harold29f5f052019-02-15 13:41:57 -08009605 private void updateModemStateMetrics() {
9606 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9607 // TODO: check the state for each modem if the api is ready.
9608 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9609 }
9610
Pengquan Meng3889a572019-01-23 11:16:29 -08009611 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009612 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009613 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009614 // Verify that the callingPackage belongs to the calling UID
9615 mApp.getSystemService(AppOpsManager.class)
9616 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009617 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009618 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009619 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009620 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9621 if (slotInfos != null) {
9622 for (int i = 0; i < slotInfos.length; i++) {
9623 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9624 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9625 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9626 portInfo.getLogicalSlotIndex()));
9627 }
9628 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009629 }
9630 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009631 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009632 } finally {
9633 Binder.restoreCallingIdentity(identity);
9634 }
9635 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009636
9637 /**
9638 * Get the IRadio HAL Version
9639 */
9640 @Override
9641 public int getRadioHalVersion() {
9642 Phone phone = getDefaultPhone();
9643 if (phone == null) return -1;
9644 HalVersion hv = phone.getHalVersion();
9645 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9646 return hv.major * 100 + hv.minor;
9647 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009648
9649 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009650 * Get the current calling package name.
9651 * @return the current calling package name
9652 */
9653 @Override
9654 public String getCurrentPackageName() {
9655 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9656 }
9657
9658 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009659 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9660 * corresponding network requests on a subId.
9661 *
9662 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009663 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009664 * 2) APN is un-metered for this subscription, or
9665 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009666 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009667 *
9668 * @return whether data is allowed for a apn type.
9669 *
9670 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009671 */
9672 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009673 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009674 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9675 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009676
9677 // Now that all security checks passes, perform the operation as ourselves.
9678 final long identity = Binder.clearCallingIdentity();
9679 try {
9680 Phone phone = getPhone(subId);
9681 if (phone == null) return false;
9682
Jack Yu41407ee2019-05-13 16:54:09 -07009683 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009684 boolean isDataEnabled;
9685 if (phone.isUsingNewDataStack()) {
9686 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9687 } else {
9688 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9689 }
9690 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009691 } finally {
9692 Binder.restoreCallingIdentity(identity);
9693 }
9694 }
9695
9696 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009697 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009698 enforceReadPrivilegedPermission("isApnMetered");
9699
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 true; // By default return true.
9705
Jack Yu41407ee2019-05-13 16:54:09 -07009706 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009707 } finally {
9708 Binder.restoreCallingIdentity(identity);
9709 }
9710 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009711
9712 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009713 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9714 int subscriptionId, IBooleanConsumer resultCallback) {
9715 enforceModifyPermission();
9716 long token = Binder.clearCallingIdentity();
9717 try {
9718 Phone phone = getPhone(subscriptionId);
9719 if (phone == null) {
9720 try {
9721 if (resultCallback != null) {
9722 resultCallback.accept(false);
9723 }
9724 } catch (RemoteException e) {
9725 // ignore
9726 }
9727 return;
9728 }
9729 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9730 Pair.create(specifiers, (x) -> {
9731 try {
9732 if (resultCallback != null) {
9733 resultCallback.accept(x);
9734 }
9735 } catch (RemoteException e) {
9736 // ignore
9737 }
9738 });
9739 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9740 } finally {
9741 Binder.restoreCallingIdentity(token);
9742 }
9743 }
9744
9745 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009746 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9747 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009748 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009749 mApp, subId, "getSystemSelectionChannels");
9750 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9751 final long identity = Binder.clearCallingIdentity();
9752 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009753 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9754 if (result instanceof IllegalStateException) {
9755 throw (IllegalStateException) result;
9756 }
9757 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009758 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9759 return specifiers;
9760 } finally {
9761 Binder.restoreCallingIdentity(identity);
9762 }
9763 }
9764
9765 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009766 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009767 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009768 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9769 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9770 if (iccRecords == null) {
9771 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9772 return false;
9773 }
9774 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9775 }
9776
9777 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009778 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9779 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009780 if (callingPackage == null) {
9781 callingPackage = getCurrentPackageName();
9782 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009783 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9784 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009785 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9786 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009787 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9788 }
9789 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9790 Intent intent = new Intent();
9791 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9792 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9793 // Bring up choose default SMS subscription dialog right now
9794 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9795 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9796 mApp.startActivity(intent);
9797 }
chen xud5ca2d52019-05-28 15:20:57 -07009798
9799 @Override
9800 public String getMmsUAProfUrl(int subId) {
9801 //TODO investigate if this API should require proper permission check in R b/133791609
9802 final long identity = Binder.clearCallingIdentity();
9803 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009804 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9805 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9806 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9807 return carrierUAProfUrl;
9808 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009809 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9810 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 }
9815
9816 @Override
9817 public String getMmsUserAgent(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 carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9822 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9823 if (!TextUtils.isEmpty(carrierUserAgent)) {
9824 return carrierUserAgent;
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);
chen xud5ca2d52019-05-28 15:20:57 -07009828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
Jack Yub07d4972019-05-28 16:12:25 -07009832
9833 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009834 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9835 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009836
Jack Yub07d4972019-05-28 16:12:25 -07009837 final long identity = Binder.clearCallingIdentity();
9838 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009839 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009840 if (phone == null) return false;
9841
Hall Liua62f5da2020-09-25 10:42:19 -07009842 switch (policy) {
9843 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009844 if (phone.isUsingNewDataStack()) {
9845 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9846 } else {
9847 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9848 }
Hall Liua62f5da2020-09-25 10:42:19 -07009849 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009850 if (phone.isUsingNewDataStack()) {
9851 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9852 } else {
9853 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9854 }
Hall Liua62f5da2020-09-25 10:42:19 -07009855 default:
9856 throw new IllegalArgumentException(policy + " is not a valid policy");
9857 }
Jack Yub07d4972019-05-28 16:12:25 -07009858 } finally {
9859 Binder.restoreCallingIdentity(identity);
9860 }
9861 }
9862
9863 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009864 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009865 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009866 enforceModifyPermission();
9867
changbettyd5c246e2019-12-24 15:40:37 +08009868 final long identity = Binder.clearCallingIdentity();
9869 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009870 Phone phone = getPhone(subscriptionId);
9871 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009872
Hall Liua62f5da2020-09-25 10:42:19 -07009873 switch (policy) {
9874 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009875 if (phone.isUsingNewDataStack()) {
9876 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9877 } else {
9878 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9879 }
Hall Liua62f5da2020-09-25 10:42:19 -07009880 break;
9881 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009882 if (phone.isUsingNewDataStack()) {
9883 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9884 } else {
9885 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9886 }
Hall Liua62f5da2020-09-25 10:42:19 -07009887 break;
9888 default:
9889 throw new IllegalArgumentException(policy + " is not a valid policy");
9890 }
changbettyd5c246e2019-12-24 15:40:37 +08009891 } finally {
9892 Binder.restoreCallingIdentity(identity);
9893 }
9894 }
9895
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009896 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009897 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009898 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9899 * otherwise.
9900 */
9901 @Override
9902 public void setCepEnabled(boolean isCepEnabled) {
9903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9904
9905 final long identity = Binder.clearCallingIdentity();
9906 try {
9907 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9908 for (Phone phone : PhoneFactory.getPhones()) {
9909 Phone defaultPhone = phone.getImsPhone();
9910 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9911 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9912 ImsPhoneCallTracker imsPhoneCallTracker =
9913 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9914 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9915 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9916 + imsPhone.getMsisdn());
9917 }
9918 }
9919 } finally {
9920 Binder.restoreCallingIdentity(identity);
9921 }
9922 }
allenwtsu46dcc572020-01-08 18:24:03 +08009923
9924 /**
9925 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9926 *
9927 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9928 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9929 * before being read.
9930 */
9931 @Override
9932 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9933 isCompressed) {
9934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9935 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009936 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9937 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9938 }
9939 if (!isImsAvailableOnDevice()) {
9940 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9941 "IMS not available on device.");
9942 }
9943
9944 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009945 try {
Hui Wang761a6682020-10-31 05:12:53 +00009946 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9947 } finally {
9948 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009949 }
9950 }
zoey chene02881a2019-12-30 16:11:23 +08009951
9952 @Override
9953 public boolean isIccLockEnabled(int subId) {
9954 enforceReadPrivilegedPermission("isIccLockEnabled");
9955
9956 // Now that all security checks passes, perform the operation as ourselves.
9957 final long identity = Binder.clearCallingIdentity();
9958 try {
9959 Phone phone = getPhone(subId);
9960 if (phone != null && phone.getIccCard() != null) {
9961 return phone.getIccCard().getIccLockEnabled();
9962 } else {
9963 return false;
9964 }
9965 } finally {
9966 Binder.restoreCallingIdentity(identity);
9967 }
9968 }
9969
9970 /**
9971 * Set the ICC pin lock enabled or disabled.
9972 *
9973 * @return an integer representing the status of IccLock enabled or disabled in the following
9974 * three cases:
9975 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9976 * successfully.
9977 * - Positive number and zero for remaining password attempts.
9978 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9979 *
9980 */
9981 @Override
9982 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9983 enforceModifyPermission();
9984
9985 Phone phone = getPhone(subId);
9986 if (phone == null) {
9987 return 0;
9988 }
9989 // Now that all security checks passes, perform the operation as ourselves.
9990 final long identity = Binder.clearCallingIdentity();
9991 try {
9992 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9993 new Pair<Boolean, String>(enabled, password), phone, null);
9994 return attemptsRemaining;
9995
9996 } catch (Exception e) {
9997 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9998 } finally {
9999 Binder.restoreCallingIdentity(identity);
10000 }
10001 return 0;
10002 }
10003
10004 /**
10005 * Change the ICC password used in ICC pin lock.
10006 *
10007 * @return an integer representing the status of IccLock changed in the following three cases:
10008 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10009 * - Positive number and zero for remaining password attempts.
10010 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10011 *
10012 */
10013 @Override
10014 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10015 enforceModifyPermission();
10016
10017 Phone phone = getPhone(subId);
10018 if (phone == null) {
10019 return 0;
10020 }
10021 // Now that all security checks passes, perform the operation as ourselves.
10022 final long identity = Binder.clearCallingIdentity();
10023 try {
10024 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10025 new Pair<String, String>(oldPassword, newPassword), phone, null);
10026 return attemptsRemaining;
10027
10028 } catch (Exception e) {
10029 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10030 } finally {
10031 Binder.restoreCallingIdentity(identity);
10032 }
10033 return 0;
10034 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010035
10036 /**
10037 * Request for receiving user activity notification
10038 */
10039 @Override
10040 public void requestUserActivityNotification() {
10041 if (!mNotifyUserActivity.get()
10042 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10043 mNotifyUserActivity.set(true);
10044 }
10045 }
10046
10047 /**
10048 * Called when userActivity is signalled in the power manager.
10049 * This is safe to call from any thread, with any window manager locks held or not.
10050 */
10051 @Override
10052 public void userActivity() {
10053 // ***************************************
10054 // * Inherited from PhoneWindowManager *
10055 // ***************************************
10056 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10057 // WITH ITS LOCKS HELD.
10058 //
10059 // This code must be VERY careful about the locks
10060 // it acquires.
10061 // In fact, the current code acquires way too many,
10062 // and probably has lurking deadlocks.
10063
10064 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10065 throw new SecurityException("Only the OS may call notifyUserActivity()");
10066 }
10067
10068 if (mNotifyUserActivity.getAndSet(false)) {
10069 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10070 USER_ACTIVITY_NOTIFICATION_DELAY);
10071 }
10072 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010073
10074 @Override
10075 public boolean canConnectTo5GInDsdsMode() {
10076 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10077 }
Jack Yud10cdd42020-09-28 20:28:01 -070010078
10079 @Override
10080 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10081 String callingFeatureId) {
10082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10083 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10084 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10085 }
10086
10087 Phone phone = getPhone(subId);
10088 if (phone == null) {
10089 throw new RuntimeException("phone is not available");
10090 }
10091 // Now that all security checks passes, perform the operation as ourselves.
10092 final long identity = Binder.clearCallingIdentity();
10093 try {
10094 return phone.getEquivalentHomePlmns();
10095 } finally {
10096 Binder.restoreCallingIdentity(identity);
10097 }
10098 }
Daniel Bright59e67312020-11-13 11:49:37 -080010099
10100 @Override
10101 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010102 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10103 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010104 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010105 if (radioInterfaceCapabilities == null) {
10106 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010107 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010108 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010109 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010110
Hui Wang641e81c2020-10-12 12:14:23 -070010111 @Override
10112 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10113 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010114 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10115 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10116 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10117 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10118 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010119 if (DBG) {
10120 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10121 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10122 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10123 }
10124
10125 if (!SubscriptionManager.isValidSubscriptionId(subId)
10126 || appType < TelephonyManager.APPTYPE_UNKNOWN
10127 || appType > TelephonyManager.APPTYPE_ISIM
10128 || nafUrl == null || securityProtocol == null || callback == null) {
10129 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10130 if (callback != null) {
10131 try {
10132 callback.onAuthenticationFailure(
10133 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10134 } catch (RemoteException exception) {
10135 log("Fail to notify onAuthenticationFailure due to " + exception);
10136 }
10137 return;
10138 }
10139 }
10140
10141 final long token = Binder.clearCallingIdentity();
10142 try {
10143 getGbaManager(subId).bootstrapAuthenticationRequest(
10144 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10145 forceBootStrapping, callback));
10146 } finally {
10147 Binder.restoreCallingIdentity(token);
10148 }
10149 }
10150
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010151 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010152 * Attempts to set the radio power state for all phones for thermal reason.
10153 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010154 * requested radio power state will actually be set. See {@link
10155 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10156 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010157 * @param enable {@code true} if trying to turn radio on.
10158 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10159 * false}.
10160 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010161 private boolean setRadioPowerForThermal(boolean enable) {
10162 boolean isPhoneAvailable = false;
10163 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10164 Phone phone = PhoneFactory.getPhone(i);
10165 if (phone != null) {
10166 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10167 isPhoneAvailable = true;
10168 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010169 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010170
10171 // return true if successfully informed the phone object about the thermal radio power
10172 // request.
10173 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010174 }
10175
10176 private int handleDataThrottlingRequest(int subId,
10177 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010178 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10179 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10180 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10181 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10182 throw new IllegalArgumentException("modem does not support data throttling");
10183 }
10184
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010185 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10186 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010187 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010188 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10189 }
10190
10191 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10192
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010193 if (isDataThrottlingSupported) {
10194 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010195 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010196 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10197 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10198 } else if (thermalMitigationResult
10199 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010200 log("Modem likely does not support data throttling on secondary carrier. Data " +
10201 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10202 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010203 }
10204 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010205 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010206
10207 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010208 }
10209
Jack Nudelman644b91a2021-03-12 14:09:48 -080010210 private static List<String> getThermalMitigationAllowlist(Context context) {
10211 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10212 for (String pckg : context.getResources()
10213 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10214 sThermalMitigationAllowlistedPackages.add(pckg);
10215 }
10216 }
10217
10218 return sThermalMitigationAllowlistedPackages;
10219 }
10220
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010221 private boolean isAnyPhoneInEmergencyState() {
10222 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10223 if (tm.isInEmergencyCall()) {
10224 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10225 return true;
10226 }
10227 for (Phone phone : PhoneFactory.getPhones()) {
10228 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10229 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10230 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10231 + phone.isInEcm());
10232 return true;
10233 }
10234 }
10235
10236 return false;
10237 }
10238
Jack Nudelman644b91a2021-03-12 14:09:48 -080010239 /**
10240 * Used by shell commands to add an authorized package name for thermal mitigation.
10241 * @param packageName name of package to be allowlisted
10242 * @param context
10243 */
10244 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10245 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10246 sThermalMitigationAllowlistedPackages.add(packageName);
10247 }
10248
10249 /**
10250 * Used by shell commands to remove an authorized package name for thermal mitigation.
10251 * @param packageName name of package to remove from allowlist
10252 * @param context
10253 */
10254 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10255 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10256 sThermalMitigationAllowlistedPackages.remove(packageName);
10257 }
10258
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010259 /**
10260 * Thermal mitigation request to control functionalities at modem.
10261 *
10262 * @param subId the id of the subscription.
10263 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010264 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010265 *
10266 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10267 */
10268 @Override
10269 @ThermalMitigationResult
10270 public int sendThermalMitigationRequest(
10271 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010272 ThermalMitigationRequest thermalMitigationRequest,
10273 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010274 enforceModifyPermission();
10275
Jack Nudelman644b91a2021-03-12 14:09:48 -080010276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10277 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10278 .contains(callingPackage)) {
10279 throw new SecurityException("Calling package must be configured in the device config. "
10280 + "calling package: " + callingPackage);
10281 }
10282
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010283 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10284 final long identity = Binder.clearCallingIdentity();
10285
10286 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10287 try {
10288 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10289 switch (thermalMitigationAction) {
10290 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10291 thermalMitigationResult =
10292 handleDataThrottlingRequest(subId,
10293 thermalMitigationRequest.getDataThrottlingRequest());
10294 break;
10295 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10296 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10297 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10298 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10299 }
10300
10301 // Ensure that radio is on. If not able to power on due to phone being
10302 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010303 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010304 thermalMitigationResult =
10305 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10306 break;
10307 }
10308
10309 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10310 false);
10311 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10312 break;
10313 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10314 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10315 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10316 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10317 }
10318
10319 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10320 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010321 Phone phone = getPhone(subId);
10322 if (phone == null) {
10323 thermalMitigationResult =
10324 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10325 break;
10326 }
10327
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010328 TelephonyConnectionService service =
10329 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010330 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010331 Log.e(LOG_TAG, "An emergency call is pending");
10332 thermalMitigationResult =
10333 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10334 break;
10335 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010336 thermalMitigationResult =
10337 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10338 break;
10339 }
10340 } else {
10341 thermalMitigationResult =
10342 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10343 break;
10344 }
10345
10346 // Turn radio off. If not able to power off due to phone being unavailable,
10347 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010348 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010349 thermalMitigationResult =
10350 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10351 break;
10352 }
10353 thermalMitigationResult =
10354 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10355 break;
10356 default:
10357 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10358 + "not exist. Requested action: " + thermalMitigationAction);
10359 }
10360 } catch (IllegalArgumentException e) {
10361 throw e;
10362 } catch (Exception e) {
10363 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10364 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10365 } finally {
10366 Binder.restoreCallingIdentity(identity);
10367 }
10368
10369 if (DBG) {
10370 log("thermalMitigationRequest returning with thermalMitigationResult: "
10371 + thermalMitigationResult);
10372 }
10373
10374 return thermalMitigationResult;
10375 }
Hui Wang641e81c2020-10-12 12:14:23 -070010376
10377 /**
10378 * Set the GbaService Package Name that Telephony will bind to.
10379 *
10380 * @param subId The sim that the GbaService is associated with.
10381 * @param packageName The name of the package to be replaced with.
10382 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10383 */
10384 @Override
10385 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10386 enforceModifyPermission();
10387
10388 final long identity = Binder.clearCallingIdentity();
10389 try {
10390 return getGbaManager(subId).overrideServicePackage(packageName);
10391 } finally {
10392 Binder.restoreCallingIdentity(identity);
10393 }
10394 }
10395
10396 /**
10397 * Return the package name of the currently bound GbaService.
10398 *
10399 * @param subId The sim that the GbaService is associated with.
10400 * @return the package name of the GbaService configuration, null if GBA is not supported.
10401 */
10402 @Override
10403 public String getBoundGbaService(int subId) {
10404 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10405
10406 final long identity = Binder.clearCallingIdentity();
10407 try {
10408 return getGbaManager(subId).getServicePackage();
10409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
10412 }
10413
10414 /**
10415 * Set the release time for telephony to unbind GbaService.
10416 *
10417 * @param subId The sim that the GbaService is associated with.
10418 * @param interval The release time to unbind GbaService by millisecond.
10419 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10420 */
10421 @Override
10422 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10423 enforceModifyPermission();
10424
10425 final long identity = Binder.clearCallingIdentity();
10426 try {
10427 return getGbaManager(subId).overrideReleaseTime(interval);
10428 } finally {
10429 Binder.restoreCallingIdentity(identity);
10430 }
10431 }
10432
10433 /**
10434 * Return the release time for telephony to unbind GbaService.
10435 *
10436 * @param subId The sim that the GbaService is associated with.
10437 * @return The release time to unbind GbaService by millisecond.
10438 */
10439 @Override
10440 public int getGbaReleaseTime(int subId) {
10441 enforceReadPrivilegedPermission("getGbaReleaseTime");
10442
10443 final long identity = Binder.clearCallingIdentity();
10444 try {
10445 return getGbaManager(subId).getReleaseTime();
10446 } finally {
10447 Binder.restoreCallingIdentity(identity);
10448 }
10449 }
10450
10451 private GbaManager getGbaManager(int subId) {
10452 GbaManager instance = GbaManager.getInstance(subId);
10453 if (instance == null) {
10454 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10455 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10456 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10457 }
10458 return instance;
10459 }
Hui Wang761a6682020-10-31 05:12:53 +000010460
10461 /**
10462 * indicate whether the device and the carrier can support
10463 * RCS VoLTE single registration.
10464 */
10465 @Override
10466 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010467 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10468 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10469 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10470 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010471
10472 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10473 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10474 }
10475
10476 final long identity = Binder.clearCallingIdentity();
10477 try {
10478 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10479 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010480 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10481 if (isCapable != null) {
10482 return isCapable;
10483 }
Hui Wang761a6682020-10-31 05:12:53 +000010484 }
Hui Wang67af90e2021-06-04 16:57:15 -070010485 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10486 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010487 } finally {
10488 Binder.restoreCallingIdentity(identity);
10489 }
10490 }
10491
10492 /**
10493 * Register RCS provisioning callback.
10494 */
10495 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010496 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010497 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010498 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010499 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010500 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10501 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010502
10503 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10504 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10505 }
10506 if (!isImsAvailableOnDevice()) {
10507 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10508 "IMS not available on device.");
10509 }
10510
10511 final long identity = Binder.clearCallingIdentity();
10512 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010513 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010514 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010515 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10516 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010517 }
Hui Wang761a6682020-10-31 05:12:53 +000010518 } finally {
10519 Binder.restoreCallingIdentity(identity);
10520 }
10521 }
10522
10523 /**
10524 * Unregister RCS provisioning callback.
10525 */
10526 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010527 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010528 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010529 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010530 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010531 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10532 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010533
10534 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10535 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10536 }
10537 if (!isImsAvailableOnDevice()) {
10538 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10539 "IMS not available on device.");
10540 }
10541
10542 final long identity = Binder.clearCallingIdentity();
10543 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010544 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010545 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010546 } finally {
10547 Binder.restoreCallingIdentity(identity);
10548 }
10549 }
10550
10551 /**
10552 * trigger RCS reconfiguration.
10553 */
10554 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010555 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10556 "triggerRcsReconfiguration",
10557 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010558
10559 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10560 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10561 }
10562 if (!isImsAvailableOnDevice()) {
10563 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10564 "IMS not available on device.");
10565 }
10566
10567 final long identity = Binder.clearCallingIdentity();
10568 try {
10569 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10570 } finally {
10571 Binder.restoreCallingIdentity(identity);
10572 }
10573 }
10574
10575 /**
10576 * Provide the client configuration parameters of the RCS application.
10577 */
10578 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010579 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10580 "setRcsClientConfiguration",
10581 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010582
10583 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10584 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10585 }
10586 if (!isImsAvailableOnDevice()) {
10587 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10588 "IMS not available on device.");
10589 }
10590
10591 final long identity = Binder.clearCallingIdentity();
10592
10593 try {
10594 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10595 if (configBinder == null) {
10596 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010597 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10598 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010599 } else {
10600 configBinder.setRcsClientConfiguration(rcc);
10601 }
joonhunshin3e154242021-09-17 06:33:39 +000010602
10603 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10604 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010605 } catch (RemoteException e) {
10606 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010607 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10608 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010609 } finally {
10610 Binder.restoreCallingIdentity(identity);
10611 }
10612 }
10613
10614 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010615 * Enables or disables the test mode for RCS VoLTE single registration.
10616 */
10617 @Override
10618 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10619 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10620 "setRcsSingleRegistrationTestModeEnabled");
10621
10622 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10623 }
10624
10625 /**
10626 * Gets the test mode for RCS VoLTE single registration.
10627 */
10628 @Override
10629 public boolean getRcsSingleRegistrationTestModeEnabled() {
10630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10631 "getRcsSingleRegistrationTestModeEnabled");
10632
10633 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10634 }
10635
10636 /**
Hui Wang761a6682020-10-31 05:12:53 +000010637 * Overrides the config of RCS VoLTE single registration enabled for the device.
10638 */
10639 @Override
10640 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10642 "setDeviceSingleRegistrationEnabledOverride");
10643 enforceModifyPermission();
10644
10645 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10646 : Boolean.parseBoolean(enabledStr);
10647 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010648 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010649 }
10650
10651 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010652 * Sends a device to device communication message. Only usable via shell.
10653 * @param message message to send.
10654 * @param value message value.
10655 */
10656 @Override
10657 public void sendDeviceToDeviceMessage(int message, int value) {
10658 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010659 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010660 enforceModifyPermission();
10661
10662 final long identity = Binder.clearCallingIdentity();
10663 try {
10664 TelephonyConnectionService service =
10665 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10666 if (service == null) {
10667 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10668 return;
10669 }
10670 service.sendTestDeviceToDeviceMessage(message, value);
10671 } finally {
10672 Binder.restoreCallingIdentity(identity);
10673 }
10674 }
10675
Tyler Gunnbabbda02021-02-10 11:05:02 -080010676 /**
10677 * Sets the specified device to device transport active.
10678 * @param transport The transport to set active.
10679 */
10680 @Override
10681 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10682 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10683 "setActiveDeviceToDeviceTransport");
10684 enforceModifyPermission();
10685
10686 final long identity = Binder.clearCallingIdentity();
10687 try {
10688 TelephonyConnectionService service =
10689 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10690 if (service == null) {
10691 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10692 return;
10693 }
10694 service.setActiveDeviceToDeviceTransport(transport);
10695 } finally {
10696 Binder.restoreCallingIdentity(identity);
10697 }
10698 }
Tyler Gunn92479152021-01-20 16:30:10 -080010699
Tyler Gunnd4339262021-05-03 14:46:49 -070010700 @Override
10701 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10702 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10703 "setDeviceToDeviceForceEnabled");
10704
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 Arrays.stream(PhoneFactory.getPhones()).forEach(
10708 p -> {
10709 Phone thePhone = p.getImsPhone();
10710 if (thePhone != null && thePhone instanceof ImsPhone) {
10711 ImsPhone imsPhone = (ImsPhone) thePhone;
10712 CallTracker tracker = imsPhone.getCallTracker();
10713 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10714 ImsPhoneCallTracker imsPhoneCallTracker =
10715 (ImsPhoneCallTracker) tracker;
10716 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10717 }
10718 }
10719 }
10720 );
10721 } finally {
10722 Binder.restoreCallingIdentity(identity);
10723 }
10724 }
10725
Tyler Gunn92479152021-01-20 16:30:10 -080010726 /**
Hui Wang761a6682020-10-31 05:12:53 +000010727 * Gets the config of RCS VoLTE single registration enabled for the device.
10728 */
10729 @Override
10730 public boolean getDeviceSingleRegistrationEnabled() {
10731 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10732 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10733 }
10734
10735 /**
10736 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10737 */
10738 @Override
10739 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10740 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10741 "setCarrierSingleRegistrationEnabledOverride");
10742 enforceModifyPermission();
10743
10744 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10745 : Boolean.parseBoolean(enabledStr);
10746 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10747 subId, enabled);
10748 }
10749
10750 /**
10751 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10752 */
10753 @Override
10754 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10755 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10756 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10757 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010758
10759 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010760 * Overrides the ims feature validation result
10761 */
10762 @Override
10763 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10764 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10765 "setImsFeatureValidationOverride");
10766
10767 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10768 : Boolean.parseBoolean(enabledStr);
10769 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10770 subId, enabled);
10771 }
10772
10773 /**
10774 * Gets the ims feature validation override value
10775 */
10776 @Override
10777 public boolean getImsFeatureValidationOverride(int subId) {
10778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10779 "getImsFeatureValidationOverride");
10780 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10781 }
10782
10783 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010784 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10785 * their mobile plan.
10786 */
10787 @Override
10788 public String getMobileProvisioningUrl() {
10789 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10790 final long identity = Binder.clearCallingIdentity();
10791 try {
10792 return getDefaultPhone().getMobileProvisioningUrl();
10793 } finally {
10794 Binder.restoreCallingIdentity(identity);
10795 }
10796 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010797
James.cf Linbcdf8b32021-01-14 16:44:13 +080010798 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010799 * Get the EAB contact from the EAB database.
10800 */
10801 @Override
10802 public String getContactFromEab(String contact) {
10803 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10804 enforceModifyPermission();
10805 final long identity = Binder.clearCallingIdentity();
10806 try {
10807 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10808 } finally {
10809 Binder.restoreCallingIdentity(identity);
10810 }
10811 }
10812
10813 /**
Calvin Pana1434322021-07-01 19:27:01 +080010814 * Get the EAB capability from the EAB database.
10815 */
10816 @Override
10817 public String getCapabilityFromEab(String contact) {
10818 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10819 enforceModifyPermission();
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10823 } finally {
10824 Binder.restoreCallingIdentity(identity);
10825 }
10826 }
10827
10828 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010829 * Remove the EAB contacts from the EAB database.
10830 */
10831 @Override
10832 public int removeContactFromEab(int subId, String contacts) {
10833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10834 enforceModifyPermission();
10835 final long identity = Binder.clearCallingIdentity();
10836 try {
10837 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10838 } finally {
10839 Binder.restoreCallingIdentity(identity);
10840 }
10841 }
10842
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010843 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010844 public boolean getDeviceUceEnabled() {
10845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10846 final long identity = Binder.clearCallingIdentity();
10847 try {
10848 return mApp.getDeviceUceEnabled();
10849 } finally {
10850 Binder.restoreCallingIdentity(identity);
10851 }
10852 }
10853
10854 @Override
10855 public void setDeviceUceEnabled(boolean isEnabled) {
10856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 mApp.setDeviceUceEnabled(isEnabled);
10860 } finally {
10861 Binder.restoreCallingIdentity(identity);
10862 }
10863 }
10864
Brad Ebinger14d467f2021-02-12 06:18:28 +000010865 /**
10866 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10867 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10868 */
10869 // Used for SHELL command only right now.
10870 @Override
10871 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10872 List<String> featureTags) {
10873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10874 "addUceRegistrationOverrideShell");
10875 final long identity = Binder.clearCallingIdentity();
10876 try {
10877 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10878 new ArraySet<>(featureTags));
10879 } catch (ImsException e) {
10880 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10881 } finally {
10882 Binder.restoreCallingIdentity(identity);
10883 }
10884 }
10885
10886 /**
10887 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10888 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10889 */
10890 // Used for SHELL command only right now.
10891 @Override
10892 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10893 List<String> featureTags) {
10894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10895 "removeUceRegistrationOverrideShell");
10896 final long identity = Binder.clearCallingIdentity();
10897 try {
10898 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10899 new ArraySet<>(featureTags));
10900 } catch (ImsException e) {
10901 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10902 } finally {
10903 Binder.restoreCallingIdentity(identity);
10904 }
10905 }
10906
10907 /**
10908 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10909 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10910 */
10911 // Used for SHELL command only right now.
10912 @Override
10913 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10914 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10915 "clearUceRegistrationOverrideShell");
10916 final long identity = Binder.clearCallingIdentity();
10917 try {
10918 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10919 } catch (ImsException e) {
10920 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10921 } finally {
10922 Binder.restoreCallingIdentity(identity);
10923 }
10924 }
10925
10926 /**
10927 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10928 */
10929 // Used for SHELL command only right now.
10930 @Override
10931 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10932 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10933 "getLatestRcsContactUceCapabilityShell");
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
10936 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10937 } catch (ImsException e) {
10938 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10939 } finally {
10940 Binder.restoreCallingIdentity(identity);
10941 }
10942 }
10943
10944 /**
10945 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10946 * device does not have an active PUBLISH.
10947 */
10948 // Used for SHELL command only right now.
10949 @Override
10950 public String getLastUcePidfXmlShell(int subId) {
10951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10952 final long identity = Binder.clearCallingIdentity();
10953 try {
10954 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10955 } catch (ImsException e) {
10956 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10957 } finally {
10958 Binder.restoreCallingIdentity(identity);
10959 }
10960 }
10961
James.cf Line8713a42021-04-29 16:04:26 +080010962 /**
10963 * Remove UCE requests cannot be sent to the network status.
10964 */
10965 // Used for SHELL command only right now.
10966 @Override
10967 public boolean removeUceRequestDisallowedStatus(int subId) {
10968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10969 final long identity = Binder.clearCallingIdentity();
10970 try {
10971 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10972 } catch (ImsException e) {
10973 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10974 } finally {
10975 Binder.restoreCallingIdentity(identity);
10976 }
10977 }
10978
James.cf Lin18bb9002021-05-25 01:37:38 +080010979 /**
10980 * Remove UCE requests cannot be sent to the network status.
10981 */
10982 // Used for SHELL command only.
10983 @Override
10984 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10986 final long identity = Binder.clearCallingIdentity();
10987 try {
10988 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10989 } catch (ImsException e) {
10990 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10991 } finally {
10992 Binder.restoreCallingIdentity(identity);
10993 }
10994 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010995
James.cf Lin4b784aa2021-01-31 03:25:15 +080010996 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010997 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10998 String callingPackage) {
10999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11000 mApp, subId, "setSignalStrengthUpdateRequest");
11001
11002 final int callingUid = Binder.getCallingUid();
11003 // Verify that tha callingPackage belongs to the calling UID
11004 mApp.getSystemService(AppOpsManager.class)
11005 .checkPackage(callingUid, callingPackage);
11006
Rambo Wang3607f502021-02-01 21:51:40 -080011007 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011008
11009 final long identity = Binder.clearCallingIdentity();
11010 try {
11011 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11012 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11013
11014 if (result instanceof IllegalStateException) {
11015 throw (IllegalStateException) result;
11016 }
11017 } finally {
11018 Binder.restoreCallingIdentity(identity);
11019 }
11020 }
11021
11022 @Override
11023 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11024 String callingPackage) {
11025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11026 mApp, subId, "clearSignalStrengthUpdateRequest");
11027
11028 final int callingUid = Binder.getCallingUid();
11029 // Verify that tha callingPackage belongs to the calling UID
11030 mApp.getSystemService(AppOpsManager.class)
11031 .checkPackage(callingUid, callingPackage);
11032
11033 final long identity = Binder.clearCallingIdentity();
11034 try {
11035 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11036 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11037
11038 if (result instanceof IllegalStateException) {
11039 throw (IllegalStateException) result;
11040 }
11041 } finally {
11042 Binder.restoreCallingIdentity(identity);
11043 }
11044 }
11045
Rambo Wang3607f502021-02-01 21:51:40 -080011046 private static void validateSignalStrengthUpdateRequest(Context context,
11047 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011048 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11049 // phone/system process do not have further restriction on request
11050 return;
11051 }
11052
11053 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011054 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011055 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011056 context.enforceCallingOrSelfPermission(
11057 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11058 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011059 }
11060
11061 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11062 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11063 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11064 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11065 || info.isEnabled()) {
11066 throw new IllegalArgumentException(
11067 "Only system can set hide fields in SignalThresholdInfo");
11068 }
11069
11070 // Thresholds length for each RAN need in range. This has been validated in
11071 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11072 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11073 final int[] thresholds = info.getThresholds();
11074 Objects.requireNonNull(thresholds);
11075 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11076 || thresholds.length
11077 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11078 throw new IllegalArgumentException(
11079 "thresholds length is out of range: " + thresholds.length);
11080 }
11081 }
11082 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011083
11084 /**
11085 * Gets the current phone capability.
11086 *
11087 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11088 * @return the PhoneCapability which describes the data connection capability of modem.
11089 * It's used to evaluate possible phone config change, for example from single
11090 * SIM device to multi-SIM device.
11091 */
11092 @Override
11093 public PhoneCapability getPhoneCapability() {
11094 enforceReadPrivilegedPermission("getPhoneCapability");
11095 final long identity = Binder.clearCallingIdentity();
11096 try {
11097 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11098 } finally {
11099 Binder.restoreCallingIdentity(identity);
11100 }
11101 }
Michele Berionne5e411512020-11-13 02:36:59 +000011102
11103 /**
11104 * Prepare TelephonyManager for an unattended reboot. The reboot is
11105 * required to be done shortly after the API is invoked.
11106 */
11107 @Override
11108 @TelephonyManager.PrepareUnattendedRebootResult
11109 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011110 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011111 enforceRebootPermission();
11112
11113 final long identity = Binder.clearCallingIdentity();
11114 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011115 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011116 } finally {
11117 Binder.restoreCallingIdentity(identity);
11118 }
11119 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011120
11121 /**
11122 * Request to get the current slicing configuration including URSP rules and
11123 * NSSAIs (configured, allowed and rejected).
11124 *
11125 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11126 */
11127 @Override
11128 public void getSlicingConfig(ResultReceiver callback) {
11129 enforceReadPrivilegedPermission("getSlicingConfig");
11130
11131 final long identity = Binder.clearCallingIdentity();
11132 try {
11133 Phone phone = getDefaultPhone();
11134 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11135 } finally {
11136 Binder.restoreCallingIdentity(identity);
11137 }
11138 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011139
11140 /**
11141 * Register an IMS connection state callback
11142 */
11143 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011144 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11145 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011146 if (feature == ImsFeature.FEATURE_MMTEL) {
11147 // ImsMmTelManager
11148 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11149 TelephonyPermissions
11150 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11151 mApp, subId, "registerImsStateCallback");
11152 } else if (feature == ImsFeature.FEATURE_RCS) {
11153 // ImsRcsManager or SipDelegateManager
11154 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11155 Binder.getCallingUid(), "registerImsStateCallback",
11156 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11157 Manifest.permission.READ_PRECISE_PHONE_STATE,
11158 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11159 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11160 }
11161
11162 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11163 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11164 "IMS not available on device.");
11165 }
11166
11167 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11168 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11169 }
11170
11171 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11172 if (controller == null) {
11173 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11174 "IMS not available on device.");
11175 }
11176
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011177 if (callingPackage == null) {
11178 callingPackage = getCurrentPackageName();
11179 }
11180
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011181 final long token = Binder.clearCallingIdentity();
11182 try {
11183 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011184 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011185 } catch (ImsException e) {
11186 throw new ServiceSpecificException(e.getCode());
11187 } finally {
11188 Binder.restoreCallingIdentity(token);
11189 }
11190 }
11191
11192 /**
11193 * Unregister an IMS connection state callback
11194 */
11195 @Override
11196 public void unregisterImsStateCallback(IImsStateCallback cb) {
11197 final long token = Binder.clearCallingIdentity();
11198 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11199 if (controller == null) {
11200 return;
11201 }
11202 try {
11203 controller.unregisterImsStateCallback(cb);
11204 } finally {
11205 Binder.restoreCallingIdentity(token);
11206 }
11207 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011208
11209 /**
11210 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11211 *
11212 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11213 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11214 * SecurityException.
11215 * If there is current registered network this value will be same as the registered cell
11216 * identity. If the device goes out of service the previous cell identity is cached and
11217 * will be returned. If the cache age of the Cell identity is more than 24 hours
11218 * it will be cleared and null will be returned.
11219 *
11220 */
11221 @Override
11222 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11223 String callingFeatureId) {
11224 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11225 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11226 LocationAccessPolicy.checkLocationPermission(mApp,
11227 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11228 .setCallingPackage(callingPackage)
11229 .setCallingFeatureId(callingFeatureId)
11230 .setCallingPid(Binder.getCallingPid())
11231 .setCallingUid(Binder.getCallingUid())
11232 .setMethod("getLastKnownCellIdentity")
11233 .setLogAsInfo(true)
11234 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11235 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11236 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11237 .build());
11238
11239 boolean hasFinePermission =
11240 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11241 if (!hasFinePermission
11242 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11243 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11244 + "and BIND_CONNECTION_SERVICE permission.");
11245 }
11246
11247 final long identity = Binder.clearCallingIdentity();
11248 try {
11249 Phone phone = getPhone(subId);
11250 if (phone == null) return null;
11251 ServiceStateTracker sst = phone.getServiceStateTracker();
11252 if (sst == null) return null;
11253 return sst.getLastKnownCellIdentity();
11254 } finally {
11255 Binder.restoreCallingIdentity(identity);
11256 }
11257 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011258
11259 @Override
11260 public boolean isUsingNewDataStack() {
11261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11262 return getDefaultPhone().isUsingNewDataStack();
11263 }
jimsun3b9ccac2021-10-26 15:01:23 +080011264
11265 /**
11266 * Sets the modem service class Name that Telephony will bind to.
11267 *
11268 * @param serviceName The class name of the modem service.
11269 * @return true if the operation is succeed, otherwise false.
11270 */
11271 public boolean setModemService(String serviceName) {
11272 Log.d(LOG_TAG, "setModemService - " + serviceName);
11273 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11275 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11276 "setModemService");
11277 return mPhoneConfigurationManager.setModemService(serviceName);
11278 }
11279
11280 /**
11281 * Return the class name of the currently bounded modem service.
11282 *
11283 * @return the class name of the modem service.
11284 */
11285 public String getModemService() {
11286 String result;
11287 Log.d(LOG_TAG, "getModemService");
11288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11289 TelephonyPermissions
11290 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11291 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11292 "getModemService");
11293 result = mPhoneConfigurationManager.getModemService();
11294 Log.d(LOG_TAG, "result = " + result);
11295 return result;
11296 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011297
11298 @Override
11299 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11300 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11301 mApp.enforceCallingOrSelfPermission(
11302 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11304
11305 final long identity = Binder.clearCallingIdentity();
11306 try {
11307 Phone phone = getPhone(subId);
11308 if (phone == null) return;
11309 phone.setVoiceServiceStateOverride(hasService);
11310 } finally {
11311 Binder.restoreCallingIdentity(identity);
11312 }
11313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011314}