blob: 4182af18c2a627f2025a71b0e145c2aa94ec32e6 [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");
shilu366312e2019-12-17 09:28:10 -08004045
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004046 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4047 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4048 "IMS not available on device.");
4049 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 final long token = Binder.clearCallingIdentity();
4051 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004052 int slotId = getSlotIndexOrException(subId);
4053 verifyImsMmTelConfiguredOrThrow(slotId);
4054 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004055 } catch (ImsException e) {
4056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 } finally {
4058 Binder.restoreCallingIdentity(token);
4059 }
4060 }
4061
shilu366312e2019-12-17 09:28:10 -08004062 /**
4063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4064 * @param subId The subscription to use to check the configuration.
4065 * @param c The callback that will be used to send the result.
4066 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004068 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004069 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004070 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004071 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4072 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4073 }
Meng Wangafbc5852019-09-19 17:37:13 -07004074 final long token = Binder.clearCallingIdentity();
4075 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004076 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4077 .removeRegistrationCallbackForSubscription(c, subId);
4078 } catch (ImsException e) {
4079 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4080 + "is inactive, ignoring unregister.");
4081 // If the subscription is no longer active, just return, since the callback
4082 // will already have been removed internally.
4083 } finally {
4084 Binder.restoreCallingIdentity(token);
4085 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 }
4087
Brad Ebingera34a6c22019-10-22 17:36:18 -07004088 /**
4089 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4090 */
4091 @Override
4092 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4093 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4094 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4095 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4096 "IMS not available on device.");
4097 }
4098 final long token = Binder.clearCallingIdentity();
4099 try {
4100 Phone phone = getPhone(subId);
4101 if (phone == null) {
4102 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4103 + subId + "'");
4104 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4105 }
4106 phone.getImsRegistrationState(regState -> {
4107 try {
4108 consumer.accept((regState == null)
4109 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4110 } catch (RemoteException e) {
4111 // Ignore if the remote process is no longer available to call back.
4112 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4113 }
4114 });
4115 } finally {
4116 Binder.restoreCallingIdentity(token);
4117 }
4118 }
4119
4120 /**
4121 * Get the transport type for the IMS service registration state.
4122 */
4123 @Override
4124 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004125 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004126 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004127 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4128 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4129 "IMS not available on device.");
4130 }
4131 final long token = Binder.clearCallingIdentity();
4132 try {
4133 Phone phone = getPhone(subId);
4134 if (phone == null) {
4135 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4136 + subId + "'");
4137 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4138 }
4139 phone.getImsRegistrationTech(regTech -> {
4140 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4141 int regTechConverted = (regTech == null)
4142 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4143 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4144 regTechConverted);
4145 try {
4146 consumer.accept(regTechConverted);
4147 } catch (RemoteException e) {
4148 // Ignore if the remote process is no longer available to call back.
4149 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4150 }
4151 });
4152 } finally {
4153 Binder.restoreCallingIdentity(token);
4154 }
4155 }
4156
shilu366312e2019-12-17 09:28:10 -08004157 /**
4158 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4159 * @param subId The subscription to use to check the configuration.
4160 * @param c The callback that will be used to send the result.
4161 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004163 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4164 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004165 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004166 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004167 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4168 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4169 "IMS not available on device.");
4170 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 final long token = Binder.clearCallingIdentity();
4172 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004173 int slotId = getSlotIndexOrException(subId);
4174 verifyImsMmTelConfiguredOrThrow(slotId);
4175 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004176 } catch (ImsException e) {
4177 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 } finally {
4179 Binder.restoreCallingIdentity(token);
4180 }
4181 }
4182
shilu366312e2019-12-17 09:28:10 -08004183 /**
4184 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4185 * @param subId The subscription to use to check the configuration.
4186 * @param c The callback that will be used to send the result.
4187 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004189 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004190 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004191 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004192 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4193 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4194 }
Meng Wangafbc5852019-09-19 17:37:13 -07004195
4196 final long token = Binder.clearCallingIdentity();
4197 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004198 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004199 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004200 } catch (ImsException e) {
4201 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4202 + "is inactive, ignoring unregister.");
4203 // If the subscription is no longer active, just return, since the callback
4204 // will already have been removed internally.
4205 } finally {
4206 Binder.restoreCallingIdentity(token);
4207 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 }
4209
4210 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004211 public boolean isCapable(int subId, int capability, int regTech) {
4212 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 final long token = Binder.clearCallingIdentity();
4214 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004215 int slotId = getSlotIndexOrException(subId);
4216 verifyImsMmTelConfiguredOrThrow(slotId);
4217 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004218 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4220 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004221 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004222 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4223 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 } finally {
4225 Binder.restoreCallingIdentity(token);
4226 }
4227 }
4228
4229 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004230 public boolean isAvailable(int subId, int capability, int regTech) {
4231 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 final long token = Binder.clearCallingIdentity();
4233 try {
4234 Phone phone = getPhone(subId);
4235 if (phone == null) return false;
4236 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004237 } catch (com.android.ims.ImsException e) {
4238 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4239 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 } finally {
4241 Binder.restoreCallingIdentity(token);
4242 }
4243 }
4244
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004245 /**
4246 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4247 * subscription.
4248 * @param subId The subscription to use to check the configuration.
4249 * @param callback The callback that will be used to send the result.
4250 * @param capability The MmTelFeature capability that will be used to send the result.
4251 * @param transportType The transport type of the MmTelFeature capability.
4252 */
4253 @Override
4254 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4255 int transportType) {
4256 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4257 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4258 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4259 "IMS not available on device.");
4260 }
4261 final long token = Binder.clearCallingIdentity();
4262 try {
4263 int slotId = getSlotIndex(subId);
4264 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4265 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4266 + subId + "'");
4267 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4268 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004269 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004270 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4271 transportType, aBoolean -> {
4272 try {
4273 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4274 } catch (RemoteException e) {
4275 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4276 + "running. Ignore");
4277 }
4278 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 } catch (ImsException e) {
4280 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004281 } finally {
4282 Binder.restoreCallingIdentity(token);
4283 }
4284 }
4285
shilu366312e2019-12-17 09:28:10 -08004286 /**
4287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4288 * @param subId The subscription to use to check the configuration.
4289 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 @Override
4291 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004292 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004293 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004294
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long token = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 } finally {
4303 Binder.restoreCallingIdentity(token);
4304 }
4305 }
4306
4307 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004308 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004310 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004314 // This setting doesn't require an active ImsService connection, so do not verify. The
4315 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004324 /**
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004329 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004331 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
4342 }
4343
4344 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004345 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004347 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004348 final long identity = Binder.clearCallingIdentity();
4349 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004350 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004351 // This setting doesn't require an active ImsService connection, so do not verify. The
4352 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004361 /**
4362 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4363 * @param subId The subscription to use to check the configuration.
4364 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 @Override
4366 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004367 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004368 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 final long identity = Binder.clearCallingIdentity();
4370 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004371 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004372 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004374 } catch (ImsException e) {
4375 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
4379 }
4380
4381 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004382 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004384 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 final long identity = Binder.clearCallingIdentity();
4386 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004387 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004388 // This setting doesn't require an active ImsService connection, so do not verify. The
4389 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004390 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004391 } catch (ImsException e) {
4392 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
4396 }
4397
shilu366312e2019-12-17 09:28:10 -08004398 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004399 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4400 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4401 * @param subId The subscription to use to check the configuration.
4402 */
4403 @Override
4404 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004405 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004406 mApp, subId, "isCrossSimCallingEnabledByUser");
4407 final long identity = Binder.clearCallingIdentity();
4408 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004410 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004412 } catch (ImsException e) {
4413 throw new ServiceSpecificException(e.getCode());
4414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
4417 }
4418
4419 /**
4420 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4421 * Requires MODIFY_PHONE_STATE permission.
4422 * @param subId The subscription to use to check the configuration.
4423 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4424 * false otherwise
4425 */
4426 @Override
4427 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4429 "setCrossSimCallingEnabled");
4430 final long identity = Binder.clearCallingIdentity();
4431 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004433 // This setting doesn't require an active ImsService connection, so do not verify. The
4434 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004435 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004436 } catch (ImsException e) {
4437 throw new ServiceSpecificException(e.getCode());
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
4440 }
4441 }
4442
4443 /**
shilu366312e2019-12-17 09:28:10 -08004444 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4445 * @param subId The subscription to use to check the configuration.
4446 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004448
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004450 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004451 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 final long identity = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004455 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004457 } catch (ImsException e) {
4458 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
4462 }
4463
4464 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004465 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004467 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004471 // This setting doesn't require an active ImsService connection, so do not verify. The
4472 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004474 } catch (ImsException e) {
4475 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
4479 }
4480
4481 @Override
4482 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4484 "setVoWiFiNonPersistent");
4485 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 will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004489 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
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
shilu366312e2019-12-17 09:28:10 -08004497 /**
4498 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4499 * @param subId The subscription to use to check the configuration.
4500 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 @Override
4502 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004503 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004504 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 final long identity = Binder.clearCallingIdentity();
4506 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004508 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004509 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004510 } catch (ImsException e) {
4511 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 } finally {
4513 Binder.restoreCallingIdentity(identity);
4514 }
4515 }
4516
4517 @Override
4518 public void setVoWiFiModeSetting(int subId, int mode) {
4519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4520 "setVoWiFiModeSetting");
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004524 // This setting doesn't require an active ImsService connection, so do not verify. The
4525 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004526 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004527 } catch (ImsException e) {
4528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
4532 }
4533
4534 @Override
4535 public int getVoWiFiRoamingModeSetting(int subId) {
4536 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4537 final long identity = Binder.clearCallingIdentity();
4538 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004540 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 } catch (ImsException e) {
4543 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
4549 @Override
4550 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4552 "setVoWiFiRoamingModeSetting");
4553 final long identity = Binder.clearCallingIdentity();
4554 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004555 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004556 // This setting doesn't require an active ImsService connection, so do not verify. The
4557 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 }
4565
4566 @Override
4567 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4569 "setRttCapabilityEnabled");
4570 final long identity = Binder.clearCallingIdentity();
4571 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004572 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004573 // This setting doesn't require an active ImsService connection, so do not verify. The
4574 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004583 /**
4584 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4585 * @param subId The subscription to use to check the configuration.
4586 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 @Override
4588 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004589 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004590 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004593 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004594 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004595 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004596 } catch (ImsException e) {
4597 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
4601 }
4602
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004603 @Override
4604 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4605 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004606
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004607 final long identity = Binder.clearCallingIdentity();
4608 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004609 if (!isImsAvailableOnDevice()) {
4610 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4611 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004612 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004613 int slotId = getSlotIndexOrException(subId);
4614 verifyImsMmTelConfiguredOrThrow(slotId);
4615 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004616 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004617 } catch (ImsException e) {
4618 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
4622 }
4623
4624 @Override
4625 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4626 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004627
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004628 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4630 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4631 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004632 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004633 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004634 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004635 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004636 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4637 + "is inactive, ignoring unregister.");
4638 // If the subscription is no longer active, just return, since the callback will already
4639 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
4643 }
4644
joonhunshincffb7fc2021-11-28 07:32:01 +00004645 @Override
4646 public void registerFeatureProvisioningChangedCallback(int subId,
4647 IFeatureProvisioningCallback callback) {
4648 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4649 mApp, subId, "registerFeatureProvisioningChangedCallback");
4650
4651 final long identity = Binder.clearCallingIdentity();
4652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4653 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4654 }
4655
4656 ImsProvisioningController.getInstance()
4657 .addFeatureProvisioningChangedCallback(subId, callback);
4658
4659 Binder.restoreCallingIdentity(identity);
4660 }
4661
4662 @Override
4663 public void unregisterFeatureProvisioningChangedCallback(int subId,
4664 IFeatureProvisioningCallback callback) {
4665 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4666 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4667
4668 final long identity = Binder.clearCallingIdentity();
4669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4670 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4671 }
4672
4673 ImsProvisioningController.getInstance()
4674 .removeFeatureProvisioningChangedCallback(subId, callback);
4675
4676 Binder.restoreCallingIdentity(identity);
4677 }
allenwtsu99c623b2020-01-03 18:24:23 +08004678
4679 private void checkModifyPhoneStatePermission(int subId, String message) {
4680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4681 message);
4682 }
4683
4684 private boolean isImsProvisioningRequired(int subId, int capability,
4685 boolean isMmtelCapability) {
4686 Phone phone = getPhone(subId);
4687 if (phone == null) {
4688 loge("phone instance null for subid " + subId);
4689 return false;
4690 }
4691 if (isMmtelCapability) {
4692 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4693 return false;
4694 }
4695 } else {
4696 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4697 return false;
4698 }
4699 }
4700 return true;
4701 }
4702
4703 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004704 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004705 boolean isProvisioned) {
4706 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004710 ImsProvisioningController.getInstance()
4711 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4712 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
allenwtsu99c623b2020-01-03 18:24:23 +08004716 }
4717
4718
4719 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004720 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4721 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4722 mApp, subId, "getRcsProvisioningStatusForCapability");
4723
allenwtsu99c623b2020-01-03 18:24:23 +08004724 final long identity = Binder.clearCallingIdentity();
4725 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004726 return ImsProvisioningController.getInstance()
4727 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
4731 }
4732
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004733 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4735 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004736 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004737
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 final long identity = Binder.clearCallingIdentity();
4739 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004740 ImsProvisioningController.getInstance()
4741 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004742 } finally {
4743 Binder.restoreCallingIdentity(identity);
4744 }
4745 }
4746
4747 @Override
4748 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004749 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4750 mApp, subId, "getProvisioningStatusForCapability");
4751
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004752 final long identity = Binder.clearCallingIdentity();
4753 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004754 return ImsProvisioningController.getInstance()
4755 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
4762 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004763 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4764 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4765 mApp, subId, "isProvisioningRequiredForCapability");
4766
4767 final long identity = Binder.clearCallingIdentity();
4768 try {
4769 return ImsProvisioningController.getInstance()
4770 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004773 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004774 }
4775
4776 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004777 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4778 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4779 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780
joonhunshincffb7fc2021-11-28 07:32:01 +00004781 final long identity = Binder.clearCallingIdentity();
4782 try {
4783 return ImsProvisioningController.getInstance()
4784 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004788 }
4789
4790 private static String getMmTelProvisioningKey(int subId, int tech) {
4791 // resulting key is provision_ims_mmtel_{subId}_{tech}
4792 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4793 }
4794
4795 /**
4796 * Query CarrierConfig to see if the specified capability requires provisioning for the
4797 * carrier associated with the subscription id.
4798 */
4799 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4800 int capability) {
4801 CarrierConfigManager configManager = new CarrierConfigManager(context);
4802 PersistableBundle c = configManager.getConfigForSubId(subId);
4803 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004804 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004805 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4806 false);
4807 boolean requireVoiceVtProvisioning = c.getBoolean(
4808 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4809
4810 // First check to make sure that the capability requires provisioning.
4811 switch (capability) {
4812 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4813 // intentional fallthrough
4814 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4815 if (requireVoiceVtProvisioning) {
4816 // Voice and Video requires provisioning
4817 return true;
4818 }
4819 break;
4820 }
4821 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4822 if (requireUtProvisioning) {
4823 // UT requires provisioning
4824 return true;
4825 }
4826 break;
4827 }
4828 }
4829 return false;
4830 }
4831
allenwtsu99c623b2020-01-03 18:24:23 +08004832 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4833 int capability) {
4834 CarrierConfigManager configManager = new CarrierConfigManager(context);
4835 PersistableBundle c = configManager.getConfigForSubId(subId);
4836
4837 boolean requireRcsProvisioning = c.getBoolean(
4838 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4839
4840 // First check to make sure that the capability requires provisioning.
4841 switch (capability) {
4842 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4843 // intentional fallthrough
4844 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4845 if (requireRcsProvisioning) {
4846 // OPTION or PRESENCE requires provisioning
4847 return true;
4848 }
4849 break;
4850 }
4851 }
4852 return false;
4853 }
4854
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004856 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4858 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4859 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004860 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4861 mApp, subId, "getImsProvisioningInt");
4862
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004863 final long identity = Binder.clearCallingIdentity();
4864 try {
4865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004866 int slotId = getSlotIndex(subId);
4867 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4868 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4869 + subId + "' for key:" + key);
4870 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4871 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004872
4873 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4874 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4875 return retVal;
4876 }
4877
calvinpanb5a34062021-02-08 19:59:36 +08004878 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004879 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004880 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4881 + subId + "' for key:" + key);
4882 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
4886 }
4887
4888 @Override
4889 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4891 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4892 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004893 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4894 mApp, subId, "getImsProvisioningString");
4895
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 int slotId = getSlotIndex(subId);
4900 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4901 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4902 + subId + "' for key:" + key);
4903 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4904 }
calvinpanb5a34062021-02-08 19:59:36 +08004905 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004906 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4908 + subId + "' for key:" + key);
4909 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
4913 }
4914
4915 @Override
4916 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4918 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4919 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4921 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004922
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004923 final long identity = Binder.clearCallingIdentity();
4924 try {
4925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004926 int slotId = getSlotIndex(subId);
4927 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4928 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4929 + subId + "' for key:" + key);
4930 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4931 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004932
4933 int retVal = ImsProvisioningController.getInstance()
4934 .setProvisioningValue(subId, key, value);
4935 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4936 return retVal;
4937 }
4938
calvinpanb5a34062021-02-08 19:59:36 +08004939 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4940 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004942 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
4947 }
4948
4949 @Override
4950 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4952 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4953 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4955 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 int slotId = getSlotIndex(subId);
4960 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4961 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4962 + subId + "' for key:" + key);
4963 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4964 }
calvinpanb5a34062021-02-08 19:59:36 +08004965 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4966 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004968 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004969 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
4973 }
4974
Brad Ebinger919631e2021-06-02 17:46:35 -07004975 /**
4976 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4977 * for the given slot ID or no ImsResolver instance has been created.
4978 * @param slotId The slot ID that the IMS service is created for.
4979 * @throws ImsException If there is no ImsService configured for this slot.
4980 */
4981 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4982 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4983 ImsFeature.FEATURE_MMTEL)) {
4984 throw new ImsException("This subscription does not support MMTEL over IMS",
4985 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4986 }
4987 }
4988
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004989 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004990 int slotId = SubscriptionManager.getSlotIndex(subId);
4991 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004992 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4993 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 }
4995 return slotId;
4996 }
4997
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 private int getSlotIndex(int subId) {
4999 int slotId = SubscriptionManager.getSlotIndex(subId);
5000 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5001 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5002 }
5003 return slotId;
5004 }
5005
Wink Saville36469e72014-06-11 15:17:00 -07005006 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005007 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005008 */
5009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005010 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5011 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005012 try {
5013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5014 } catch (SecurityException se) {
5015 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5016 throw new SecurityException("Package " + callingPackage + " does not belong to "
5017 + Binder.getCallingUid());
5018 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005019 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005020 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005021 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005022 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005023 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005024 mApp, subId, callingPackage, callingFeatureId,
5025 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005026 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5027 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 final Phone phone = getPhone(subId);
5032 if (phone != null) {
5033 return phone.getServiceState().getDataNetworkType();
5034 } else {
5035 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5036 }
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005040 }
5041
5042 /**
5043 * Returns the data network type
5044 */
5045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005046 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005047 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5048 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005049 }
5050
5051 /**
5052 * Returns the data network type for a subId
5053 */
5054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005055 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5056 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005057 String functionName = "getDataNetworkTypeForSubscriber";
5058 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5059 mApp, functionName)) {
5060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5061 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005064 }
5065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 final Phone phone = getPhone(subId);
5069 if (phone != null) {
5070 return phone.getServiceState().getDataNetworkType();
5071 } else {
5072 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5073 }
5074 } finally {
5075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005077 }
5078
5079 /**
Wink Saville36469e72014-06-11 15:17:00 -07005080 * Returns the Voice network type for a subId
5081 */
5082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005083 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5084 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005085 String functionName = "getVoiceNetworkTypeForSubscriber";
5086 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5087 mApp, functionName)) {
5088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5089 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5090 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5091 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005092 }
5093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 final Phone phone = getPhone(subId);
5097 if (phone != null) {
5098 return phone.getServiceState().getVoiceNetworkType();
5099 } else {
5100 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5101 }
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005105 }
5106
5107 /**
5108 * @return true if a ICC card is present
5109 */
5110 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005111 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005112 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5113 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005114 }
5115
5116 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005117 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005118 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005119 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005120 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 final Phone phone = PhoneFactory.getPhone(slotIndex);
5124 if (phone != null) {
5125 return phone.getIccCard().hasIccCard();
5126 } else {
5127 return false;
5128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005132 }
5133
5134 /**
5135 * Return if the current radio is LTE on CDMA. This
5136 * is a tri-state return value as for a period of time
5137 * the mode may be unknown.
5138 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005139 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005140 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005141 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005142 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005143 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005144 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5145 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5146 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005147 }
5148
Sanket Padawe356d7632015-06-22 14:03:32 -07005149 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005150 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5151 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005152 try {
5153 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5154 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005155 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5156 }
5157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 final Phone phone = getPhone(subId);
5161 if (phone == null) {
5162 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5163 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005164 return TelephonyProperties.lte_on_cdma_device()
5165 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005169 }
Wink Saville36469e72014-06-11 15:17:00 -07005170 }
5171
Wink Saville36469e72014-06-11 15:17:00 -07005172 /**
5173 * {@hide}
5174 * Returns Default subId, 0 in the case of single standby.
5175 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005176 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005177 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005178 }
5179
Shishir Agrawala9f32182016-04-12 12:00:16 -07005180 private int getSlotForDefaultSubscription() {
5181 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5182 }
5183
Wink Savilleb564aae2014-10-23 10:18:09 -07005184 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005185 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005186 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005187
Pengquan Menge92a50d2018-09-21 15:54:48 -07005188 private boolean isActiveSubscription(int subId) {
5189 return mSubscriptionController.isActiveSubId(subId);
5190 }
5191
Ihab Awadf2177b72013-11-25 13:33:23 -08005192 /**
5193 * @see android.telephony.TelephonyManager.WifiCallingChoices
5194 */
5195 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 final long identity = Binder.clearCallingIdentity();
5197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005198 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5200 getWhenToMakeWifiCallsDefaultPreference());
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005204 }
5205
5206 /**
5207 * @see android.telephony.TelephonyManager.WifiCallingChoices
5208 */
5209 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 final long identity = Binder.clearCallingIdentity();
5211 try {
5212 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005213 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5215 } finally {
5216 Binder.restoreCallingIdentity(identity);
5217 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005218 }
5219
Sailesh Nepald1e68152013-12-12 19:08:02 -08005220 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005221 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005222 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005223 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005224
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005225 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5226 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5227 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005228 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005229 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5230 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005231 }
5232 return PhoneFactory.getPhone(phoneId);
5233 }
5234
Shishir Agrawal566b7612013-10-28 14:41:00 -07005235 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005236 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005237 @NonNull IccLogicalChannelRequest request) {
5238 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5239 /*message=*/ "iccOpenLogicalChannel");
5240
5241 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5242 // Verify that the callingPackage in the request belongs to the calling UID
5243 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5244
5245 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005246 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005247
Rambo Wanga1782702021-11-10 20:15:19 -08005248 private Phone getPhoneFromValidIccLogicalChannelRequest(
5249 @NonNull IccLogicalChannelRequest request, String message) {
5250 Phone phone;
5251 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5253 mApp, request.subId, message);
5254 phone = getPhoneFromSubId(request.subId);
5255 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5256 enforceModifyPermission();
5257 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5258 } else {
5259 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005260 }
Rambo Wanga1782702021-11-10 20:15:19 -08005261 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005262 }
5263
5264 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005265 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 final long identity = Binder.clearCallingIdentity();
5267 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005268 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005270 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5271 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005272 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5273 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 loge("The calling package is not allowed to access ISD-R.");
5275 throw new SecurityException(
5276 "The calling package is not allowed to access ISD-R.");
5277 }
Derek Tan740e1672017-06-27 14:56:27 -07005278 }
Derek Tan740e1672017-06-27 14:56:27 -07005279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005281 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5282 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 return response;
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005287 }
5288
5289 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005290 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5291 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5292 /*message=*/"iccCloseLogicalChannel");
5293
5294 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5295
5296 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005297 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005298
Rambo Wanga1782702021-11-10 20:15:19 -08005299 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5300 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 final long identity = Binder.clearCallingIdentity();
5302 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005303 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005304 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 }
Chen Xue9d737e2022-01-01 23:41:31 -08005306 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005307 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005308 Boolean success = false;
5309 if (result instanceof RuntimeException) {
5310 // if there is an exception returned, throw from the binder thread here.
5311 throw (RuntimeException) result;
5312 } else if (result instanceof Boolean) {
5313 success = (Boolean) result;
5314 } else {
5315 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5316 }
Rambo Wanga1782702021-11-10 20:15:19 -08005317 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318 return success;
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005321 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322 }
5323
5324 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005325 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5328 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005329 if (DBG) {
5330 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5331 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5332 + p3 + " data=" + data);
5333 }
5334 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5335 command, p1, p2, p3, data);
5336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337
Jordan Liu4c733742019-02-28 12:03:40 -08005338 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005339 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5340 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005341 enforceModifyPermission();
5342 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005343 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5344 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5345 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005346 }
5347 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005348 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5349 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005350 }
5351
5352 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5353 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 final long identity = Binder.clearCallingIdentity();
5355 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005356 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 return "";
5358 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005361 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5362 null /* workSource */);
5363 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 // Append the returned status code to the end of the response payload.
5366 String s = Integer.toHexString(
5367 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5368 if (response.payload != null) {
5369 s = IccUtils.bytesToHexString(response.payload) + s;
5370 }
5371 return s;
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005374 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005375 }
Jake Hambye994d462014-02-03 13:10:13 -08005376
Evan Charltonc66da362014-05-16 14:06:40 -07005377 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005378 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5379 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5381 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005383 if (DBG) {
5384 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5385 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5386 }
5387 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5388 cla, command, p1, p2, p3, data);
5389 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005390
Jordan Liu4c733742019-02-28 12:03:40 -08005391 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005392 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5393 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005394 enforceModifyPermission();
5395 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5396 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005397 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5398 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5399 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005400 }
5401
5402 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005403 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5404 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005405 }
5406
5407 // open APDU basic channel assuming the caller has sufficient permissions
5408 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5409 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5413 && TextUtils.equals(ISDR_AID, data)) {
5414 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005415 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5416 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 if (bestComponent == null
5418 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5419 loge("The calling package is not allowed to select ISD-R.");
5420 throw new SecurityException(
5421 "The calling package is not allowed to select ISD-R.");
5422 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005423 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005426 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5427 null /* workSource */);
5428 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 // Append the returned status code to the end of the response payload.
5431 String s = Integer.toHexString(
5432 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5433 if (response.payload != null) {
5434 s = IccUtils.bytesToHexString(response.payload) + s;
5435 }
5436 return s;
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005439 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005440 }
5441
5442 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005443 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5446 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
5450 if (DBG) {
5451 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5452 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5453 }
5454
5455 IccIoResult response =
5456 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5457 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5458 subId);
5459
5460 if (DBG) {
5461 log("Exchange SIM_IO [R]" + response);
5462 }
5463
5464 byte[] result = null;
5465 int length = 2;
5466 if (response.payload != null) {
5467 length = 2 + response.payload.length;
5468 result = new byte[length];
5469 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5470 } else {
5471 result = new byte[length];
5472 }
5473
5474 result[length - 1] = (byte) response.sw2;
5475 result[length - 2] = (byte) response.sw1;
5476 return result;
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005479 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005480 }
5481
Nathan Haroldb3014052017-01-25 15:57:32 -08005482 /**
5483 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5484 * on a particular subscription
5485 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005486 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5487 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005489 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005490 return null;
5491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492
5493 final long identity = Binder.clearCallingIdentity();
5494 try {
5495 if (appType != TelephonyManager.APPTYPE_USIM
5496 && appType != TelephonyManager.APPTYPE_SIM) {
5497 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5498 return null;
5499 }
5500 Object response = sendRequest(
5501 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5502 if (response instanceof String[]) {
5503 return (String[]) response;
5504 }
yincheng zhao2737e882019-09-06 17:06:54 -07005505 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005507 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005510 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005511 }
5512
yincheng zhao2737e882019-09-06 17:06:54 -07005513 /**
5514 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5515 * subscription.
5516 *
5517 * @param subId the id of the subscription.
5518 * @param appType the uicc app type, must be USIM or SIM.
5519 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5520 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005521 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005522 * @return number of fplmns that is successfully written to the SIM.
5523 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005524 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5525 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5527 mApp, subId, "setForbiddenPlmns");
5528
yincheng zhao2737e882019-09-06 17:06:54 -07005529 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5530 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5531 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5532 }
5533 if (fplmns == null) {
5534 throw new IllegalArgumentException("Fplmn List provided is null");
5535 }
5536 for (String fplmn : fplmns) {
5537 if (!CellIdentity.isValidPlmn(fplmn)) {
5538 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5539 }
5540 }
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 Object response = sendRequest(
5544 CMD_SET_FORBIDDEN_PLMNS,
5545 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5546 subId);
5547 return (int) response;
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005554 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5556 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5561 if (response.payload == null) {
5562 return "";
5563 }
Evan Charltonc66da362014-05-16 14:06:40 -07005564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 // Append the returned status code to the end of the response payload.
5566 String s = Integer.toHexString(
5567 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5568 s = IccUtils.bytesToHexString(response.payload) + s;
5569 return s;
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
Evan Charltonc66da362014-05-16 14:06:40 -07005573 }
5574
Jake Hambye994d462014-02-03 13:10:13 -08005575 /**
5576 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5577 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5578 *
5579 * @param itemID the ID of the item to read
5580 * @return the NV item as a String, or null on error.
5581 */
5582 @Override
5583 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5586 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
5588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005591 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5593 return value;
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Jake Hambye994d462014-02-03 13:10:13 -08005597 }
5598
5599 /**
5600 * Write 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 * @param itemValue the value to write, as a String
5605 * @return true on success; false on any failure
5606 */
5607 @Override
5608 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005609 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5611 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612
5613 final long identity = Binder.clearCallingIdentity();
5614 try {
5615 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5616 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005617 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5619 return success;
5620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
Jake Hambye994d462014-02-03 13:10:13 -08005623 }
5624
5625 /**
5626 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5627 * Used for device configuration by some CDMA operators.
5628 *
5629 * @param preferredRoamingList byte array containing the new PRL
5630 * @return true on success; false on any failure
5631 */
5632 @Override
5633 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5640 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5641 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5642 return success;
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Jake Hambye994d462014-02-03 13:10:13 -08005646 }
5647
5648 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005649 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005650 * Used for device configuration by some CDMA operators.
5651 *
chen xu6dac5ab2018-10-26 17:39:23 -07005652 * @param slotIndex - device slot.
5653 *
Jake Hambye994d462014-02-03 13:10:13 -08005654 * @return true on success; false on any failure
5655 */
5656 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005657 public boolean resetModemConfig(int slotIndex) {
5658 Phone phone = PhoneFactory.getPhone(slotIndex);
5659 if (phone != null) {
5660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
chen xu6dac5ab2018-10-26 17:39:23 -07005663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5666 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5667 return success;
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 }
chen xu6dac5ab2018-10-26 17:39:23 -07005672 return false;
5673 }
5674
5675 /**
5676 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5677 *
5678 * @param slotIndex - device slot.
5679 *
5680 * @return true on success; false on any failure
5681 */
5682 @Override
5683 public boolean rebootModem(int slotIndex) {
5684 Phone phone = PhoneFactory.getPhone(slotIndex);
5685 if (phone != null) {
5686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5687 mApp, phone.getSubId(), "rebootModem");
5688
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5692 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5693 return success;
5694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
5697 }
5698 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005699 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005700
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005701 public String[] getPcscfAddress(String apnType, String callingPackage,
5702 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5705 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005706 return new String[0];
5707 }
5708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 final long identity = Binder.clearCallingIdentity();
5710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005711 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 } finally {
5713 Binder.restoreCallingIdentity(identity);
5714 }
Wink Saville36469e72014-06-11 15:17:00 -07005715 }
5716
Brad Ebinger51f743a2017-01-23 13:50:20 -08005717 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005718 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5719 * {@link #disableIms(int)}.
5720 * @param slotIndex device slot.
5721 */
5722 public void resetIms(int slotIndex) {
5723 enforceModifyPermission();
5724
5725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 if (mImsResolver == null) {
5728 // may happen if the does not support IMS.
5729 return;
5730 }
5731 mImsResolver.disableIms(slotIndex);
5732 mImsResolver.enableIms(slotIndex);
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
5736 }
5737
5738 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5740 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005741 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005742 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005747 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005748 // may happen if the device does not support IMS.
5749 return;
5750 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005751 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005755 }
5756
5757 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005758 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5759 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005760 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 public void disableIms(int slotId) {
5762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005767 // may happen if the device does not support IMS.
5768 return;
5769 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005774 }
5775
5776 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005777 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5778 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005779 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005780 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005781 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5788 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005789 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005790 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005794 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005795 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005796 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5797 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005798 @Override
5799 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005800 enforceModifyPermission();
5801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005805 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
5809 }
5810
5811 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005812 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005813 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005814 */
5815 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005821 // may happen if the device does not support IMS.
5822 return null;
5823 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005828 }
5829
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005830 /**
5831 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005832 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005833 */
5834 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005840 // may happen if the device does not support IMS.
5841 return null;
5842 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005847 }
5848
Brad Ebinger884c07b2018-02-15 16:17:40 -08005849 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005850 * Sets the ImsService Package Name that Telephony will bind to.
5851 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 * @param slotIndex the slot ID that the ImsService should bind for.
5853 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005854 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 * @param featureTypes An integer array of feature types associated with a packageName.
5856 * @param packageName The name of the package that the current configuration will be replaced
5857 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005858 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005859 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005860 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5861 int[] featureTypes, String packageName) {
5862 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5865 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005871 // may happen if the device does not support IMS.
5872 return false;
5873 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 Map<Integer, String> featureConfig = new HashMap<>();
5875 for (int featureType : featureTypes) {
5876 featureConfig.put(featureType, packageName);
5877 }
5878 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5879 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005883 }
5884
5885 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005886 * Clears any carrier ImsService overrides for the slot index specified that were previously
5887 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5888 *
5889 * This should only be used for testing.
5890 *
5891 * @param slotIndex the slot ID that the ImsService should bind for.
5892 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5893 */
5894 @Override
5895 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5896 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5898 "clearCarrierImsServiceOverride");
5899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5900 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5901 "clearCarrierImsServiceOverride");
5902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 if (mImsResolver == null) {
5906 // may happen if the device does not support IMS.
5907 return false;
5908 }
5909 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
5913 }
5914
5915 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005917 *
5918 * @param slotId The slot that the ImsService is associated with.
5919 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5920 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005921 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005922 * @return the package name of the ImsService configuration.
5923 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5925 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005926 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005928 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005929 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5930 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 final long identity = Binder.clearCallingIdentity();
5933 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005934 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005935 // may happen if the device does not support IMS.
5936 return "";
5937 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005938 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005939 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5940 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005944 }
5945
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005946 /**
5947 * Get the MmTelFeature state associated with the requested subscription id.
5948 * @param subId The subscription that the MmTelFeature is associated with.
5949 * @param callback A callback with an integer containing the
5950 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5951 */
5952 @Override
5953 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5954 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5955 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5956 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5957 "IMS not available on device.");
5958 }
5959 final long token = Binder.clearCallingIdentity();
5960 try {
5961 int slotId = getSlotIndex(subId);
5962 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5963 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5964 + subId + "'");
5965 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5966 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005967 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005968 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5969 try {
5970 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5971 } catch (RemoteException e) {
5972 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5973 + "Ignore");
5974 }
5975 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005976 } catch (ImsException e) {
5977 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005978 } finally {
5979 Binder.restoreCallingIdentity(token);
5980 }
5981 }
5982
Daniel Brightbb5840b2021-01-12 15:48:18 -08005983 /**
5984 * Sets the ims registration state on all valid {@link Phone}s.
5985 */
5986 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
5989 final long identity = Binder.clearCallingIdentity();
5990 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005991 // NOTE: Before S, this method only set the default phone.
5992 for (final Phone phone : PhoneFactory.getPhones()) {
5993 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5994 phone.setImsRegistrationState(registered);
5995 }
5996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Wink Saville36469e72014-06-11 15:17:00 -07006000 }
6001
6002 /**
Stuart Scott54788802015-03-30 13:18:01 -07006003 * Set the network selection mode to automatic.
6004 *
6005 */
6006 @Override
6007 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 final long identity = Binder.clearCallingIdentity();
6012 try {
shilufc958392020-01-20 11:36:01 -08006013 if (!isActiveSubscription(subId)) {
6014 return;
6015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006017 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6018 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Stuart Scott54788802015-03-30 13:18:01 -07006022 }
6023
Jack Yud10cdd42020-09-28 20:28:01 -07006024 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006025 * Ask the radio to connect to the input network and change selection mode to manual.
6026 *
6027 * @param subId the id of the subscription.
6028 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6029 * the operator to attach to.
6030 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6031 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6032 * normal network selection next time.
6033 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006034 */
6035 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006036 public boolean setNetworkSelectionModeManual(
6037 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6039 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006040
6041 if (!isActiveSubscription(subId)) {
6042 return false;
6043 }
6044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 final long identity = Binder.clearCallingIdentity();
6046 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006047 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006049 if (DBG) {
6050 log("setNetworkSelectionModeManual: subId: " + subId
6051 + " operator: " + operatorInfo);
6052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006057 }
shilu84f6e8b2019-12-19 13:58:01 -08006058 /**
6059 * Get the manual network selection
6060 *
6061 * @param subId the id of the subscription.
6062 *
6063 * @return the previously saved user selected PLMN
6064 */
6065 @Override
6066 public String getManualNetworkSelectionPlmn(int subId) {
6067 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006068 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006069 mApp, subId, "getManualNetworkSelectionPlmn");
6070
6071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006074 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006075 }
6076
6077 final Phone phone = getPhone(subId);
6078 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006079 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006080 }
6081 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6082 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6083 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
6087 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006088
6089 /**
6090 * Scans for available networks.
6091 */
6092 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006093 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6094 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6096 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006097 LocationAccessPolicy.LocationPermissionResult locationResult =
6098 LocationAccessPolicy.checkLocationPermission(mApp,
6099 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6100 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006101 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006102 .setCallingPid(Binder.getCallingPid())
6103 .setCallingUid(Binder.getCallingUid())
6104 .setMethod("getCellNetworkScanResults")
6105 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006106 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6107 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006108 .build());
6109 switch (locationResult) {
6110 case DENIED_HARD:
6111 throw new SecurityException("Not allowed to access scan results -- location");
6112 case DENIED_SOFT:
6113 return null;
6114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115
Pengquan Menga1bb6272018-09-06 09:59:22 -07006116 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 try {
6118 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006119 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006124 }
6125
6126 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006127 * Get the call forwarding info, given the call forwarding reason.
6128 */
6129 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006130 public void getCallForwarding(int subId, int callForwardingReason,
6131 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006132 enforceReadPrivilegedPermission("getCallForwarding");
6133 long identity = Binder.clearCallingIdentity();
6134 try {
6135 if (DBG) {
6136 log("getCallForwarding: subId " + subId
6137 + " callForwardingReason" + callForwardingReason);
6138 }
Hall Liu27d24262020-09-18 19:04:59 -07006139
6140 Phone phone = getPhone(subId);
6141 if (phone == null) {
6142 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006143 callback.onError(
6144 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006145 } catch (RemoteException e) {
6146 // ignore
6147 }
6148 return;
6149 }
6150
6151 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6152 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6153 @Override
6154 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6155 try {
6156 callback.onCallForwardingInfoAvailable(info);
6157 } catch (RemoteException e) {
6158 // ignore
6159 }
6160 }
6161
6162 @Override
6163 public void onError(int error) {
6164 try {
6165 callback.onError(error);
6166 } catch (RemoteException e) {
6167 // ignore
6168 }
6169 }
6170 });
6171 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 }
6176
6177 /**
6178 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6179 * reason, the number to forward, and the timeout before the forwarding is attempted.
6180 */
6181 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006182 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6183 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006184 enforceModifyPermission();
6185 long identity = Binder.clearCallingIdentity();
6186 try {
6187 if (DBG) {
6188 log("setCallForwarding: subId " + subId
6189 + " callForwardingInfo" + callForwardingInfo);
6190 }
Hall Liu27d24262020-09-18 19:04:59 -07006191
6192 Phone phone = getPhone(subId);
6193 if (phone == null) {
6194 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006195 callback.accept(
6196 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006197 } catch (RemoteException e) {
6198 // ignore
6199 }
6200 return;
6201 }
6202
6203 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6204 FunctionalUtils.ignoreRemoteException(callback::accept));
6205
6206 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
6210 }
6211
6212 /**
Hall Liu27d24262020-09-18 19:04:59 -07006213 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006214 */
6215 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006216 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006217 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006218 long identity = Binder.clearCallingIdentity();
6219 try {
Hall Liu27d24262020-09-18 19:04:59 -07006220 Phone phone = getPhone(subId);
6221 if (phone == null) {
6222 try {
6223 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6224 } catch (RemoteException e) {
6225 // ignore
6226 }
6227 return;
6228 }
SongFerngWang0e767992021-03-31 22:08:45 +08006229 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6230 PersistableBundle c = configManager.getConfigForSubId(subId);
6231 boolean requireUssd = c.getBoolean(
6232 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006233
Shuo Qian4a594052020-01-23 11:59:30 -08006234 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006235 if (requireUssd) {
6236 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6237 getSubscriptionCarrierId(subId));
6238 String newUssdCommand = "";
6239 try {
6240 newUssdCommand = carrierXmlParser.getFeature(
6241 CarrierXmlParser.FEATURE_CALL_WAITING)
6242 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6243 } catch (NullPointerException e) {
6244 loge("Failed to generate USSD number" + e);
6245 }
6246 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6247 mMainThreadHandler, callback, carrierXmlParser,
6248 CarrierXmlParser.SsEntry.SSAction.QUERY);
6249 final String ussdCommand = newUssdCommand;
6250 Executors.newSingleThreadExecutor().execute(() -> {
6251 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6252 });
6253 } else {
6254 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6255 callback::accept);
6256 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6257 }
Shuo Qian4a594052020-01-23 11:59:30 -08006258 } finally {
6259 Binder.restoreCallingIdentity(identity);
6260 }
6261 }
6262
6263 /**
Hall Liu27d24262020-09-18 19:04:59 -07006264 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006265 */
6266 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006267 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006268 enforceModifyPermission();
6269 long identity = Binder.clearCallingIdentity();
6270 try {
Hall Liu27d24262020-09-18 19:04:59 -07006271 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6272
6273 Phone phone = getPhone(subId);
6274 if (phone == null) {
6275 try {
6276 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6277 } catch (RemoteException e) {
6278 // ignore
6279 }
6280 return;
6281 }
6282
SongFerngWang0e767992021-03-31 22:08:45 +08006283 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6284 PersistableBundle c = configManager.getConfigForSubId(subId);
6285 boolean requireUssd = c.getBoolean(
6286 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006287
SongFerngWang0e767992021-03-31 22:08:45 +08006288 if (DBG) log("getCallWaitingStatus: subId " + subId);
6289 if (requireUssd) {
6290 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6291 getSubscriptionCarrierId(subId));
6292 CarrierXmlParser.SsEntry.SSAction ssAction =
6293 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6294 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6295 String newUssdCommand = "";
6296 try {
6297 newUssdCommand = carrierXmlParser.getFeature(
6298 CarrierXmlParser.FEATURE_CALL_WAITING)
6299 .makeCommand(ssAction, null);
6300 } catch (NullPointerException e) {
6301 loge("Failed to generate USSD number" + e);
6302 }
6303 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6304 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6305 final String ussdCommand = newUssdCommand;
6306 Executors.newSingleThreadExecutor().execute(() -> {
6307 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6308 });
6309 } else {
6310 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6311 FunctionalUtils.ignoreRemoteException(callback::accept));
6312
6313 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6314 }
Shuo Qian4a594052020-01-23 11:59:30 -08006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
6318 }
6319
6320 /**
yinxub1bed742017-04-17 11:45:04 -07006321 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006322 *
yinxub1bed742017-04-17 11:45:04 -07006323 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006324 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6325 * location related information which will be sent if the caller already possess
6326 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006327 * @param request contains the radio access networks with bands/channels to scan
6328 * @param messenger callback messenger for scan results or errors
6329 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006330 * @return the id of the requested scan which can be used to stop the scan.
6331 */
6332 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006333 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6334 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006335 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006338 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006339 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6340 if (!renounceFineLocationAccess) {
6341 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6342 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6343 .setCallingPackage(callingPackage)
6344 .setCallingFeatureId(callingFeatureId)
6345 .setCallingPid(Binder.getCallingPid())
6346 .setCallingUid(Binder.getCallingUid())
6347 .setMethod("requestNetworkScan")
6348 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6349 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6350 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6351 .build());
6352 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006354 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6355 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006356 if (e != null) {
6357 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6358 throw e;
6359 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006360 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 return TelephonyScanManager.INVALID_SCAN_ID;
6362 }
6363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 }
Hall Liu912dfd32019-04-25 14:02:26 -07006365 int callingUid = Binder.getCallingUid();
6366 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006367 final long identity = Binder.clearCallingIdentity();
6368 try {
6369 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006370 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006371 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
yinxu504e1392017-04-12 16:03:22 -07006375 }
6376
Hall Liub2ac8ef2019-02-28 15:56:23 -08006377 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006378 NetworkScanRequest request, int subId, String callingPackage) {
6379 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006380 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6381 boolean hasNetworkScanPermission =
6382 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6383 == PERMISSION_GRANTED;
6384
6385 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6386 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6387 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006388 }
6389
6390 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6391 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006392 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6393 return new SecurityException("Specific channels must not be"
6394 + " scanned without location access.");
6395 }
6396 }
6397 }
6398
Hall Liub2ac8ef2019-02-28 15:56:23 -08006399 return null;
6400 }
6401
yinxu504e1392017-04-12 16:03:22 -07006402 /**
6403 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006404 *
6405 * @param subId id of the subscription
6406 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006407 */
6408 @Override
6409 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
Hall Liu912dfd32019-04-25 14:02:26 -07006413 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 final long identity = Binder.clearCallingIdentity();
6415 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006416 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
yinxu504e1392017-04-12 16:03:22 -07006420 }
6421
6422 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006424 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006425 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006426 */
6427 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006429 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006430 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006431 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006435 if (DBG) log("getAllowedNetworkTypesBitmask");
6436 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6437 int networkTypesBitmask = (result != null ? result[0] : -1);
6438 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6439 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006443 }
6444
6445 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006446 * Get the allowed network types for certain reason.
6447 *
6448 * @param subId the id of the subscription.
6449 * @param reason the reason the allowed network type change is taking place
6450 * @return the allowed network types.
6451 */
6452 @Override
6453 public long getAllowedNetworkTypesForReason(int subId,
6454 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006455 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006456 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
6465 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006466 * Enable/Disable E-UTRA-NR Dual Connectivity
6467 * @param subId subscription id of the sim card
6468 * @param nrDualConnectivityState expected NR dual connectivity state
6469 * This can be passed following states
6470 * <ol>
6471 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6472 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6473 * <li>Disable NR dual connectivity and force secondary cell to be released
6474 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6475 * </ol>
6476 * @return operation result.
6477 */
6478 @Override
6479 public int setNrDualConnectivityState(int subId,
6480 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6482 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006483 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006484 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6485 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6486 }
6487
Sooraj Sasindran37444802020-08-11 10:40:43 -07006488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6492 nrDualConnectivityState, subId,
6493 workSource);
6494 if (DBG) log("enableNRDualConnectivity result: " + result);
6495 return result;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500
6501 /**
6502 * Is E-UTRA-NR Dual Connectivity enabled
6503 * @return true if dual connectivity is enabled else false
6504 */
6505 @Override
6506 public boolean isNrDualConnectivityEnabled(int subId) {
6507 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006508 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006509 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006510 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006511 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6512 return false;
6513 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6518 null, subId, workSource);
6519 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6520 return isEnabled;
6521 } finally {
6522 Binder.restoreCallingIdentity(identity);
6523 }
6524 }
6525
6526 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006527 * Set the allowed network types of the device and
6528 * provide the reason triggering the allowed network change.
6529 *
6530 * @param subId the id of the subscription.
6531 * @param reason the reason the allowed network type change is taking place
6532 * @param allowedNetworkTypes the allowed network types.
6533 * @return true on success; false on any failure.
6534 */
6535 @Override
6536 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006537 @TelephonyManager.AllowedNetworkTypesReason int reason,
6538 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6540 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006542 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6543 return false;
6544 }
6545 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6546 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 return false;
6548 }
6549
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006550 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6551 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6552
6553
6554 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6555 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6556 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006558
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006559 final long identity = Binder.clearCallingIdentity();
6560 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006561 Boolean success = (Boolean) sendRequest(
6562 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6563 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6564
6565 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6566 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
6570 }
6571
6572 /**
Miaoa84611c2019-03-15 09:21:10 +08006573 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006574 *
Miaoa84611c2019-03-15 09:21:10 +08006575 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006576 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006577 * @hide
6578 */
6579 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006580 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006583 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 try {
Miaoa84611c2019-03-15 09:21:10 +08006585 if (phone != null) {
6586 return phone.hasMatchedTetherApnSetting();
6587 } else {
6588 return false;
6589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 } finally {
6591 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006592 }
Junda Liu475951f2014-11-07 16:45:03 -08006593 }
6594
6595 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006596 * Get the user enabled state of Mobile Data.
6597 *
6598 * TODO: remove and use isUserDataEnabled.
6599 * This can't be removed now because some vendor codes
6600 * calls through ITelephony directly while they should
6601 * use TelephonyManager.
6602 *
6603 * @return true on enabled
6604 */
6605 @Override
6606 public boolean getDataEnabled(int subId) {
6607 return isUserDataEnabled(subId);
6608 }
6609
6610 /**
6611 * Get whether mobile data is enabled per user setting.
6612 *
6613 * There are other factors deciding whether mobile data is actually enabled, but they are
6614 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006615 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006616 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6617 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006618 *
6619 * @return {@code true} if data is enabled else {@code false}
6620 */
6621 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006622 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006623 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006624 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006625 try {
6626 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6627 functionName);
6628 } catch (Exception e) {
6629 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6630 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006631 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 mApp, subId, functionName);
6634
Robert Greenwalt646120a2014-05-23 11:54:03 -07006635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 int phoneId = mSubscriptionController.getPhoneId(subId);
6640 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6641 Phone phone = PhoneFactory.getPhone(phoneId);
6642 if (phone != null) {
6643 boolean retVal = phone.isUserDataEnabled();
6644 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6645 return retVal;
6646 } else {
6647 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6648 return false;
6649 }
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006652 }
6653 }
6654
6655 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006656 * Checks if the device is capable of mobile data by considering whether whether the
6657 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6658 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006659 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006660 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006661 */
6662 @Override
6663 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006664 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 try {
6666 try {
6667 mApp.enforceCallingOrSelfPermission(
6668 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006669 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006670 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006671 try {
6672 mApp.enforceCallingOrSelfPermission(
6673 android.Manifest.permission.READ_PHONE_STATE,
6674 functionName);
6675 } catch (Exception e2) {
6676 mApp.enforceCallingOrSelfPermission(
6677 permission.READ_BASIC_PHONE_STATE, functionName);
6678 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006679 }
6680 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006681 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683
6684 final long identity = Binder.clearCallingIdentity();
6685 try {
6686 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006687 Phone phone = PhoneFactory.getPhone(phoneId);
6688 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006689 boolean retVal;
6690 if (phone.isUsingNewDataStack()) {
6691 retVal = phone.getDataNetworkController().getDataSettingsManager()
6692 .isDataEnabled();
6693 } else {
6694 retVal = phone.getDataEnabledSettings().isDataEnabled();
6695 }
6696 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 return retVal;
6698 } else {
6699 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6700 return false;
6701 }
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006704 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006705 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006706
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006707 /**
6708 * Check if data is enabled for a specific reason
6709 * @param subId Subscription index
6710 * @param reason the reason the data enable change is taking place
6711 * @return {@code true} if the overall data is enabled; {@code false} if not.
6712 */
6713 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006714 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006716 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006717 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006718 try {
6719 mApp.enforceCallingOrSelfPermission(
6720 android.Manifest.permission.ACCESS_NETWORK_STATE,
6721 functionName);
6722 } catch (Exception e) {
6723 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6724 functionName);
6725 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006726 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006727 try {
6728 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006729 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006730 } catch (Exception e2) {
6731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006732 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006733 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 }
6735
6736
6737 final long identity = Binder.clearCallingIdentity();
6738 try {
6739 int phoneId = mSubscriptionController.getPhoneId(subId);
6740 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006741 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 + " reason=" + reason);
6743 }
6744 Phone phone = PhoneFactory.getPhone(phoneId);
6745 if (phone != null) {
6746 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006747 if (phone.isUsingNewDataStack()) {
6748 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006749 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006750 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6751 retVal = phone.isUserDataEnabled();
6752 } else {
6753 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6754 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006755 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006756 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006757 return retVal;
6758 } else {
6759 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006760 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006761 + subId + " retVal=false");
6762 }
6763 return false;
6764 }
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
6768 }
6769
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006770 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006771 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006772 if (uid == Process.PHONE_UID) {
6773 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6774 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6776 }
6777
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006778 //load access rules from carrier configs, and check those as well: b/139133814
6779 SubscriptionController subController = SubscriptionController.getInstance();
6780 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6781 || subController == null) return privilegeFromSim;
6782
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006783 PackageManager pkgMgr = phone.getContext().getPackageManager();
6784 String[] packages = pkgMgr.getPackagesForUid(uid);
6785
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006788 int subId = phone.getSubId();
6789 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6790 // A test override is in place for the privileges for this subId, so don't try to
6791 // read the subscription privileges.
6792 return privilegeFromSim;
6793 }
6794 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006795 SubscriptionManager subManager = (SubscriptionManager)
6796 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6797 for (String pkg : packages) {
6798 if (subManager.canManageSubscription(subInfo, pkg)) {
6799 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6800 }
6801 }
6802 return privilegeFromSim;
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
6806 }
6807
6808 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6809 String pkgName) {
6810 //load access rules from carrier configs, and check those as well: b/139133814
6811 SubscriptionController subController = SubscriptionController.getInstance();
6812 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6813 || subController == null) return privilegeFromSim;
6814
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006817 int subId = phone.getSubId();
6818 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6819 // A test override is in place for the privileges for this subId, so don't try to
6820 // read the subscription privileges.
6821 return privilegeFromSim;
6822 }
6823 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006824 SubscriptionManager subManager = (SubscriptionManager)
6825 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6826 return subManager.canManageSubscription(subInfo, pkgName)
6827 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6828 } finally {
6829 Binder.restoreCallingIdentity(identity);
6830 }
6831 }
6832
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006833 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006834 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006835 // No permission needed; this only lets the caller inspect their own status.
6836 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006837 }
Junda Liu29340342014-07-10 15:23:27 -07006838
6839 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006841 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006842 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6843 }
6844
6845 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6846 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006847 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006848 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006849 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6850 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006851 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6852 if (cpt == null) {
6853 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6855 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006856 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006857 }
6858
6859 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006860 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006861 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006862 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006863 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006864 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006865 Phone phone = getPhone(subId);
6866 if (phone == null) {
6867 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6868 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6869 }
6870 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6871 if (cpt == null) {
6872 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006873 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6874 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006875 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006876 }
6877
6878 @Override
6879 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006880 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
6881 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006882 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006883 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006884 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006885 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6886 Phone phone = PhoneFactory.getPhone(phoneId);
6887 if (phone == null) {
6888 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006889 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006890 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6891 if (cpt == null) {
6892 continue;
6893 }
6894 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006895 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6896 break;
6897 }
6898 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006899 return result;
Junda Liu29340342014-07-10 15:23:27 -07006900 }
Derek Tan89e89d42014-07-08 17:00:10 -07006901
6902 @Override
Junda Liue64de782015-04-16 17:19:16 -07006903 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006904 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006905 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6906 loge("phoneId " + phoneId + " is not valid.");
6907 return null;
6908 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006909 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6910 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006911 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006912 return null ;
6913 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006914 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006915 }
6916
Amith Yamasani6e118872016-02-19 12:53:51 -08006917 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006918 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006919 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006920 Phone phone = PhoneFactory.getPhone(phoneId);
6921 if (phone == null) {
6922 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006923 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006924 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6925 if (cpt == null) {
6926 return Collections.emptyList();
6927 }
6928 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006929 }
6930
chen xuf7e9fe82019-05-09 19:31:02 -07006931 @Override
6932 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006933 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006934 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006935 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006936 try {
6937 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6938 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6939 }
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006942 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006943 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006944 }
6945
Wink Savilleb564aae2014-10-23 10:18:09 -07006946 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006947 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006948 UiccPort port = phone == null ? null : phone.getUiccPort();
6949 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006950 return null;
6951 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006952 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006953 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006954 return null;
6955 }
6956 return iccId;
6957 }
6958
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006959 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006960 public void setCallComposerStatus(int subId, int status) {
6961 enforceModifyPermission();
6962
6963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 Phone phone = getPhone(subId);
6966 if (phone != null) {
6967 Phone defaultPhone = phone.getImsPhone();
6968 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6969 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6970 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006971 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6972 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006973 }
6974 }
Shuo Qian284ae752020-12-22 19:10:14 -08006975 } catch (ImsException e) {
6976 throw new ServiceSpecificException(e.getCode());
6977 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006978 Binder.restoreCallingIdentity(identity);
6979 }
6980 }
6981
6982 @Override
6983 public int getCallComposerStatus(int subId) {
6984 enforceReadPrivilegedPermission("getCallComposerStatus");
6985
6986 final long identity = Binder.clearCallingIdentity();
6987 try {
6988 Phone phone = getPhone(subId);
6989 if (phone != null) {
6990 Phone defaultPhone = phone.getImsPhone();
6991 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6992 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6993 return imsPhone.getCallComposerStatus();
6994 }
6995 }
6996 } finally {
6997 Binder.restoreCallingIdentity(identity);
6998 }
6999 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7000 }
7001
7002 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007003 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7004 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007005 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007006 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 final String iccId = getIccId(subId);
7011 final Phone phone = getPhone(subId);
7012 if (phone == null) {
7013 return false;
7014 }
7015 final String subscriberId = phone.getSubscriberId();
7016
7017 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007018 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 + subscriberId + " to " + number);
7020 }
7021
7022 if (TextUtils.isEmpty(iccId)) {
7023 return false;
7024 }
7025
7026 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7027
7028 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7029 if (alphaTag == null) {
7030 editor.remove(alphaTagPrefKey);
7031 } else {
7032 editor.putString(alphaTagPrefKey, alphaTag);
7033 }
7034
7035 // Record both the line number and IMSI for this ICCID, since we need to
7036 // track all merged IMSIs based on line number
7037 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7038 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7039 if (number == null) {
7040 editor.remove(numberPrefKey);
7041 editor.remove(subscriberPrefKey);
7042 } else {
7043 editor.putString(numberPrefKey, number);
7044 editor.putString(subscriberPrefKey, subscriberId);
7045 }
7046
7047 editor.commit();
7048 return true;
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007051 }
Derek Tan7226c842014-07-02 17:42:23 -07007052 }
7053
7054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007055 public String getLine1NumberForDisplay(int subId, String callingPackage,
7056 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007057 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007059 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007060 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007061 return null;
7062 }
Derek Tan97ebb422014-09-05 16:55:38 -07007063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 final long identity = Binder.clearCallingIdentity();
7065 try {
7066 String iccId = getIccId(subId);
7067 if (iccId != null) {
7068 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7069 if (DBG_MERGE) {
7070 log("getLine1NumberForDisplay returning "
7071 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7072 }
7073 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7076 return null;
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007079 }
Derek Tan7226c842014-07-02 17:42:23 -07007080 }
7081
7082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007083 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7084 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007086 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007087 return null;
7088 }
Derek Tan97ebb422014-09-05 16:55:38 -07007089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 final long identity = Binder.clearCallingIdentity();
7091 try {
7092 String iccId = getIccId(subId);
7093 if (iccId != null) {
7094 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7095 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7096 }
7097 return null;
7098 } finally {
7099 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007100 }
Derek Tan7226c842014-07-02 17:42:23 -07007101 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007102
7103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007104 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7105 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007106 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7107 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007109 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007110 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007111 return null;
7112 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007113
Jordan Liub49b04b2019-05-06 14:45:15 -07007114 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7115 // the process, where TelephonyManager was instantiated.
7116 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007117 final long identity = Binder.clearCallingIdentity();
7118 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007119 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 final TelephonyManager tele = TelephonyManager.from(context);
7121 final SubscriptionManager sub = SubscriptionManager.from(context);
7122
7123 // Figure out what subscribers are currently active
7124 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125
Jordan Liub49b04b2019-05-06 14:45:15 -07007126 // Only consider subs which match the current subId
7127 // This logic can be simplified. See b/131189269 for progress.
7128 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007129 activeSubscriberIds.add(tele.getSubscriberId(subId));
7130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131
7132 // First pass, find a number override for an active subscriber
7133 String mergeNumber = null;
7134 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7135 for (String key : prefs.keySet()) {
7136 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7137 final String subscriberId = (String) prefs.get(key);
7138 if (activeSubscriberIds.contains(subscriberId)) {
7139 final String iccId = key.substring(
7140 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7141 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7142 mergeNumber = (String) prefs.get(numberKey);
7143 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007144 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 + " for active subscriber " + subscriberId);
7146 }
7147 if (!TextUtils.isEmpty(mergeNumber)) {
7148 break;
7149 }
7150 }
7151 }
7152 }
7153
7154 // Shortcut when no active merged subscribers
7155 if (TextUtils.isEmpty(mergeNumber)) {
7156 return null;
7157 }
7158
7159 // Second pass, find all subscribers under that line override
7160 final ArraySet<String> result = new ArraySet<>();
7161 for (String key : prefs.keySet()) {
7162 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7163 final String number = (String) prefs.get(key);
7164 if (mergeNumber.equals(number)) {
7165 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7166 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7167 final String subscriberId = (String) prefs.get(subscriberKey);
7168 if (!TextUtils.isEmpty(subscriberId)) {
7169 result.add(subscriberId);
7170 }
7171 }
7172 }
7173 }
7174
7175 final String[] resultArray = result.toArray(new String[result.size()]);
7176 Arrays.sort(resultArray);
7177 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007178 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7180 }
7181 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007182 } finally {
7183 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007184 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007185 }
7186
7187 @Override
zoey chen38003472019-12-13 17:16:31 +08007188 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7189 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007190
7191 final long identity = Binder.clearCallingIdentity();
7192 try {
7193 final TelephonyManager telephonyManager = mApp.getSystemService(
7194 TelephonyManager.class);
7195 String subscriberId = telephonyManager.getSubscriberId(subId);
7196 if (subscriberId == null) {
7197 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007198 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007199 + subId);
7200 }
7201 return null;
7202 }
7203
7204 final SubscriptionInfo info = SubscriptionController.getInstance()
7205 .getSubscriptionInfo(subId);
7206 final ParcelUuid groupUuid = info.getGroupUuid();
7207 // If it doesn't belong to any group, return just subscriberId of itself.
7208 if (groupUuid == null) {
7209 return new String[]{subscriberId};
7210 }
7211
7212 // Get all subscriberIds from the group.
7213 final List<String> mergedSubscriberIds = new ArrayList<>();
7214 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007215 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007216 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007217 for (SubscriptionInfo subInfo : groupInfos) {
7218 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7219 if (subscriberId != null) {
7220 mergedSubscriberIds.add(subscriberId);
7221 }
7222 }
7223
7224 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227
7228 }
7229 }
7230
7231 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007232 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007233 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007234 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235
7236 final long identity = Binder.clearCallingIdentity();
7237 try {
7238 final Phone phone = getPhone(subId);
7239 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007243 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007244
7245 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007246 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007247 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7248 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007249 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7250 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251
7252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 final Phone phone = getPhone(subId);
7255 if (phone == null) {
7256 return false;
7257 }
7258 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7259 cdmaNonRoamingList);
7260 } finally {
7261 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007262 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007263 }
7264
7265 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007266 @Deprecated
7267 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7268 enforceModifyPermission();
7269
7270 int returnValue = 0;
7271 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007272 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007273 if(result.exception == null) {
7274 if (result.result != null) {
7275 byte[] responseData = (byte[])(result.result);
7276 if(responseData.length > oemResp.length) {
7277 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7278 responseData.length + "bytes. Buffer Size is " +
7279 oemResp.length + "bytes.");
7280 }
7281 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7282 returnValue = responseData.length;
7283 }
7284 } else {
7285 CommandException ex = (CommandException) result.exception;
7286 returnValue = ex.getCommandError().ordinal();
7287 if(returnValue > 0) returnValue *= -1;
7288 }
7289 } catch (RuntimeException e) {
7290 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7291 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7292 if(returnValue > 0) returnValue *= -1;
7293 }
7294
7295 return returnValue;
7296 }
7297
7298 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007299 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007300 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007301 try {
7302 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007303 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007304 mApp, phone.getSubId(), "getRadioAccessFamily");
7305 } catch (SecurityException e) {
7306 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7307 throw e;
7308 }
chen xub97461a2018-10-26 14:17:57 -07007309 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007310 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007311 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 final long identity = Binder.clearCallingIdentity();
7314 try {
chen xub97461a2018-10-26 14:17:57 -07007315 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007316 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007317 mApp, phone.getSubId(), "getRadioAccessFamily");
7318 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 } finally {
7320 Binder.restoreCallingIdentity(identity);
7321 }
chen xub97461a2018-10-26 14:17:57 -07007322 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007323 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007324
7325 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007326 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007327 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007328 try {
7329 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7330 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007331 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007332 }
7333 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007334 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007335 }
7336 RoleManager rm = mApp.getSystemService(RoleManager.class);
7337 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7338 if (!dialerRoleHolders.contains(callingPackage)) {
7339 throw new SecurityException("App must be the dialer role holder to"
7340 + " upload a call composer pic");
7341 }
7342
7343 Executors.newSingleThreadExecutor().execute(() -> {
7344 ByteArrayOutputStream output = new ByteArrayOutputStream(
7345 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7346 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7347 boolean readUntilEnd = false;
7348 int totalBytesRead = 0;
7349 byte[] buffer = new byte[16 * 1024];
7350 while (true) {
7351 int numRead;
7352 try {
7353 numRead = input.read(buffer);
7354 } catch (IOException e) {
7355 try {
7356 fd.checkError();
7357 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7358 null);
7359 } catch (IOException e1) {
7360 // This means that the other side closed explicitly with an error. If this
7361 // happens, log and ignore.
7362 loge("Remote end of call composer picture pipe closed: " + e1);
7363 }
7364 break;
7365 }
7366 if (numRead == -1) {
7367 readUntilEnd = true;
7368 break;
7369 }
7370 totalBytesRead += numRead;
7371 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7372 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7373 try {
7374 input.close();
7375 } catch (IOException e) {
7376 // ignore
7377 }
7378 break;
7379 }
7380 output.write(buffer, 0, numRead);
7381 }
7382 // Generally, the remote end will close the file descriptors. The only case where we
7383 // close is above, where the picture size is too big.
7384
7385 try {
7386 fd.checkError();
7387 } catch (IOException e) {
7388 loge("Remote end for call composer closed with an error: " + e);
7389 return;
7390 }
7391
Hall Liuaa4211e2021-01-20 15:43:39 -08007392 if (!readUntilEnd) {
7393 loge("Did not finish reading entire image; aborting");
7394 return;
7395 }
Hall Liu82694d52020-12-11 18:22:04 -08007396
Hall Liuaa4211e2021-01-20 15:43:39 -08007397 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7398 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7399 new CallComposerPictureTransfer.Factory() {},
7400 imageData,
7401 (result) -> {
7402 if (result.first != null) {
7403 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7404 Bundle outputResult = new Bundle();
7405 outputResult.putParcelable(
7406 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7407 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7408 outputResult);
7409 } else {
7410 callback.send(result.second, null);
7411 }
7412 }
7413 );
Hall Liu82694d52020-12-11 18:22:04 -08007414 });
7415 }
7416
7417 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007418 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007419 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007424 ImsManager.getInstance(defaultPhone.getContext(),
7425 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 } finally {
7427 Binder.restoreCallingIdentity(identity);
7428 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007429 }
7430
7431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007432 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007433 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7435 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007436 return false;
7437 }
Svet Ganovb320e182015-04-16 12:30:10 -07007438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 final long identity = Binder.clearCallingIdentity();
7440 try {
7441 // Check the user preference and the system-level IMS setting. Even if the user has
7442 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7443 // In the long run, we may instead need to check if there exists a connection service
7444 // which can support video calling.
7445 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007446 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 return imsManager.isVtEnabledByPlatform()
7448 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7449 && imsManager.isVtEnabledByUser();
7450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007453 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007454
Andrew Leea1239f22015-03-02 17:44:07 -08007455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007456 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7457 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007459 mApp, subId, callingPackage, callingFeatureId,
7460 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 return false;
7462 }
7463
7464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 CarrierConfigManager configManager =
7467 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007468 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
Andrew Leea1239f22015-03-02 17:44:07 -08007473 }
7474
7475 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007476 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 return false;
7480 }
7481
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 CarrierConfigManager configManager =
7485 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Andrew Leea1239f22015-03-02 17:44:07 -08007491 }
7492
Andrew Lee9431b832015-03-09 18:46:45 -07007493 @Override
7494 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007495 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007496 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007497 }
7498
7499 @Override
7500 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 final long identity = Binder.clearCallingIdentity();
7502 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007503 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
Andrew Lee9431b832015-03-09 18:46:45 -07007507 }
7508
Hall Liuf6668912018-10-31 17:05:23 -07007509 /**
7510 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7511 * support for the feature and device firmware support.
7512 *
7513 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7514 */
7515 @Override
7516 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007518 final Phone phone = getPhone(subscriptionId);
7519 if (phone == null) {
7520 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7521 return false;
7522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007524 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7526 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007527 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 return isCarrierSupported && isDeviceSupported;
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
Hall Liu98187582018-01-22 19:15:32 -08007532 }
7533
Hall Liuf6668912018-10-31 17:05:23 -07007534 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007535 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7536 * RTT setting, will return true if the device and carrier both support RTT.
7537 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007538 */
7539 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 final long identity = Binder.clearCallingIdentity();
7541 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007542 boolean isRttSupported = isRttSupported(subscriptionId);
7543 boolean isUserRttSettingOn = Settings.Secure.getInt(
7544 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7545 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7546 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7547 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 } finally {
7549 Binder.restoreCallingIdentity(identity);
7550 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007551 }
7552
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007553 @Deprecated
7554 @Override
7555 public String getDeviceId(String callingPackage) {
7556 return getDeviceIdWithFeature(callingPackage, null);
7557 }
7558
Sanket Padawe7310cc72015-01-14 09:53:20 -08007559 /**
7560 * Returns the unique device ID of phone, for example, the IMEI for
7561 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7562 *
7563 * <p>Requires Permission:
7564 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7565 */
7566 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007567 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007568 try {
7569 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7570 } catch (SecurityException se) {
7571 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7572 throw new SecurityException("Package " + callingPackage + " does not belong to "
7573 + Binder.getCallingUid());
7574 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007575 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007576 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007577 return null;
7578 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007579 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007580 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007581 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007582 return null;
7583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584
7585 final long identity = Binder.clearCallingIdentity();
7586 try {
7587 return phone.getDeviceId();
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
7590 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007591 }
7592
Ping Sunc67b7c22016-03-02 19:16:45 +08007593 /**
7594 * {@hide}
7595 * Returns the IMS Registration Status on a particular subid
7596 *
7597 * @param subId
7598 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007599 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007600 Phone phone = getPhone(subId);
7601 if (phone != null) {
7602 return phone.isImsRegistered();
7603 } else {
7604 return false;
7605 }
7606 }
7607
Santos Cordon7a1885b2015-02-03 11:15:19 -08007608 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007609 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007610 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007612 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007613 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7614 }
7615 final long identity = Binder.clearCallingIdentity();
7616 try {
7617 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7618 } finally {
7619 Binder.restoreCallingIdentity(identity);
7620 }
7621 }
7622
7623 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007624 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007625 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007626 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007627 mApp,
7628 subscriptionId,
7629 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 Phone phone = getPhone(subscriptionId);
7633 if (phone == null) {
7634 return null;
7635 }
7636 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
7640 }
7641
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007642 /**
7643 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007644 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007645 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 Phone phone = getPhone(subId);
7649 if (phone != null) {
7650 return phone.isWifiCallingEnabled();
7651 } else {
7652 return false;
7653 }
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007656 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007657 }
7658
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007659 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007661 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 Phone phone = getPhone(subId);
7666 if (phone != null) {
7667 return phone.isVideoEnabled();
7668 } else {
7669 return false;
7670 }
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007673 }
7674 }
7675
7676 /**
7677 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7678 * defined in {@link ImsRegistrationImplBase}.
7679 */
7680 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 Phone phone = getPhone(subId);
7684 if (phone != null) {
7685 return phone.getImsRegistrationTech();
7686 } else {
7687 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7688 }
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007692 }
7693
Stuart Scott8eef64f2015-04-08 15:13:54 -07007694 @Override
7695 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007696 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007697 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7698 return;
7699 }
Kai Shif70f46f2021-03-03 13:59:46 -08007700 Phone defaultPhone = getDefaultPhone();
7701 if (defaultPhone != null) {
7702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7703 mApp, getDefaultPhone().getSubId(), "factoryReset");
7704 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007705 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007706
Svet Ganovcc087f82015-05-12 20:35:54 -07007707 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007708 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7709 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007710 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007711 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007712 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007713 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007714 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007715 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007716 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007717 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007718 // There has been issues when Sms raw table somehow stores orphan
7719 // fragments. They lead to garbled message when new fragments come
7720 // in and combined with those stale ones. In case this happens again,
7721 // user can reset all network settings which will clean up this table.
7722 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007723 // Clean up IMS settings as well here.
7724 int slotId = getSlotIndex(subId);
7725 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7726 ImsManager.getInstance(mApp, slotId).factoryReset();
7727 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007728
Kai Shif70f46f2021-03-03 13:59:46 -08007729 if (defaultPhone == null) {
7730 return;
7731 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007732 // Erase modem config if erase modem on network setting is enabled.
7733 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7734 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7735 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007736 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007737 }
Kai Shif70f46f2021-03-03 13:59:46 -08007738
7739 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007740 } finally {
7741 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007742 }
7743 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007744
SongFerngWangfd89b102021-05-27 22:44:54 +08007745 @VisibleForTesting
7746 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7747 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7748 return;
7749 }
7750 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7751 RILConstants.PREFERRED_NETWORK_MODE);
7752 SubscriptionManager.setSubscriptionProperty(subId,
7753 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7754 "user=" + defaultNetworkType);
7755 phone.loadAllowedNetworksFromSubscriptionDatabase();
7756 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7757 defaultNetworkType, null);
7758 }
7759
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007760 private void cleanUpSmsRawTable(Context context) {
7761 ContentResolver resolver = context.getContentResolver();
7762 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7763 resolver.delete(uri, null, null);
7764 }
7765
Narayan Kamath1c496c22015-04-16 14:40:19 +01007766 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007767 public String getSimLocaleForSubscriber(int subId) {
7768 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7769 final Phone phone = getPhone(subId);
7770 if (phone == null) {
7771 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007772 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 final long identity = Binder.clearCallingIdentity();
7775 try {
chen xu5d3637b2019-01-21 23:31:38 -08007776 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007777 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007778 if (info == null) {
7779 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7780 return null;
7781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 // Try and fetch the locale from the carrier properties or from the SIM language
7783 // preferences (EF-PL and EF-LI)...
7784 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007786 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7787 if (localeFromDefaultSim != null) {
7788 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7789 if (DBG) log("Using locale from subId: " + subId + " locale: "
7790 + localeFromDefaultSim);
7791 return localeFromDefaultSim.toLanguageTag();
7792 } else {
7793 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 }
7795 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 // The SIM language preferences only store a language (e.g. fr = French), not an
7798 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7799 // the SIM and carrier preferences does not include a country we add the country
7800 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007801 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007803 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804 return mccLocale.toLanguageTag();
7805 }
7806
7807 if (DBG) log("No locale found - returning null");
7808 return null;
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
7811 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007812 }
7813
7814 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007815 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007816 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007817 }
7818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 /**
7820 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7821 */
7822 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007824 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007825 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007826
Chenjie Yu1ba97252018-01-11 18:16:20 -08007827 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007828 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007829
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007830 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007831 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7832 * representing the state of the modem.
7833 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007834 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7835 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007836 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007837 */
7838 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007839 public void requestModemActivityInfo(ResultReceiver result) {
7840 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007841 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842
7843 final long identity = Binder.clearCallingIdentity();
7844 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007845 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 } finally {
7847 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007849 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007850
Siddharth Rayb8114062018-06-17 15:02:38 -07007851 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7852 // less than total activity duration.
7853 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7854 if (info == null) {
7855 return false;
7856 }
7857 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007858 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7859 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7860
Siddharth Rayb8114062018-06-17 15:02:38 -07007861 return (info.isValid()
7862 && (info.getSleepTimeMillis() <= activityDurationMs)
7863 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007864 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007865 && (totalTxTimeMs <= activityDurationMs));
7866 }
7867
Jack Yu85bd38a2015-11-09 11:34:32 -08007868 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007869 * Returns the service state information on specified subscription.
7870 */
7871 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007872 public ServiceState getServiceStateForSubscriber(int subId,
7873 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7874 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007876 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007877 return null;
7878 }
7879
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007880 boolean hasFinePermission = false;
7881 boolean hasCoarsePermission = false;
7882 if (!renounceFineLocationAccess) {
7883 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7884 LocationAccessPolicy.checkLocationPermission(mApp,
7885 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7886 .setCallingPackage(callingPackage)
7887 .setCallingFeatureId(callingFeatureId)
7888 .setCallingPid(Binder.getCallingPid())
7889 .setCallingUid(Binder.getCallingUid())
7890 .setMethod("getServiceStateForSubscriber")
7891 .setLogAsInfo(true)
7892 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7893 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7894 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7895 .build());
7896 hasFinePermission =
7897 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7898 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007899
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007900 if (!renounceCoarseLocationAccess) {
7901 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7902 LocationAccessPolicy.checkLocationPermission(mApp,
7903 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7904 .setCallingPackage(callingPackage)
7905 .setCallingFeatureId(callingFeatureId)
7906 .setCallingPid(Binder.getCallingPid())
7907 .setCallingUid(Binder.getCallingUid())
7908 .setMethod("getServiceStateForSubscriber")
7909 .setLogAsInfo(true)
7910 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7911 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7912 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7913 .build());
7914 hasCoarsePermission =
7915 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7916 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007917
Jack Yu479f40e2020-10-27 21:29:25 -07007918 final Phone phone = getPhone(subId);
7919 if (phone == null) {
7920 return null;
7921 }
7922
Jordan Liu0f2bc442020-11-18 16:47:37 -08007923 final long identity = Binder.clearCallingIdentity();
7924
Jack Yu479f40e2020-10-27 21:29:25 -07007925 boolean isCallingPackageDataService = phone.getDataServicePackages()
7926 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007928 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7929 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7930 Rlog.d(LOG_TAG,
7931 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7932 return null;
7933 }
7934
Hall Liuf19c44f2018-11-27 14:38:17 -08007935 ServiceState ss = phone.getServiceState();
7936
7937 // Scrub out the location info in ServiceState depending on what level of access
7938 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007939 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007940 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7941 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 } finally {
7943 Binder.restoreCallingIdentity(identity);
7944 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007945 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007946
7947 /**
7948 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7949 *
7950 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7951 * voicemail ringtone.
7952 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7953 * PhoneAccount.
7954 */
7955 @Override
7956 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7960 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007961 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
7967 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007968 }
7969
7970 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007971 * Sets the per-account voicemail ringtone.
7972 *
7973 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7974 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7975 *
7976 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7977 * voicemail ringtone.
7978 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7979 * PhoneAccount.
7980 */
7981 @Override
7982 public void setVoicemailRingtoneUri(String callingPackage,
7983 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007984 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007986 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7987 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7989 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7990 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992
7993 final long identity = Binder.clearCallingIdentity();
7994 try {
7995 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7996 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007997 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998 }
7999 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8000 } finally {
8001 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008002 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008003 }
8004
8005 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008006 * Returns whether vibration is set for voicemail notification in Phone settings.
8007 *
8008 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8009 * voicemail vibration setting.
8010 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8011 */
8012 @Override
8013 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 final long identity = Binder.clearCallingIdentity();
8015 try {
8016 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8017 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008018 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8022 } finally {
8023 Binder.restoreCallingIdentity(identity);
8024 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008025 }
8026
Youhan Wange64578a2016-05-02 15:32:42 -07008027 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008028 * Sets the per-account voicemail vibration.
8029 *
8030 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8031 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8032 *
8033 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8034 * voicemail vibration setting.
8035 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8036 * specific PhoneAccount.
8037 */
8038 @Override
8039 public void setVoicemailVibrationEnabled(String callingPackage,
8040 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008041 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008043 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8044 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8046 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8047 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008048 }
8049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8053 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008054 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 }
8056 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008059 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008060 }
8061
8062 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008063 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8064 *
8065 * @throws SecurityException if the caller does not have the required permission
8066 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008067 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008068 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008069 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008070 }
8071
8072 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008073 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8074 * permission.
8075 *
8076 * @throws SecurityException if the caller does not have the required permission
8077 */
8078 private void enforceSendSmsPermission() {
8079 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8080 }
8081
8082 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008083 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008084 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008085 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008086 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008087 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 final long identity = Binder.clearCallingIdentity();
8089 try {
8090 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008091 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 if (componentName == null) {
8093 throw new SecurityException(
8094 "Caller not current active visual voicemail package[null]");
8095 }
8096 String vvmPackage = componentName.getPackageName();
8097 if (!callingPackage.equals(vvmPackage)) {
8098 throw new SecurityException("Caller not current active visual voicemail package["
8099 + vvmPackage + "]");
8100 }
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008103 }
8104 }
8105
8106 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008107 * Return the application ID for the app type.
8108 *
8109 * @param subId the subscription ID that this request applies to.
8110 * @param appType the uicc app type.
8111 * @return Application ID for specificied app type, or null if no uicc.
8112 */
8113 @Override
8114 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008115 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008116 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117
8118 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008119 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 if (phone == null) {
8121 return null;
8122 }
8123 String aid = null;
8124 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008125 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 .getApplicationByType(appType).getAid();
8127 } catch (Exception e) {
8128 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8129 }
8130 return aid;
8131 } finally {
8132 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008133 }
Youhan Wange64578a2016-05-02 15:32:42 -07008134 }
8135
Youhan Wang4001d252016-05-11 10:29:41 -07008136 /**
8137 * Return the Electronic Serial Number.
8138 *
8139 * @param subId the subscription ID that this request applies to.
8140 * @return ESN or null if error.
8141 */
8142 @Override
8143 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008144 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008145 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146
8147 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008148 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149 if (phone == null) {
8150 return null;
8151 }
8152 String esn = null;
8153 try {
8154 esn = phone.getEsn();
8155 } catch (Exception e) {
8156 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8157 }
8158 return esn;
8159 } finally {
8160 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008161 }
Youhan Wang4001d252016-05-11 10:29:41 -07008162 }
8163
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008164 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008165 * Return the Preferred Roaming List Version.
8166 *
8167 * @param subId the subscription ID that this request applies to.
8168 * @return PRLVersion or null if error.
8169 */
8170 @Override
8171 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008172 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008173 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008174
8175 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008176 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177 if (phone == null) {
8178 return null;
8179 }
8180 String cdmaPrlVersion = null;
8181 try {
8182 cdmaPrlVersion = phone.getCdmaPrlVersion();
8183 } catch (Exception e) {
8184 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8185 }
8186 return cdmaPrlVersion;
8187 } finally {
8188 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008190 }
8191
8192 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008193 * Get snapshot of Telephony histograms
8194 * @return List of Telephony histograms
8195 * @hide
8196 */
8197 @Override
8198 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8200 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201
8202 final long identity = Binder.clearCallingIdentity();
8203 try {
8204 return RIL.getTelephonyRILTimingHistograms();
8205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008208 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008209
8210 /**
8211 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008212 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8213 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008214 * Require system privileges. In the future we may add this to carrier APIs.
8215 *
Michele Berionne482f8202018-11-27 18:57:59 -08008216 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008217 */
8218 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008219 @TelephonyManager.SetCarrierRestrictionResult
8220 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008221 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008223
Michele Berionne482f8202018-11-27 18:57:59 -08008224 if (carrierRestrictionRules == null) {
8225 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008226 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 final long identity = Binder.clearCallingIdentity();
8229 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008230 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008231 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 } finally {
8233 Binder.restoreCallingIdentity(identity);
8234 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008235 }
8236
8237 /**
8238 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008239 * Get the allowed carrier list and the excluded carrier list, including the priority between
8240 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008241 * Require system privileges. In the future we may add this to carrier APIs.
8242 *
Michele Berionne482f8202018-11-27 18:57:59 -08008243 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008244 */
8245 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008246 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008247 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008248 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249
8250 final long identity = Binder.clearCallingIdentity();
8251 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008252 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8253 if (response instanceof CarrierRestrictionRules) {
8254 return (CarrierRestrictionRules) response;
8255 }
8256 // Response is an Exception of some kind,
8257 // which is signalled to the user as a NULL retval
8258 return null;
8259 } catch (Exception e) {
8260 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8261 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 } finally {
8263 Binder.restoreCallingIdentity(identity);
8264 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008265 }
8266
fionaxu59545b42016-05-25 15:53:37 -07008267 /**
fionaxu59545b42016-05-25 15:53:37 -07008268 * Action set from carrier signalling broadcast receivers to enable/disable radio
8269 * @param subId the subscription ID that this action applies to.
8270 * @param enabled control enable or disable radio.
8271 * {@hide}
8272 */
8273 @Override
8274 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8275 enforceModifyPermission();
8276 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277
8278 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008279 if (phone == null) {
8280 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8281 return;
8282 }
8283 try {
8284 phone.carrierActionSetRadioEnabled(enabled);
8285 } catch (Exception e) {
8286 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 } finally {
8288 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008289 }
8290 }
8291
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008292 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008293 * Enable or disable Voice over NR (VoNR)
8294 * @param subId the subscription ID that this action applies to.
8295 * @param enabled enable or disable VoNR.
8296 * @return operation result.
8297 */
8298 @Override
8299 public int setVoNrEnabled(int subId, boolean enabled) {
8300 enforceModifyPermission();
8301 final Phone phone = getPhone(subId);
8302
8303 final long identity = Binder.clearCallingIdentity();
8304 if (phone == null) {
8305 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8306 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8307 }
8308
8309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8310 try {
8311 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8312 workSource);
8313 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008314
8315 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8316 if (DBG) {
8317 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8318 }
8319 SubscriptionManager.setSubscriptionProperty(
8320 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8321 (enabled ? "1" : "0"));
8322 }
8323
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008324 return result;
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 }
8329
8330 /**
8331 * Is voice over NR enabled
8332 * @return true if VoNR is enabled else false
8333 */
8334 @Override
8335 public boolean isVoNrEnabled(int subId) {
8336 enforceReadPrivilegedPermission("isVoNrEnabled");
8337 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8341 null, subId, workSource);
8342 if (DBG) log("isVoNrEnabled: " + isEnabled);
8343 return isEnabled;
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
8347 }
8348
8349 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008350 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8351 * network status based on which carrier apps could apply actions accordingly,
8352 * enable/disable default url handler for example.
8353 *
8354 * @param subId the subscription ID that this action applies to.
8355 * @param report control start/stop reporting the default network status.
8356 * {@hide}
8357 */
8358 @Override
8359 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8360 enforceModifyPermission();
8361 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362
8363 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008364 if (phone == null) {
8365 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8366 return;
8367 }
8368 try {
8369 phone.carrierActionReportDefaultNetworkStatus(report);
8370 } catch (Exception e) {
8371 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 } finally {
8373 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008374 }
8375 }
8376
8377 /**
fionaxud9622282017-07-17 17:51:30 -07008378 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8379 * @param subId the subscription ID that this action applies to.
8380 * {@hide}
8381 */
8382 @Override
8383 public void carrierActionResetAll(int subId) {
8384 enforceModifyPermission();
8385 final Phone phone = getPhone(subId);
8386 if (phone == null) {
8387 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8388 return;
8389 }
8390 try {
8391 phone.carrierActionResetAll();
8392 } catch (Exception e) {
8393 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8394 }
8395 }
8396
8397 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008398 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8399 * bug report is being generated.
8400 */
8401 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008402 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008403 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8404 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008405 writer.println("Permission Denial: can't dump Phone from pid="
8406 + Binder.getCallingPid()
8407 + ", uid=" + Binder.getCallingUid()
8408 + "without permission "
8409 + android.Manifest.permission.DUMP);
8410 return;
8411 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008412 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008413 }
Jack Yueb89b242016-06-22 13:27:47 -07008414
Brad Ebingerdac2f002018-04-03 15:17:52 -07008415 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008416 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8417 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8418 @NonNull String[] args) {
8419 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8420 this, in.getFileDescriptor(), out.getFileDescriptor(),
8421 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008422 }
8423
Jack Yueb89b242016-06-22 13:27:47 -07008424 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008425 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008426 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008427 * @param reason the reason the data enable change is taking place
8428 * @param enabled True if enabling the data, otherwise disabling.
8429 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008430 */
8431 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008432 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008433 boolean enabled) {
8434 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8435 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8436 try {
8437 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008438 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008439 } catch (SecurityException se) {
8440 enforceModifyPermission();
8441 }
8442 } else {
8443 enforceModifyPermission();
8444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 Phone phone = getPhone(subId);
8449 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008450 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8451 phone.carrierActionSetMeteredApnsEnabled(enabled);
8452 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008453 if (phone.isUsingNewDataStack()) {
8454 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8455 } else {
8456 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8457 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459 }
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008462 }
8463 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008464
8465 /**
8466 * Get Client request stats
8467 * @return List of Client Request Stats
8468 * @hide
8469 */
8470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008471 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8472 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008474 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008475 return null;
8476 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008477 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 if (phone != null) {
8482 return phone.getClientRequestStats();
8483 }
8484
8485 return null;
8486 } finally {
8487 Binder.restoreCallingIdentity(identity);
8488 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008489 }
8490
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008491 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008492 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008493 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008494 }
Jack Yueb4124c2017-02-16 15:32:43 -08008495
8496 /**
Grace Chen70990072017-03-24 17:21:30 -07008497 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008498 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008499 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008500 * @param state State of SIM (power down, power up, pass through)
8501 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8502 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8503 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008504 *
8505 **/
8506 @Override
Grace Chen70990072017-03-24 17:21:30 -07008507 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008508 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008509 Phone phone = PhoneFactory.getPhone(slotIndex);
8510
vagdeviaf9a5b92018-08-15 16:01:53 -07008511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008516 phone.setSimPowerState(state, null, workSource);
8517 }
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
8521 }
8522
8523 /**
8524 * Set SIM card power state.
8525 *
8526 * @param slotIndex SIM slot id.
8527 * @param state State of SIM (power down, power up, pass through)
8528 * @param callback callback to trigger after success or failure
8529 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8531 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8532 *
8533 **/
8534 @Override
8535 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8536 IIntegerConsumer callback) {
8537 enforceModifyPermission();
8538 Phone phone = PhoneFactory.getPhone(slotIndex);
8539
8540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8541
8542 final long identity = Binder.clearCallingIdentity();
8543 try {
8544 if (phone != null) {
8545 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8546 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547 }
8548 } finally {
8549 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008550 }
8551 }
Shuo Qiandd210312017-04-12 22:11:33 +00008552
Tyler Gunn65d45c22017-06-05 11:22:26 -07008553 private boolean isUssdApiAllowed(int subId) {
8554 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008555 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008556 if (configManager == null) {
8557 return false;
8558 }
8559 PersistableBundle pb = configManager.getConfigForSubId(subId);
8560 if (pb == null) {
8561 return false;
8562 }
8563 return pb.getBoolean(
8564 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8565 }
8566
Shuo Qiandd210312017-04-12 22:11:33 +00008567 /**
8568 * Check if phone is in emergency callback mode
8569 * @return true if phone is in emergency callback mode
8570 * @param subId sub id
8571 */
goneil9c5f4872017-12-05 14:07:56 -08008572 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008573 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008574 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008575 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008576
8577 final long identity = Binder.clearCallingIdentity();
8578 try {
8579 if (phone != null) {
8580 return phone.isInEcm();
8581 } else {
8582 return false;
8583 }
8584 } finally {
8585 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008586 }
8587 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008588
8589 /**
8590 * Get the current signal strength information for the given subscription.
8591 * Because this information is not updated when the device is in a low power state
8592 * it should not be relied-upon to be current.
8593 * @param subId Subscription index
8594 * @return the most recent cached signal strength info from the modem
8595 */
8596 @Override
8597 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 Phone p = getPhone(subId);
8601 if (p == null) {
8602 return null;
8603 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 return p.getSignalStrength();
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
8608 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008609 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008610
Pengquan Meng77b7f132018-08-22 14:49:57 -07008611 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008612 * Get the current modem radio state for the given slot.
8613 * @param slotIndex slot index.
8614 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008615 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008616 * @return the current radio power state from the modem
8617 */
8618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008619 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008620 Phone phone = PhoneFactory.getPhone(slotIndex);
8621 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8623 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008624 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8625 }
8626
8627 final long identity = Binder.clearCallingIdentity();
8628 try {
8629 return phone.getRadioPowerState();
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8635 }
8636
8637 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008638 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8639 *
8640 * <p>Requires one of the following permissions:
8641 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008642 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008643 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8644 * privileges.
8645 *
8646 * @param subId subscription id
8647 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8648 * {@code false}.
8649 */
8650 @Override
8651 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008652 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008653 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008654 try {
8655 mApp.enforceCallingOrSelfPermission(
8656 android.Manifest.permission.ACCESS_NETWORK_STATE,
8657 functionName);
8658 } catch (Exception e) {
8659 mApp.enforceCallingOrSelfPermission(
8660 permission.READ_BASIC_PHONE_STATE, functionName);
8661 }
Shuo Qian093013d2020-08-13 15:42:55 -07008662 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008663 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008664 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008665 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008666
Pengquan Menga1bb6272018-09-06 09:59:22 -07008667 boolean isEnabled = false;
8668 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008669 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008670 Phone phone = getPhone(subId);
8671 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008672 } finally {
8673 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008675 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008676 }
8677
8678
8679 /**
8680 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8681 *
8682 * <p> Requires permission:
8683 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8684 * privileges.
8685 *
8686 * @param subId subscription id
8687 * @param isEnabled {@code true} means enable, {@code false} means disable.
8688 */
8689 @Override
8690 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8692 mApp, subId, "setDataRoamingEnabled");
8693
Pengquan Menga1bb6272018-09-06 09:59:22 -07008694 final long identity = Binder.clearCallingIdentity();
8695 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008696 Phone phone = getPhone(subId);
8697 if (phone != null) {
8698 phone.setDataRoamingEnabled(isEnabled);
8699 }
8700 } finally {
8701 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008702 }
8703 }
8704
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008705 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008706 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008707 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008708 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008709 mApp, subId, "isManualNetworkSelectionAllowed");
8710
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008711 boolean isAllowed = true;
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008714 Phone phone = getPhone(subId);
8715 if (phone != null) {
8716 isAllowed = phone.isCspPlmnEnabled();
8717 }
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
8720 }
8721 return isAllowed;
8722 }
8723
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008724 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8725 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008726 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008727 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008728 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008729 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8730 if (phone == null) {
8731 return false;
8732 }
8733 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8734 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8735 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008736 }
8737
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008738 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008739 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008740 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008741 mApp.getSystemService(AppOpsManager.class)
8742 .checkPackage(Binder.getCallingUid(), callingPackage);
8743
Jordan Liu1e142fc2019-04-22 15:10:43 -07008744 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008745 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008746 try {
8747 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008748 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008749 } catch (SecurityException e) {
8750 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8751 // has carrier privileges on an active UICC
8752 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8753 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008754 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008755 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008756 }
sandeepjsb6c87872021-09-27 15:34:44 +00008757 // checking compatibility, if calling app's target SDK is T and beyond.
8758 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8759 Binder.getCallingUid())) {
8760 isIccIdAccessRestricted = true;
8761 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008762 final long identity = Binder.clearCallingIdentity();
8763 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008764 UiccController uiccController = UiccController.getInstance();
8765 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008766 if (hasReadPermission) {
8767 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008768 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008769
8770 // Remove private info if the caller doesn't have access
8771 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8772 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008773 //setting the value after compatibility check
8774 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008775 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8776 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008777 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008778 if (card == null) {
8779 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008780 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008781 continue;
8782 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008783 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8784 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008785 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008786 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008787 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008788 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8789 for (UiccPortInfo portInfo : portInfos) {
8790 UiccPort port = uiccController.getUiccPortForSlot(
8791 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8792 if (port == null) {
8793 // assume no access if port is null
8794 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8795 continue;
8796 }
8797 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8798 uiccPortInfos.add(portInfo);
8799 } else {
8800 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8801 }
8802 }
8803 filteredInfos.add(new UiccCardInfo(
8804 cardInfo.isEuicc(),
8805 cardInfo.getCardId(),
8806 null,
8807 cardInfo.getPhysicalSlotIndex(),
8808 cardInfo.isRemovable(),
8809 cardInfo.isMultipleEnabledProfilesSupported(),
8810 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008811 }
8812 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008813 } finally {
8814 Binder.restoreCallingIdentity(identity);
8815 }
8816 }
8817
sandeepjsb6c87872021-09-27 15:34:44 +00008818 /**
8819 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8820 * generally private and require carrier privileges to view.
8821 *
8822 * @hide
8823 */
8824 @NonNull
8825 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8826 List<UiccPortInfo> portinfo = new ArrayList<>();
8827 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8828 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8829 }
8830 return new UiccCardInfo(
8831 cardInfo.isEuicc(),
8832 cardInfo.getCardId(),
8833 null,
8834 cardInfo.getPhysicalSlotIndex(),
8835 cardInfo.isRemovable(),
8836 cardInfo.isMultipleEnabledProfilesSupported(),
8837 portinfo
8838 );
8839 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008840
sandeepjsb6c87872021-09-27 15:34:44 +00008841 /**
8842 * @hide
8843 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8844 * These values are generally private and require carrier privileges to view.
8845 */
8846 @NonNull
8847 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8848 return new UiccPortInfo(
8849 UiccPortInfo.ICCID_REDACTED,
8850 portInfo.getPortIndex(),
8851 portInfo.getLogicalSlotIndex(),
8852 portInfo.isActive()
8853 );
8854 }
8855 @Override
8856 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008857 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008858 mApp.getSystemService(AppOpsManager.class)
8859 .checkPackage(Binder.getCallingUid(), callingPackage);
8860
8861 boolean hasReadPermission = false;
8862 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008863
8864 try {
8865 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8866 hasReadPermission = true;
8867 } catch (SecurityException e) {
8868 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8869 // has carrier privileges on an active UICC
8870 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8871 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8872 hasReadPermission = true;
8873 }
8874 }
8875
8876 // checking compatibility, if calling app's target SDK is T and beyond.
8877 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8878 Binder.getCallingUid())) {
8879 isLogicalSlotAccessRestricted = true;
8880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 final long identity = Binder.clearCallingIdentity();
8882 try {
8883 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008884 if (slots == null || slots.length == 0) {
8885 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886 return null;
8887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8889 for (int i = 0; i < slots.length; i++) {
8890 UiccSlot slot = slots[i];
8891 if (slot == null) {
8892 continue;
8893 }
8894
Jordan Liu7be7e652019-05-06 18:55:02 +00008895 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008896 UiccCard card = slot.getUiccCard();
8897 if (card != null) {
8898 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008899 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008900 cardId = slot.getEid();
8901 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008902 // If cardId is null, use iccId of default port as cardId. Check if has
8903 // read permission otherwise set to null.(card is null which means no
8904 // carrier permission)
8905 cardId = hasReadPermission ? slot.getIccId(
8906 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008908 }
8909
Jordan Liu857451f2019-05-09 16:35:35 -07008910 if (cardId != null) {
8911 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8912 // if cardId is an EID, it's all digits so this is fine
8913 cardId = IccUtils.stripTrailingFs(cardId);
8914 }
8915
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008916 int cardState = 0;
8917 switch (slot.getCardState()) {
8918 case CARDSTATE_ABSENT:
8919 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8920 break;
8921 case CARDSTATE_PRESENT:
8922 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8923 break;
8924 case CARDSTATE_ERROR:
8925 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8926 break;
8927 case CARDSTATE_RESTRICTED:
8928 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8929 break;
8930 default:
8931 break;
8932
8933 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008934 List<UiccPortInfo> portInfos = new ArrayList<>();
8935 int[] portIndexes = slot.getPortList();
8936 for (int portIdx : portIndexes) {
8937 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8938 callingPackage, hasReadPermission));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008939 portInfos.add(new UiccPortInfo(iccId, portIdx,
8940 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 slot.isEuicc(),
8944 cardId,
8945 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008946 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008947 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008948 //setting the value after compatibility check
8949 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 }
8951 return infos;
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008954 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008955 }
8956
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008957 /* Returns null if doesn't have read permission or carrier privilege access. */
8958 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8959 boolean hasReadPermission) {
8960 String iccId = slot.getIccId(portIndex);
8961 if (hasReadPermission) { // if has read permission
8962 return iccId;
8963 } else {
8964 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8965 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8966 // if no read permission, checking carrier privilege access
8967 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8968 return iccId;
8969 }
8970 }
8971 }
8972 // No read permission or carrier privilege access.
8973 return UiccPortInfo.ICCID_REDACTED;
8974 }
8975
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008976 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008977 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008978 public boolean switchSlots(int[] physicalSlots) {
8979 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980
8981 final long identity = Binder.clearCallingIdentity();
8982 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008983 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8984 for (int i = 0; i < physicalSlots.length; i++) {
8985 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8986 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8987 physicalSlots[i], i));
8988 }
8989 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008990 } finally {
8991 Binder.restoreCallingIdentity(identity);
8992 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008993 }
Jack Yu4c988042018-02-27 15:30:01 -08008994
8995 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008996 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8997 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8998 enforceModifyPermission();
8999
9000 final long identity = Binder.clearCallingIdentity();
9001 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009002 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009003 } finally {
9004 Binder.restoreCallingIdentity(identity);
9005 }
9006 }
9007
9008 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009009 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009010 final long identity = Binder.clearCallingIdentity();
9011 try {
9012 return UiccController.getInstance().getCardIdForDefaultEuicc();
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
9015 }
9016 }
9017
Pengquan Meng85728fb2018-03-12 16:31:21 -07009018 /**
goneil47ffb6e2018-04-06 15:40:58 -07009019 * A test API to reload the UICC profile.
9020 *
9021 * <p>Requires that the calling app has permission
9022 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9023 * @hide
9024 */
9025 @Override
9026 public void refreshUiccProfile(int subId) {
9027 enforceModifyPermission();
9028
9029 final long identity = Binder.clearCallingIdentity();
9030 try {
9031 Phone phone = getPhone(subId);
9032 if (phone == null) {
9033 return;
9034 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009035 UiccPort uiccPort = phone.getUiccPort();
9036 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009037 return;
9038 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009039 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009040 if (uiccProfile == null) {
9041 return;
9042 }
9043 uiccProfile.refresh();
9044 } finally {
9045 Binder.restoreCallingIdentity(identity);
9046 }
9047 }
9048
9049 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009050 * Returns false if the mobile data is disabled by default, otherwise return true.
9051 */
9052 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009053 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009054 }
9055
9056 /**
9057 * Returns true if the data roaming is enabled by default, i.e the system property
9058 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9059 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9060 */
9061 private boolean getDefaultDataRoamingEnabled(int subId) {
9062 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009063 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009064 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009065 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9066 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9067 return isDataRoamingEnabled;
9068 }
9069
9070 /**
9071 * Returns the default network type for the given {@code subId}, if the default network type is
9072 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9073 */
9074 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009075 List<Integer> list = TelephonyProperties.default_network();
9076 int phoneId = mSubscriptionController.getPhoneId(subId);
9077 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9078 return list.get(phoneId);
9079 }
9080 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009081 }
fionaxua13278b2018-03-21 00:08:13 -07009082
9083 @Override
9084 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009085 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009086 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009087
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
9090 final Phone phone = getPhone(subId);
9091 if (phone == null) {
9092 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9093 return;
9094 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009095 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9096 if (cpt != null) {
9097 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9098 }
9099 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009100 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9101 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009102 if (carrierPrivilegeRules == null) {
9103 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9104 } else {
9105 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009107 } finally {
9108 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009109 }
fionaxua13278b2018-03-21 00:08:13 -07009110 }
9111
9112 @Override
9113 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009114 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009115
9116 final long identity = Binder.clearCallingIdentity();
9117 try {
9118 final Phone phone = getPhone(subId);
9119 if (phone == null) {
9120 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9121 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9122 }
9123 return phone.getCarrierIdListVersion();
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009126 }
fionaxua13278b2018-03-21 00:08:13 -07009127 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009128
9129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009130 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9131 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009133 mApp, subId, callingPackage, callingFeatureId,
9134 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009135 return -1;
9136 }
9137
9138 final long identity = Binder.clearCallingIdentity();
9139 try {
9140 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9141 } finally {
9142 Binder.restoreCallingIdentity(identity);
9143 }
9144 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009145
9146 @Override
9147 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009148 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009149 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009150 mApp, subId, "getCdmaRoamingMode");
9151
9152 final long identity = Binder.clearCallingIdentity();
9153 try {
9154 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9155 } finally {
9156 Binder.restoreCallingIdentity(identity);
9157 }
9158 }
9159
9160 @Override
9161 public boolean setCdmaRoamingMode(int subId, int mode) {
9162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9163 mApp, subId, "setCdmaRoamingMode");
9164
9165 final long identity = Binder.clearCallingIdentity();
9166 try {
9167 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
9170 }
9171 }
9172
9173 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009174 public int getCdmaSubscriptionMode(int subId) {
9175 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009176 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009177 mApp, subId, "getCdmaSubscriptionMode");
9178
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9182 } finally {
9183 Binder.restoreCallingIdentity(identity);
9184 }
9185 }
9186
9187 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009188 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9190 mApp, subId, "setCdmaSubscriptionMode");
9191
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
9194 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009199
sqianc5eccab2018-10-19 18:46:41 -07009200 @Override
sqian8c685422019-02-22 15:55:18 -08009201 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009202 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009204 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9205 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009206 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9207 }
9208 final long identity = Binder.clearCallingIdentity();
9209 try {
sqian854d44b2018-12-12 16:48:18 -08009210 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9211 for (Phone phone: PhoneFactory.getPhones()) {
9212 if (phone.getEmergencyNumberTracker() != null
9213 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9214 emergencyNumberListInternal.put(
9215 phone.getSubId(),
9216 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9217 }
sqian11b7a0e2018-12-05 18:48:28 -08009218 }
sqian854d44b2018-12-12 16:48:18 -08009219 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009220 } finally {
9221 Binder.restoreCallingIdentity(identity);
9222 }
sqianc5eccab2018-10-19 18:46:41 -07009223 }
9224
9225 @Override
sqian8c685422019-02-22 15:55:18 -08009226 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009227 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009228 if (!exactMatch) {
9229 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009230 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009231 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009232 }
9233 final long identity = Binder.clearCallingIdentity();
9234 try {
sqian854d44b2018-12-12 16:48:18 -08009235 for (Phone phone: PhoneFactory.getPhones()) {
9236 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009237 && phone.getEmergencyNumberTracker()
9238 .isEmergencyNumber(number, exactMatch)) {
9239 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009240 }
sqian11b7a0e2018-12-05 18:48:28 -08009241 }
9242 return false;
9243 } finally {
9244 Binder.restoreCallingIdentity(identity);
9245 }
9246 }
9247
sqianf4ca7ed2019-01-15 18:32:07 -08009248 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009249 * Start emergency callback mode for GsmCdmaPhone for testing.
9250 */
9251 @Override
9252 public void startEmergencyCallbackMode() {
9253 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9254 "startEmergencyCallbackMode");
9255 enforceModifyPermission();
9256 final long identity = Binder.clearCallingIdentity();
9257 try {
9258 for (Phone phone : PhoneFactory.getPhones()) {
9259 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9260 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9261 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9262 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9263 gsmCdmaPhone.obtainMessage(
9264 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9265 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9266 }
9267 }
9268 } finally {
9269 Binder.restoreCallingIdentity(identity);
9270 }
9271 }
9272
9273 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009274 * Update emergency number list for test mode.
9275 */
9276 @Override
9277 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9278 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9279 "updateEmergencyNumberListTestMode");
9280
9281 final long identity = Binder.clearCallingIdentity();
9282 try {
9283 for (Phone phone: PhoneFactory.getPhones()) {
9284 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9285 if (tracker != null) {
9286 tracker.executeEmergencyNumberTestModeCommand(action, num);
9287 }
9288 }
9289 } finally {
9290 Binder.restoreCallingIdentity(identity);
9291 }
9292 }
9293
9294 /**
9295 * Get the full emergency number list for test mode.
9296 */
9297 @Override
9298 public List<String> getEmergencyNumberListTestMode() {
9299 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9300 "getEmergencyNumberListTestMode");
9301
9302 final long identity = Binder.clearCallingIdentity();
9303 try {
9304 Set<String> emergencyNumbers = new HashSet<>();
9305 for (Phone phone: PhoneFactory.getPhones()) {
9306 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9307 if (tracker != null) {
9308 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9309 emergencyNumbers.add(num.getNumber());
9310 }
9311 }
9312 }
9313 return new ArrayList<>(emergencyNumbers);
9314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
9317 }
9318
chen xud6b45bd2018-10-30 22:27:10 -07009319 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009320 public int getEmergencyNumberDbVersion(int subId) {
9321 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 final Phone phone = getPhone(subId);
9326 if (phone == null) {
9327 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9328 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9329 }
9330 return phone.getEmergencyNumberDbVersion();
9331 } finally {
9332 Binder.restoreCallingIdentity(identity);
9333 }
9334 }
9335
9336 @Override
9337 public void notifyOtaEmergencyNumberDbInstalled() {
9338 enforceModifyPermission();
9339
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 for (Phone phone: PhoneFactory.getPhones()) {
9343 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9344 if (tracker != null) {
9345 tracker.updateOtaEmergencyNumberDatabase();
9346 }
9347 }
9348 } finally {
9349 Binder.restoreCallingIdentity(identity);
9350 }
9351 }
9352
9353 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009354 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009355 enforceActiveEmergencySessionPermission();
9356
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 for (Phone phone: PhoneFactory.getPhones()) {
9360 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9361 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009362 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9363 }
9364 }
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
9368 }
9369
9370 @Override
9371 public void resetOtaEmergencyNumberDbFilePath() {
9372 enforceActiveEmergencySessionPermission();
9373
9374 final long identity = Binder.clearCallingIdentity();
9375 try {
9376 for (Phone phone: PhoneFactory.getPhones()) {
9377 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9378 if (tracker != null) {
9379 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009380 }
9381 }
9382 } finally {
9383 Binder.restoreCallingIdentity(identity);
9384 }
9385 }
9386
9387 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009388 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9389 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9390 Phone phone = getPhone(subId);
9391 if (phone == null) {
9392 return null;
9393 }
9394 final long identity = Binder.clearCallingIdentity();
9395 try {
9396 UiccProfile profile = UiccController.getInstance()
9397 .getUiccProfileForPhone(phone.getPhoneId());
9398 if (profile != null) {
9399 return profile.getCertsFromCarrierPrivilegeAccessRules();
9400 }
9401 } finally {
9402 Binder.restoreCallingIdentity(identity);
9403 }
9404 return null;
9405 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009406
9407 /**
9408 * Enable or disable a modem stack.
9409 */
9410 @Override
9411 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9412 enforceModifyPermission();
9413
9414 final long identity = Binder.clearCallingIdentity();
9415 try {
9416 Phone phone = PhoneFactory.getPhone(slotIndex);
9417 if (phone == null) {
9418 return false;
9419 } else {
9420 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9421 }
9422 } finally {
9423 Binder.restoreCallingIdentity(identity);
9424 }
9425 }
Michelecea4cf22018-12-21 15:00:11 -08009426
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009427 /**
9428 * Whether a modem stack is enabled or not.
9429 */
9430 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009431 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9432 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009433 Phone phone = PhoneFactory.getPhone(slotIndex);
9434 if (phone == null) return false;
9435
9436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009437 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9438 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009439 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9440 }
9441
9442 final long identity = Binder.clearCallingIdentity();
9443 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009444 try {
9445 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9446 } catch (NoSuchElementException ex) {
9447 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9448 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
9453
Michelecea4cf22018-12-21 15:00:11 -08009454 @Override
Michele0ea7d782019-03-19 14:58:42 -07009455 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009456 enforceModifyPermission();
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009461 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009462 .commit();
9463 } finally {
9464 Binder.restoreCallingIdentity(identity);
9465 }
9466 }
9467
9468 @Override
Michele0ea7d782019-03-19 14:58:42 -07009469 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009470 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009472 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9473 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009474 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009475 }
Michelecea4cf22018-12-21 15:00:11 -08009476
9477 final long identity = Binder.clearCallingIdentity();
9478 try {
Michele0ea7d782019-03-19 14:58:42 -07009479 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009480 } finally {
9481 Binder.restoreCallingIdentity(identity);
9482 }
9483 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009484
Michele0ea7d782019-03-19 14:58:42 -07009485 @TelephonyManager.IsMultiSimSupportedResult
9486 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009487 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9488 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9489 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009490 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9491 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009492 }
9493 // Check if the hardware supports multisim functionality. If usage of multisim is not
9494 // supported by the modem, indicate that it is restricted.
9495 PhoneCapability staticCapability =
9496 mPhoneConfigurationManager.getStaticPhoneCapability();
9497 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009498 loge("isMultiSimSupportedInternal: no static configuration available");
9499 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009500 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009501 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009502 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9503 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009504 }
9505 // Check if support of multiple SIMs is restricted by carrier
9506 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009507 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009508 }
9509
Michele0ea7d782019-03-19 14:58:42 -07009510 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009511 }
9512
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009513 /**
9514 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009515 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9516 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9517 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009518 * @param numOfSims number of active sims we want to switch to
9519 */
9520 @Override
9521 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009522 if (numOfSims == 1) {
9523 enforceModifyPermission();
9524 } else {
9525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9526 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9527 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009528 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009529
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009530 try {
Michele30b57b22019-03-01 12:01:14 -08009531 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009532 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009533 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9534 return;
9535 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009536 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9537 } finally {
9538 Binder.restoreCallingIdentity(identity);
9539 }
9540 }
9541
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009542 @Override
9543 public boolean isApplicationOnUicc(int subId, int appType) {
9544 enforceReadPrivilegedPermission("isApplicationOnUicc");
9545 Phone phone = getPhone(subId);
9546 if (phone == null) {
9547 return false;
9548 }
9549 final long identity = Binder.clearCallingIdentity();
9550 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009551 UiccPort uiccPort = phone.getUiccPort();
9552 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009553 return false;
9554 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009555 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009556 if (uiccProfile == null) {
9557 return false;
9558 }
9559 if (TelephonyManager.APPTYPE_SIM <= appType
9560 && appType <= TelephonyManager.APPTYPE_ISIM) {
9561 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9562 }
9563 return false;
9564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009569 /**
chen xub4baa772019-04-03 10:23:41 -07009570 * Get whether making changes to modem configurations will trigger reboot.
9571 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009572 */
9573 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009574 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9575 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009577 mApp, subId, callingPackage, callingFeatureId,
9578 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009579 return false;
9580 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009581 final long identity = Binder.clearCallingIdentity();
9582 try {
9583 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
9586 }
9587 }
9588
Nathan Harold29f5f052019-02-15 13:41:57 -08009589 private void updateModemStateMetrics() {
9590 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9591 // TODO: check the state for each modem if the api is ready.
9592 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9593 }
9594
Pengquan Meng3889a572019-01-23 11:16:29 -08009595 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009596 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009597 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009598 // Verify that the callingPackage belongs to the calling UID
9599 mApp.getSystemService(AppOpsManager.class)
9600 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009601 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009602 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009603 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009604 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9605 if (slotInfos != null) {
9606 for (int i = 0; i < slotInfos.length; i++) {
9607 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9608 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9609 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9610 portInfo.getLogicalSlotIndex()));
9611 }
9612 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009613 }
9614 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009615 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009616 } finally {
9617 Binder.restoreCallingIdentity(identity);
9618 }
9619 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009620
9621 /**
9622 * Get the IRadio HAL Version
9623 */
9624 @Override
9625 public int getRadioHalVersion() {
9626 Phone phone = getDefaultPhone();
9627 if (phone == null) return -1;
9628 HalVersion hv = phone.getHalVersion();
9629 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9630 return hv.major * 100 + hv.minor;
9631 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009632
9633 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009634 * Get the current calling package name.
9635 * @return the current calling package name
9636 */
9637 @Override
9638 public String getCurrentPackageName() {
9639 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9640 }
9641
9642 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009643 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9644 * corresponding network requests on a subId.
9645 *
9646 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009647 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009648 * 2) APN is un-metered for this subscription, or
9649 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009650 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009651 *
9652 * @return whether data is allowed for a apn type.
9653 *
9654 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009655 */
9656 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009657 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009658 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9659 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009660
9661 // Now that all security checks passes, perform the operation as ourselves.
9662 final long identity = Binder.clearCallingIdentity();
9663 try {
9664 Phone phone = getPhone(subId);
9665 if (phone == null) return false;
9666
Jack Yu41407ee2019-05-13 16:54:09 -07009667 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009668 boolean isDataEnabled;
9669 if (phone.isUsingNewDataStack()) {
9670 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9671 } else {
9672 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9673 }
9674 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
9679
9680 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009681 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009682 enforceReadPrivilegedPermission("isApnMetered");
9683
9684 // Now that all security checks passes, perform the operation as ourselves.
9685 final long identity = Binder.clearCallingIdentity();
9686 try {
9687 Phone phone = getPhone(subId);
9688 if (phone == null) return true; // By default return true.
9689
Jack Yu41407ee2019-05-13 16:54:09 -07009690 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009691 } finally {
9692 Binder.restoreCallingIdentity(identity);
9693 }
9694 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009695
9696 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009697 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9698 int subscriptionId, IBooleanConsumer resultCallback) {
9699 enforceModifyPermission();
9700 long token = Binder.clearCallingIdentity();
9701 try {
9702 Phone phone = getPhone(subscriptionId);
9703 if (phone == null) {
9704 try {
9705 if (resultCallback != null) {
9706 resultCallback.accept(false);
9707 }
9708 } catch (RemoteException e) {
9709 // ignore
9710 }
9711 return;
9712 }
9713 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9714 Pair.create(specifiers, (x) -> {
9715 try {
9716 if (resultCallback != null) {
9717 resultCallback.accept(x);
9718 }
9719 } catch (RemoteException e) {
9720 // ignore
9721 }
9722 });
9723 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9724 } finally {
9725 Binder.restoreCallingIdentity(token);
9726 }
9727 }
9728
9729 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009730 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9731 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009732 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009733 mApp, subId, "getSystemSelectionChannels");
9734 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9735 final long identity = Binder.clearCallingIdentity();
9736 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009737 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9738 if (result instanceof IllegalStateException) {
9739 throw (IllegalStateException) result;
9740 }
9741 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009742 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9743 return specifiers;
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748
9749 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009750 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009751 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009752 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9753 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9754 if (iccRecords == null) {
9755 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9756 return false;
9757 }
9758 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9759 }
9760
9761 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009762 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9763 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009764 if (callingPackage == null) {
9765 callingPackage = getCurrentPackageName();
9766 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009767 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9768 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009769 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9770 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009771 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9772 }
9773 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9774 Intent intent = new Intent();
9775 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9776 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9777 // Bring up choose default SMS subscription dialog right now
9778 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9779 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9780 mApp.startActivity(intent);
9781 }
chen xud5ca2d52019-05-28 15:20:57 -07009782
9783 @Override
9784 public String getMmsUAProfUrl(int subId) {
9785 //TODO investigate if this API should require proper permission check in R b/133791609
9786 final long identity = Binder.clearCallingIdentity();
9787 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009788 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9789 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9790 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9791 return carrierUAProfUrl;
9792 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009793 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9794 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009795 } finally {
9796 Binder.restoreCallingIdentity(identity);
9797 }
9798 }
9799
9800 @Override
9801 public String getMmsUserAgent(int subId) {
9802 //TODO investigate if this API should require proper permission check in R b/133791609
9803 final long identity = Binder.clearCallingIdentity();
9804 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009805 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9806 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9807 if (!TextUtils.isEmpty(carrierUserAgent)) {
9808 return carrierUserAgent;
9809 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009810 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9811 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 }
Jack Yub07d4972019-05-28 16:12:25 -07009816
9817 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009818 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9819 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009820
Jack Yub07d4972019-05-28 16:12:25 -07009821 final long identity = Binder.clearCallingIdentity();
9822 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009823 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009824 if (phone == null) return false;
9825
Hall Liua62f5da2020-09-25 10:42:19 -07009826 switch (policy) {
9827 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009828 if (phone.isUsingNewDataStack()) {
9829 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9830 } else {
9831 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9832 }
Hall Liua62f5da2020-09-25 10:42:19 -07009833 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009834 if (phone.isUsingNewDataStack()) {
9835 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9836 } else {
9837 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9838 }
Hall Liua62f5da2020-09-25 10:42:19 -07009839 default:
9840 throw new IllegalArgumentException(policy + " is not a valid policy");
9841 }
Jack Yub07d4972019-05-28 16:12:25 -07009842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
9846
9847 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009848 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009849 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009850 enforceModifyPermission();
9851
changbettyd5c246e2019-12-24 15:40:37 +08009852 final long identity = Binder.clearCallingIdentity();
9853 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009854 Phone phone = getPhone(subscriptionId);
9855 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009856
Hall Liua62f5da2020-09-25 10:42:19 -07009857 switch (policy) {
9858 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009859 if (phone.isUsingNewDataStack()) {
9860 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9861 } else {
9862 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9863 }
Hall Liua62f5da2020-09-25 10:42:19 -07009864 break;
9865 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009866 if (phone.isUsingNewDataStack()) {
9867 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9868 } else {
9869 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9870 }
Hall Liua62f5da2020-09-25 10:42:19 -07009871 break;
9872 default:
9873 throw new IllegalArgumentException(policy + " is not a valid policy");
9874 }
changbettyd5c246e2019-12-24 15:40:37 +08009875 } finally {
9876 Binder.restoreCallingIdentity(identity);
9877 }
9878 }
9879
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009880 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009881 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009882 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9883 * otherwise.
9884 */
9885 @Override
9886 public void setCepEnabled(boolean isCepEnabled) {
9887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9888
9889 final long identity = Binder.clearCallingIdentity();
9890 try {
9891 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9892 for (Phone phone : PhoneFactory.getPhones()) {
9893 Phone defaultPhone = phone.getImsPhone();
9894 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9895 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9896 ImsPhoneCallTracker imsPhoneCallTracker =
9897 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9898 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9899 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9900 + imsPhone.getMsisdn());
9901 }
9902 }
9903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
allenwtsu46dcc572020-01-08 18:24:03 +08009907
9908 /**
9909 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9910 *
9911 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9912 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9913 * before being read.
9914 */
9915 @Override
9916 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9917 isCompressed) {
9918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9919 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9921 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9922 }
9923 if (!isImsAvailableOnDevice()) {
9924 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9925 "IMS not available on device.");
9926 }
9927
9928 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009929 try {
Hui Wang761a6682020-10-31 05:12:53 +00009930 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9931 } finally {
9932 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009933 }
9934 }
zoey chene02881a2019-12-30 16:11:23 +08009935
9936 @Override
9937 public boolean isIccLockEnabled(int subId) {
9938 enforceReadPrivilegedPermission("isIccLockEnabled");
9939
9940 // Now that all security checks passes, perform the operation as ourselves.
9941 final long identity = Binder.clearCallingIdentity();
9942 try {
9943 Phone phone = getPhone(subId);
9944 if (phone != null && phone.getIccCard() != null) {
9945 return phone.getIccCard().getIccLockEnabled();
9946 } else {
9947 return false;
9948 }
9949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 }
9953
9954 /**
9955 * Set the ICC pin lock enabled or disabled.
9956 *
9957 * @return an integer representing the status of IccLock enabled or disabled in the following
9958 * three cases:
9959 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9960 * successfully.
9961 * - Positive number and zero for remaining password attempts.
9962 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9963 *
9964 */
9965 @Override
9966 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9967 enforceModifyPermission();
9968
9969 Phone phone = getPhone(subId);
9970 if (phone == null) {
9971 return 0;
9972 }
9973 // Now that all security checks passes, perform the operation as ourselves.
9974 final long identity = Binder.clearCallingIdentity();
9975 try {
9976 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9977 new Pair<Boolean, String>(enabled, password), phone, null);
9978 return attemptsRemaining;
9979
9980 } catch (Exception e) {
9981 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9982 } finally {
9983 Binder.restoreCallingIdentity(identity);
9984 }
9985 return 0;
9986 }
9987
9988 /**
9989 * Change the ICC password used in ICC pin lock.
9990 *
9991 * @return an integer representing the status of IccLock changed in the following three cases:
9992 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9993 * - Positive number and zero for remaining password attempts.
9994 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9995 *
9996 */
9997 @Override
9998 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9999 enforceModifyPermission();
10000
10001 Phone phone = getPhone(subId);
10002 if (phone == null) {
10003 return 0;
10004 }
10005 // Now that all security checks passes, perform the operation as ourselves.
10006 final long identity = Binder.clearCallingIdentity();
10007 try {
10008 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10009 new Pair<String, String>(oldPassword, newPassword), phone, null);
10010 return attemptsRemaining;
10011
10012 } catch (Exception e) {
10013 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10014 } finally {
10015 Binder.restoreCallingIdentity(identity);
10016 }
10017 return 0;
10018 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010019
10020 /**
10021 * Request for receiving user activity notification
10022 */
10023 @Override
10024 public void requestUserActivityNotification() {
10025 if (!mNotifyUserActivity.get()
10026 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10027 mNotifyUserActivity.set(true);
10028 }
10029 }
10030
10031 /**
10032 * Called when userActivity is signalled in the power manager.
10033 * This is safe to call from any thread, with any window manager locks held or not.
10034 */
10035 @Override
10036 public void userActivity() {
10037 // ***************************************
10038 // * Inherited from PhoneWindowManager *
10039 // ***************************************
10040 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10041 // WITH ITS LOCKS HELD.
10042 //
10043 // This code must be VERY careful about the locks
10044 // it acquires.
10045 // In fact, the current code acquires way too many,
10046 // and probably has lurking deadlocks.
10047
10048 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10049 throw new SecurityException("Only the OS may call notifyUserActivity()");
10050 }
10051
10052 if (mNotifyUserActivity.getAndSet(false)) {
10053 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10054 USER_ACTIVITY_NOTIFICATION_DELAY);
10055 }
10056 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010057
10058 @Override
10059 public boolean canConnectTo5GInDsdsMode() {
10060 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10061 }
Jack Yud10cdd42020-09-28 20:28:01 -070010062
10063 @Override
10064 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10065 String callingFeatureId) {
10066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10067 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10068 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10069 }
10070
10071 Phone phone = getPhone(subId);
10072 if (phone == null) {
10073 throw new RuntimeException("phone is not available");
10074 }
10075 // Now that all security checks passes, perform the operation as ourselves.
10076 final long identity = Binder.clearCallingIdentity();
10077 try {
10078 return phone.getEquivalentHomePlmns();
10079 } finally {
10080 Binder.restoreCallingIdentity(identity);
10081 }
10082 }
Daniel Bright59e67312020-11-13 11:49:37 -080010083
10084 @Override
10085 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010086 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10087 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010088 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010089 if (radioInterfaceCapabilities == null) {
10090 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010091 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010092 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010093 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010094
Hui Wang641e81c2020-10-12 12:14:23 -070010095 @Override
10096 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10097 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010098 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10099 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10100 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10101 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10102 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010103 if (DBG) {
10104 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10105 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10106 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10107 }
10108
10109 if (!SubscriptionManager.isValidSubscriptionId(subId)
10110 || appType < TelephonyManager.APPTYPE_UNKNOWN
10111 || appType > TelephonyManager.APPTYPE_ISIM
10112 || nafUrl == null || securityProtocol == null || callback == null) {
10113 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10114 if (callback != null) {
10115 try {
10116 callback.onAuthenticationFailure(
10117 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10118 } catch (RemoteException exception) {
10119 log("Fail to notify onAuthenticationFailure due to " + exception);
10120 }
10121 return;
10122 }
10123 }
10124
10125 final long token = Binder.clearCallingIdentity();
10126 try {
10127 getGbaManager(subId).bootstrapAuthenticationRequest(
10128 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10129 forceBootStrapping, callback));
10130 } finally {
10131 Binder.restoreCallingIdentity(token);
10132 }
10133 }
10134
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010135 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010136 * Attempts to set the radio power state for all phones for thermal reason.
10137 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010138 * requested radio power state will actually be set. See {@link
10139 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10140 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010141 * @param enable {@code true} if trying to turn radio on.
10142 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10143 * false}.
10144 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010145 private boolean setRadioPowerForThermal(boolean enable) {
10146 boolean isPhoneAvailable = false;
10147 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10148 Phone phone = PhoneFactory.getPhone(i);
10149 if (phone != null) {
10150 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10151 isPhoneAvailable = true;
10152 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010153 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010154
10155 // return true if successfully informed the phone object about the thermal radio power
10156 // request.
10157 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010158 }
10159
10160 private int handleDataThrottlingRequest(int subId,
10161 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010162 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10163 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10164 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10165 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10166 throw new IllegalArgumentException("modem does not support data throttling");
10167 }
10168
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010169 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10170 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010171 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010172 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10173 }
10174
10175 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10176
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010177 if (isDataThrottlingSupported) {
10178 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010179 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010180 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10181 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10182 } else if (thermalMitigationResult
10183 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010184 log("Modem likely does not support data throttling on secondary carrier. Data " +
10185 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10186 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010187 }
10188 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010189 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010190
10191 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010192 }
10193
Jack Nudelman644b91a2021-03-12 14:09:48 -080010194 private static List<String> getThermalMitigationAllowlist(Context context) {
10195 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10196 for (String pckg : context.getResources()
10197 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10198 sThermalMitigationAllowlistedPackages.add(pckg);
10199 }
10200 }
10201
10202 return sThermalMitigationAllowlistedPackages;
10203 }
10204
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010205 private boolean isAnyPhoneInEmergencyState() {
10206 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10207 if (tm.isInEmergencyCall()) {
10208 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10209 return true;
10210 }
10211 for (Phone phone : PhoneFactory.getPhones()) {
10212 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10213 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10214 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10215 + phone.isInEcm());
10216 return true;
10217 }
10218 }
10219
10220 return false;
10221 }
10222
Jack Nudelman644b91a2021-03-12 14:09:48 -080010223 /**
10224 * Used by shell commands to add an authorized package name for thermal mitigation.
10225 * @param packageName name of package to be allowlisted
10226 * @param context
10227 */
10228 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10229 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10230 sThermalMitigationAllowlistedPackages.add(packageName);
10231 }
10232
10233 /**
10234 * Used by shell commands to remove an authorized package name for thermal mitigation.
10235 * @param packageName name of package to remove from allowlist
10236 * @param context
10237 */
10238 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10239 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10240 sThermalMitigationAllowlistedPackages.remove(packageName);
10241 }
10242
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010243 /**
10244 * Thermal mitigation request to control functionalities at modem.
10245 *
10246 * @param subId the id of the subscription.
10247 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010248 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010249 *
10250 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10251 */
10252 @Override
10253 @ThermalMitigationResult
10254 public int sendThermalMitigationRequest(
10255 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010256 ThermalMitigationRequest thermalMitigationRequest,
10257 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010258 enforceModifyPermission();
10259
Jack Nudelman644b91a2021-03-12 14:09:48 -080010260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10261 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10262 .contains(callingPackage)) {
10263 throw new SecurityException("Calling package must be configured in the device config. "
10264 + "calling package: " + callingPackage);
10265 }
10266
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010267 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10268 final long identity = Binder.clearCallingIdentity();
10269
10270 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10271 try {
10272 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10273 switch (thermalMitigationAction) {
10274 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10275 thermalMitigationResult =
10276 handleDataThrottlingRequest(subId,
10277 thermalMitigationRequest.getDataThrottlingRequest());
10278 break;
10279 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10280 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10281 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10282 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10283 }
10284
10285 // Ensure that radio is on. If not able to power on due to phone being
10286 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010287 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010288 thermalMitigationResult =
10289 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10290 break;
10291 }
10292
10293 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10294 false);
10295 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10296 break;
10297 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10298 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10299 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10300 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10301 }
10302
10303 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10304 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010305 Phone phone = getPhone(subId);
10306 if (phone == null) {
10307 thermalMitigationResult =
10308 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10309 break;
10310 }
10311
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010312 TelephonyConnectionService service =
10313 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010314 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010315 Log.e(LOG_TAG, "An emergency call is pending");
10316 thermalMitigationResult =
10317 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10318 break;
10319 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010320 thermalMitigationResult =
10321 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10322 break;
10323 }
10324 } else {
10325 thermalMitigationResult =
10326 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10327 break;
10328 }
10329
10330 // Turn radio off. If not able to power off due to phone being unavailable,
10331 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010332 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010333 thermalMitigationResult =
10334 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10335 break;
10336 }
10337 thermalMitigationResult =
10338 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10339 break;
10340 default:
10341 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10342 + "not exist. Requested action: " + thermalMitigationAction);
10343 }
10344 } catch (IllegalArgumentException e) {
10345 throw e;
10346 } catch (Exception e) {
10347 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10348 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352
10353 if (DBG) {
10354 log("thermalMitigationRequest returning with thermalMitigationResult: "
10355 + thermalMitigationResult);
10356 }
10357
10358 return thermalMitigationResult;
10359 }
Hui Wang641e81c2020-10-12 12:14:23 -070010360
10361 /**
10362 * Set the GbaService Package Name that Telephony will bind to.
10363 *
10364 * @param subId The sim that the GbaService is associated with.
10365 * @param packageName The name of the package to be replaced with.
10366 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10367 */
10368 @Override
10369 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10370 enforceModifyPermission();
10371
10372 final long identity = Binder.clearCallingIdentity();
10373 try {
10374 return getGbaManager(subId).overrideServicePackage(packageName);
10375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 }
10379
10380 /**
10381 * Return the package name of the currently bound GbaService.
10382 *
10383 * @param subId The sim that the GbaService is associated with.
10384 * @return the package name of the GbaService configuration, null if GBA is not supported.
10385 */
10386 @Override
10387 public String getBoundGbaService(int subId) {
10388 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10389
10390 final long identity = Binder.clearCallingIdentity();
10391 try {
10392 return getGbaManager(subId).getServicePackage();
10393 } finally {
10394 Binder.restoreCallingIdentity(identity);
10395 }
10396 }
10397
10398 /**
10399 * Set the release time for telephony to unbind GbaService.
10400 *
10401 * @param subId The sim that the GbaService is associated with.
10402 * @param interval The release time to unbind GbaService by millisecond.
10403 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10404 */
10405 @Override
10406 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10407 enforceModifyPermission();
10408
10409 final long identity = Binder.clearCallingIdentity();
10410 try {
10411 return getGbaManager(subId).overrideReleaseTime(interval);
10412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
10415 }
10416
10417 /**
10418 * Return the release time for telephony to unbind GbaService.
10419 *
10420 * @param subId The sim that the GbaService is associated with.
10421 * @return The release time to unbind GbaService by millisecond.
10422 */
10423 @Override
10424 public int getGbaReleaseTime(int subId) {
10425 enforceReadPrivilegedPermission("getGbaReleaseTime");
10426
10427 final long identity = Binder.clearCallingIdentity();
10428 try {
10429 return getGbaManager(subId).getReleaseTime();
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
10434
10435 private GbaManager getGbaManager(int subId) {
10436 GbaManager instance = GbaManager.getInstance(subId);
10437 if (instance == null) {
10438 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10439 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10440 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10441 }
10442 return instance;
10443 }
Hui Wang761a6682020-10-31 05:12:53 +000010444
10445 /**
10446 * indicate whether the device and the carrier can support
10447 * RCS VoLTE single registration.
10448 */
10449 @Override
10450 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010451 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10452 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10453 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10454 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010455
10456 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10457 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10458 }
10459
10460 final long identity = Binder.clearCallingIdentity();
10461 try {
10462 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10463 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010464 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10465 if (isCapable != null) {
10466 return isCapable;
10467 }
Hui Wang761a6682020-10-31 05:12:53 +000010468 }
Hui Wang67af90e2021-06-04 16:57:15 -070010469 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10470 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476 /**
10477 * Register RCS provisioning callback.
10478 */
10479 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010480 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010481 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010482 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010483 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010484 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10485 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010486
10487 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10488 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10489 }
10490 if (!isImsAvailableOnDevice()) {
10491 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10492 "IMS not available on device.");
10493 }
10494
10495 final long identity = Binder.clearCallingIdentity();
10496 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010497 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010498 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010499 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10500 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010501 }
Hui Wang761a6682020-10-31 05:12:53 +000010502 } finally {
10503 Binder.restoreCallingIdentity(identity);
10504 }
10505 }
10506
10507 /**
10508 * Unregister RCS provisioning callback.
10509 */
10510 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010511 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010512 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010513 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010514 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010515 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10516 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010517
10518 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10519 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10520 }
10521 if (!isImsAvailableOnDevice()) {
10522 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10523 "IMS not available on device.");
10524 }
10525
10526 final long identity = Binder.clearCallingIdentity();
10527 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010528 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010529 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010530 } finally {
10531 Binder.restoreCallingIdentity(identity);
10532 }
10533 }
10534
10535 /**
10536 * trigger RCS reconfiguration.
10537 */
10538 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010539 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10540 "triggerRcsReconfiguration",
10541 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010542
10543 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10544 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10545 }
10546 if (!isImsAvailableOnDevice()) {
10547 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10548 "IMS not available on device.");
10549 }
10550
10551 final long identity = Binder.clearCallingIdentity();
10552 try {
10553 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
10558
10559 /**
10560 * Provide the client configuration parameters of the RCS application.
10561 */
10562 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010563 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10564 "setRcsClientConfiguration",
10565 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010566
10567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10568 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10569 }
10570 if (!isImsAvailableOnDevice()) {
10571 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10572 "IMS not available on device.");
10573 }
10574
10575 final long identity = Binder.clearCallingIdentity();
10576
10577 try {
10578 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10579 if (configBinder == null) {
10580 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010581 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10582 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010583 } else {
10584 configBinder.setRcsClientConfiguration(rcc);
10585 }
joonhunshin3e154242021-09-17 06:33:39 +000010586
10587 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10588 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010589 } catch (RemoteException e) {
10590 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010591 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10592 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010593 } finally {
10594 Binder.restoreCallingIdentity(identity);
10595 }
10596 }
10597
10598 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010599 * Enables or disables the test mode for RCS VoLTE single registration.
10600 */
10601 @Override
10602 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10603 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10604 "setRcsSingleRegistrationTestModeEnabled");
10605
10606 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10607 }
10608
10609 /**
10610 * Gets the test mode for RCS VoLTE single registration.
10611 */
10612 @Override
10613 public boolean getRcsSingleRegistrationTestModeEnabled() {
10614 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10615 "getRcsSingleRegistrationTestModeEnabled");
10616
10617 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10618 }
10619
10620 /**
Hui Wang761a6682020-10-31 05:12:53 +000010621 * Overrides the config of RCS VoLTE single registration enabled for the device.
10622 */
10623 @Override
10624 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10626 "setDeviceSingleRegistrationEnabledOverride");
10627 enforceModifyPermission();
10628
10629 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10630 : Boolean.parseBoolean(enabledStr);
10631 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010632 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010633 }
10634
10635 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010636 * Sends a device to device communication message. Only usable via shell.
10637 * @param message message to send.
10638 * @param value message value.
10639 */
10640 @Override
10641 public void sendDeviceToDeviceMessage(int message, int value) {
10642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010643 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010644 enforceModifyPermission();
10645
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
10648 TelephonyConnectionService service =
10649 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10650 if (service == null) {
10651 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10652 return;
10653 }
10654 service.sendTestDeviceToDeviceMessage(message, value);
10655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
10659
Tyler Gunnbabbda02021-02-10 11:05:02 -080010660 /**
10661 * Sets the specified device to device transport active.
10662 * @param transport The transport to set active.
10663 */
10664 @Override
10665 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10667 "setActiveDeviceToDeviceTransport");
10668 enforceModifyPermission();
10669
10670 final long identity = Binder.clearCallingIdentity();
10671 try {
10672 TelephonyConnectionService service =
10673 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10674 if (service == null) {
10675 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10676 return;
10677 }
10678 service.setActiveDeviceToDeviceTransport(transport);
10679 } finally {
10680 Binder.restoreCallingIdentity(identity);
10681 }
10682 }
Tyler Gunn92479152021-01-20 16:30:10 -080010683
Tyler Gunnd4339262021-05-03 14:46:49 -070010684 @Override
10685 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10686 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10687 "setDeviceToDeviceForceEnabled");
10688
10689 final long identity = Binder.clearCallingIdentity();
10690 try {
10691 Arrays.stream(PhoneFactory.getPhones()).forEach(
10692 p -> {
10693 Phone thePhone = p.getImsPhone();
10694 if (thePhone != null && thePhone instanceof ImsPhone) {
10695 ImsPhone imsPhone = (ImsPhone) thePhone;
10696 CallTracker tracker = imsPhone.getCallTracker();
10697 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10698 ImsPhoneCallTracker imsPhoneCallTracker =
10699 (ImsPhoneCallTracker) tracker;
10700 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10701 }
10702 }
10703 }
10704 );
10705 } finally {
10706 Binder.restoreCallingIdentity(identity);
10707 }
10708 }
10709
Tyler Gunn92479152021-01-20 16:30:10 -080010710 /**
Hui Wang761a6682020-10-31 05:12:53 +000010711 * Gets the config of RCS VoLTE single registration enabled for the device.
10712 */
10713 @Override
10714 public boolean getDeviceSingleRegistrationEnabled() {
10715 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10716 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10717 }
10718
10719 /**
10720 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10721 */
10722 @Override
10723 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10725 "setCarrierSingleRegistrationEnabledOverride");
10726 enforceModifyPermission();
10727
10728 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10729 : Boolean.parseBoolean(enabledStr);
10730 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10731 subId, enabled);
10732 }
10733
10734 /**
10735 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10736 */
10737 @Override
10738 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10739 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10740 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10741 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010742
10743 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010744 * Overrides the ims feature validation result
10745 */
10746 @Override
10747 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10749 "setImsFeatureValidationOverride");
10750
10751 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10752 : Boolean.parseBoolean(enabledStr);
10753 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10754 subId, enabled);
10755 }
10756
10757 /**
10758 * Gets the ims feature validation override value
10759 */
10760 @Override
10761 public boolean getImsFeatureValidationOverride(int subId) {
10762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10763 "getImsFeatureValidationOverride");
10764 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10765 }
10766
10767 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010768 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10769 * their mobile plan.
10770 */
10771 @Override
10772 public String getMobileProvisioningUrl() {
10773 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10774 final long identity = Binder.clearCallingIdentity();
10775 try {
10776 return getDefaultPhone().getMobileProvisioningUrl();
10777 } finally {
10778 Binder.restoreCallingIdentity(identity);
10779 }
10780 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010781
James.cf Linbcdf8b32021-01-14 16:44:13 +080010782 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010783 * Get the EAB contact from the EAB database.
10784 */
10785 @Override
10786 public String getContactFromEab(String contact) {
10787 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10788 enforceModifyPermission();
10789 final long identity = Binder.clearCallingIdentity();
10790 try {
10791 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10792 } finally {
10793 Binder.restoreCallingIdentity(identity);
10794 }
10795 }
10796
10797 /**
Calvin Pana1434322021-07-01 19:27:01 +080010798 * Get the EAB capability from the EAB database.
10799 */
10800 @Override
10801 public String getCapabilityFromEab(String contact) {
10802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10803 enforceModifyPermission();
10804 final long identity = Binder.clearCallingIdentity();
10805 try {
10806 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10807 } finally {
10808 Binder.restoreCallingIdentity(identity);
10809 }
10810 }
10811
10812 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010813 * Remove the EAB contacts from the EAB database.
10814 */
10815 @Override
10816 public int removeContactFromEab(int subId, String contacts) {
10817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10818 enforceModifyPermission();
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010827 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010828 public boolean getDeviceUceEnabled() {
10829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10830 final long identity = Binder.clearCallingIdentity();
10831 try {
10832 return mApp.getDeviceUceEnabled();
10833 } finally {
10834 Binder.restoreCallingIdentity(identity);
10835 }
10836 }
10837
10838 @Override
10839 public void setDeviceUceEnabled(boolean isEnabled) {
10840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10841 final long identity = Binder.clearCallingIdentity();
10842 try {
10843 mApp.setDeviceUceEnabled(isEnabled);
10844 } finally {
10845 Binder.restoreCallingIdentity(identity);
10846 }
10847 }
10848
Brad Ebinger14d467f2021-02-12 06:18:28 +000010849 /**
10850 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10851 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10852 */
10853 // Used for SHELL command only right now.
10854 @Override
10855 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10856 List<String> featureTags) {
10857 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10858 "addUceRegistrationOverrideShell");
10859 final long identity = Binder.clearCallingIdentity();
10860 try {
10861 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10862 new ArraySet<>(featureTags));
10863 } catch (ImsException e) {
10864 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10865 } finally {
10866 Binder.restoreCallingIdentity(identity);
10867 }
10868 }
10869
10870 /**
10871 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10872 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10873 */
10874 // Used for SHELL command only right now.
10875 @Override
10876 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10877 List<String> featureTags) {
10878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10879 "removeUceRegistrationOverrideShell");
10880 final long identity = Binder.clearCallingIdentity();
10881 try {
10882 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10883 new ArraySet<>(featureTags));
10884 } catch (ImsException e) {
10885 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10886 } finally {
10887 Binder.restoreCallingIdentity(identity);
10888 }
10889 }
10890
10891 /**
10892 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10893 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10894 */
10895 // Used for SHELL command only right now.
10896 @Override
10897 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10899 "clearUceRegistrationOverrideShell");
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
10902 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10903 } catch (ImsException e) {
10904 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10905 } finally {
10906 Binder.restoreCallingIdentity(identity);
10907 }
10908 }
10909
10910 /**
10911 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10912 */
10913 // Used for SHELL command only right now.
10914 @Override
10915 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10917 "getLatestRcsContactUceCapabilityShell");
10918 final long identity = Binder.clearCallingIdentity();
10919 try {
10920 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10921 } catch (ImsException e) {
10922 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
10928 /**
10929 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10930 * device does not have an active PUBLISH.
10931 */
10932 // Used for SHELL command only right now.
10933 @Override
10934 public String getLastUcePidfXmlShell(int subId) {
10935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10936 final long identity = Binder.clearCallingIdentity();
10937 try {
10938 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10939 } catch (ImsException e) {
10940 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10941 } finally {
10942 Binder.restoreCallingIdentity(identity);
10943 }
10944 }
10945
James.cf Line8713a42021-04-29 16:04:26 +080010946 /**
10947 * Remove UCE requests cannot be sent to the network status.
10948 */
10949 // Used for SHELL command only right now.
10950 @Override
10951 public boolean removeUceRequestDisallowedStatus(int subId) {
10952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
10955 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10956 } catch (ImsException e) {
10957 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
James.cf Lin18bb9002021-05-25 01:37:38 +080010963 /**
10964 * Remove UCE requests cannot be sent to the network status.
10965 */
10966 // Used for SHELL command only.
10967 @Override
10968 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
10972 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10973 } catch (ImsException e) {
10974 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10975 } finally {
10976 Binder.restoreCallingIdentity(identity);
10977 }
10978 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010979
James.cf Lin4b784aa2021-01-31 03:25:15 +080010980 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010981 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10982 String callingPackage) {
10983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10984 mApp, subId, "setSignalStrengthUpdateRequest");
10985
10986 final int callingUid = Binder.getCallingUid();
10987 // Verify that tha callingPackage belongs to the calling UID
10988 mApp.getSystemService(AppOpsManager.class)
10989 .checkPackage(callingUid, callingPackage);
10990
Rambo Wang3607f502021-02-01 21:51:40 -080010991 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010992
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
10995 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10996 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10997
10998 if (result instanceof IllegalStateException) {
10999 throw (IllegalStateException) result;
11000 }
11001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
11005
11006 @Override
11007 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11008 String callingPackage) {
11009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11010 mApp, subId, "clearSignalStrengthUpdateRequest");
11011
11012 final int callingUid = Binder.getCallingUid();
11013 // Verify that tha callingPackage belongs to the calling UID
11014 mApp.getSystemService(AppOpsManager.class)
11015 .checkPackage(callingUid, callingPackage);
11016
11017 final long identity = Binder.clearCallingIdentity();
11018 try {
11019 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11020 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11021
11022 if (result instanceof IllegalStateException) {
11023 throw (IllegalStateException) result;
11024 }
11025 } finally {
11026 Binder.restoreCallingIdentity(identity);
11027 }
11028 }
11029
Rambo Wang3607f502021-02-01 21:51:40 -080011030 private static void validateSignalStrengthUpdateRequest(Context context,
11031 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011032 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11033 // phone/system process do not have further restriction on request
11034 return;
11035 }
11036
11037 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011038 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011039 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011040 context.enforceCallingOrSelfPermission(
11041 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11042 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011043 }
11044
11045 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11046 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11047 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11048 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11049 || info.isEnabled()) {
11050 throw new IllegalArgumentException(
11051 "Only system can set hide fields in SignalThresholdInfo");
11052 }
11053
11054 // Thresholds length for each RAN need in range. This has been validated in
11055 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11056 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11057 final int[] thresholds = info.getThresholds();
11058 Objects.requireNonNull(thresholds);
11059 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11060 || thresholds.length
11061 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11062 throw new IllegalArgumentException(
11063 "thresholds length is out of range: " + thresholds.length);
11064 }
11065 }
11066 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011067
11068 /**
11069 * Gets the current phone capability.
11070 *
11071 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11072 * @return the PhoneCapability which describes the data connection capability of modem.
11073 * It's used to evaluate possible phone config change, for example from single
11074 * SIM device to multi-SIM device.
11075 */
11076 @Override
11077 public PhoneCapability getPhoneCapability() {
11078 enforceReadPrivilegedPermission("getPhoneCapability");
11079 final long identity = Binder.clearCallingIdentity();
11080 try {
11081 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11082 } finally {
11083 Binder.restoreCallingIdentity(identity);
11084 }
11085 }
Michele Berionne5e411512020-11-13 02:36:59 +000011086
11087 /**
11088 * Prepare TelephonyManager for an unattended reboot. The reboot is
11089 * required to be done shortly after the API is invoked.
11090 */
11091 @Override
11092 @TelephonyManager.PrepareUnattendedRebootResult
11093 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011094 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011095 enforceRebootPermission();
11096
11097 final long identity = Binder.clearCallingIdentity();
11098 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011099 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011100 } finally {
11101 Binder.restoreCallingIdentity(identity);
11102 }
11103 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011104
11105 /**
11106 * Request to get the current slicing configuration including URSP rules and
11107 * NSSAIs (configured, allowed and rejected).
11108 *
11109 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11110 */
11111 @Override
11112 public void getSlicingConfig(ResultReceiver callback) {
11113 enforceReadPrivilegedPermission("getSlicingConfig");
11114
11115 final long identity = Binder.clearCallingIdentity();
11116 try {
11117 Phone phone = getDefaultPhone();
11118 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11119 } finally {
11120 Binder.restoreCallingIdentity(identity);
11121 }
11122 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011123
11124 /**
11125 * Register an IMS connection state callback
11126 */
11127 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011128 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11129 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011130 if (feature == ImsFeature.FEATURE_MMTEL) {
11131 // ImsMmTelManager
11132 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11133 TelephonyPermissions
11134 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11135 mApp, subId, "registerImsStateCallback");
11136 } else if (feature == ImsFeature.FEATURE_RCS) {
11137 // ImsRcsManager or SipDelegateManager
11138 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11139 Binder.getCallingUid(), "registerImsStateCallback",
11140 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11141 Manifest.permission.READ_PRECISE_PHONE_STATE,
11142 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11143 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11144 }
11145
11146 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11147 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11148 "IMS not available on device.");
11149 }
11150
11151 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11152 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11153 }
11154
11155 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11156 if (controller == null) {
11157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11158 "IMS not available on device.");
11159 }
11160
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011161 if (callingPackage == null) {
11162 callingPackage = getCurrentPackageName();
11163 }
11164
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011165 final long token = Binder.clearCallingIdentity();
11166 try {
11167 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011168 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011169 } catch (ImsException e) {
11170 throw new ServiceSpecificException(e.getCode());
11171 } finally {
11172 Binder.restoreCallingIdentity(token);
11173 }
11174 }
11175
11176 /**
11177 * Unregister an IMS connection state callback
11178 */
11179 @Override
11180 public void unregisterImsStateCallback(IImsStateCallback cb) {
11181 final long token = Binder.clearCallingIdentity();
11182 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11183 if (controller == null) {
11184 return;
11185 }
11186 try {
11187 controller.unregisterImsStateCallback(cb);
11188 } finally {
11189 Binder.restoreCallingIdentity(token);
11190 }
11191 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011192
11193 /**
11194 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11195 *
11196 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11197 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11198 * SecurityException.
11199 * If there is current registered network this value will be same as the registered cell
11200 * identity. If the device goes out of service the previous cell identity is cached and
11201 * will be returned. If the cache age of the Cell identity is more than 24 hours
11202 * it will be cleared and null will be returned.
11203 *
11204 */
11205 @Override
11206 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11207 String callingFeatureId) {
11208 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11209 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11210 LocationAccessPolicy.checkLocationPermission(mApp,
11211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11212 .setCallingPackage(callingPackage)
11213 .setCallingFeatureId(callingFeatureId)
11214 .setCallingPid(Binder.getCallingPid())
11215 .setCallingUid(Binder.getCallingUid())
11216 .setMethod("getLastKnownCellIdentity")
11217 .setLogAsInfo(true)
11218 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11219 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11220 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11221 .build());
11222
11223 boolean hasFinePermission =
11224 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11225 if (!hasFinePermission
11226 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11227 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11228 + "and BIND_CONNECTION_SERVICE permission.");
11229 }
11230
11231 final long identity = Binder.clearCallingIdentity();
11232 try {
11233 Phone phone = getPhone(subId);
11234 if (phone == null) return null;
11235 ServiceStateTracker sst = phone.getServiceStateTracker();
11236 if (sst == null) return null;
11237 return sst.getLastKnownCellIdentity();
11238 } finally {
11239 Binder.restoreCallingIdentity(identity);
11240 }
11241 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011242
11243 @Override
11244 public boolean isUsingNewDataStack() {
11245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11246 return getDefaultPhone().isUsingNewDataStack();
11247 }
jimsun3b9ccac2021-10-26 15:01:23 +080011248
11249 /**
11250 * Sets the modem service class Name that Telephony will bind to.
11251 *
11252 * @param serviceName The class name of the modem service.
11253 * @return true if the operation is succeed, otherwise false.
11254 */
11255 public boolean setModemService(String serviceName) {
11256 Log.d(LOG_TAG, "setModemService - " + serviceName);
11257 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11259 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11260 "setModemService");
11261 return mPhoneConfigurationManager.setModemService(serviceName);
11262 }
11263
11264 /**
11265 * Return the class name of the currently bounded modem service.
11266 *
11267 * @return the class name of the modem service.
11268 */
11269 public String getModemService() {
11270 String result;
11271 Log.d(LOG_TAG, "getModemService");
11272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11273 TelephonyPermissions
11274 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11275 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11276 "getModemService");
11277 result = mPhoneConfigurationManager.getModemService();
11278 Log.d(LOG_TAG, "result = " + result);
11279 return result;
11280 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011281
11282 @Override
11283 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11284 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11285 mApp.enforceCallingOrSelfPermission(
11286 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11287 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11288
11289 final long identity = Binder.clearCallingIdentity();
11290 try {
11291 Phone phone = getPhone(subId);
11292 if (phone == null) return;
11293 phone.setVoiceServiceStateOverride(hasService);
11294 } finally {
11295 Binder.restoreCallingIdentity(identity);
11296 }
11297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011298}