blob: 352e9a2706869c1e0b07fc75a465961e70297044 [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;
joonhunshinfa314642021-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;
sandeepjs0a502c42021-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;
sandeepjs0a502c42021-09-27 15:34:44 +000036import android.compat.annotation.ChangeId;
37import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070038import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070039import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.content.Context;
41import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070043import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080044import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070075import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080076import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080077import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070078import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080079import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070080import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080081import android.telephony.CellIdentityCdma;
82import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070084import android.telephony.CellInfoGsm;
85import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070086import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070088import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070089import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070090import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080091import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070094import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080095import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080096import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800100import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800101import android.telephony.SignalStrengthUpdateRequest;
102import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800103import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800105import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800110import android.telephony.UiccCardInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjs0a502c42021-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;
joonhunshin2c3e4232021-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 Gunnd4575212021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800152import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800155import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700157import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800158import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800159import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800160import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700161import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000162import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800164import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700167import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700168import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700169import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700171import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800172import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700173import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700174import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700175import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700176import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800177import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800178import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700179import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700180import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700181import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800182import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800183import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700185import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700187import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800188import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700189import com.android.internal.telephony.imsphone.ImsPhone;
190import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshinfa314642021-09-17 06:33:39 +0000191import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800192import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700193import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800195import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700198import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000201import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800202import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000203import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800204import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700205import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700206import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800207import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800208import com.android.phone.callcomposer.CallComposerPictureManager;
209import com.android.phone.callcomposer.CallComposerPictureTransfer;
210import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700211import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700212import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800213import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700215import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800216import com.android.services.telephony.TelecomAccountRegistry;
217import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800218import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800219
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700221import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.IOException;
223import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800226import java.util.Arrays;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +0000227import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800228import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800229import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800230import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100231import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700233import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800235import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800237import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800238import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240/**
241 * Implementation of the ITelephony interface.
242 */
Santos Cordon117fee72014-05-16 17:56:12 -0700243public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244 private static final String LOG_TAG = "PhoneInterfaceManager";
245 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
246 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800247 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
249 // Message codes used with mMainThreadHandler
250 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700251 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
252 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700253 private static final int CMD_OPEN_CHANNEL = 9;
254 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
255 private static final int CMD_CLOSE_CHANNEL = 11;
256 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800257 private static final int CMD_NV_READ_ITEM = 13;
258 private static final int EVENT_NV_READ_ITEM_DONE = 14;
259 private static final int CMD_NV_WRITE_ITEM = 15;
260 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
261 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
262 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_RESET_MODEM_CONFIG = 19;
264 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800265 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
266 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800267 private static final int CMD_SEND_ENVELOPE = 25;
268 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000269 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
270 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700271 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
272 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
273 private static final int CMD_EXCHANGE_SIM_IO = 31;
274 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800275 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
276 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700277 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
278 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700279 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
280 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700281 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
282 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
283 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
284 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700285 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
286 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
287 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
288 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700289 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800290 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
291 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000292 private static final int CMD_SWITCH_SLOTS = 50;
293 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700294 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
295 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
296 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
297 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
298 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
299 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
300 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
301 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700302 private static final int CMD_GET_ALL_CELL_INFO = 60;
303 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
304 private static final int CMD_GET_CELL_LOCATION = 62;
305 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700306 private static final int CMD_MODEM_REBOOT = 64;
307 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700308 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
309 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800310 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
311 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700312 private static final int CMD_GET_MODEM_STATUS = 70;
313 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700314 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
315 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700316 private static final int CMD_ERASE_MODEM_CONFIG = 74;
317 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800318 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
319 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
320 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
321 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800322 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
323 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800324 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800325 private static final int CMD_GET_CALL_FORWARDING = 83;
326 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
327 private static final int CMD_SET_CALL_FORWARDING = 85;
328 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
329 private static final int CMD_GET_CALL_WAITING = 87;
330 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
331 private static final int CMD_SET_CALL_WAITING = 89;
332 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700333 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
334 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
335 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
336 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700337 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
338 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800339 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
340 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800341 private static final int CMD_SET_DATA_THROTTLING = 99;
342 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800343 private static final int CMD_SET_SIM_POWER = 101;
344 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800345 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
346 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
347 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
348 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800349 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
350 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000351 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800352 private static final int CMD_GET_SLICING_CONFIG = 110;
353 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800354 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700355 private static final int CMD_ENABLE_VONR = 113;
356 private static final int EVENT_ENABLE_VONR_DONE = 114;
357 private static final int CMD_IS_VONR_ENABLED = 115;
358 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800360 // Parameters of select command.
361 private static final int SELECT_COMMAND = 0xA4;
362 private static final int SELECT_P1 = 0x04;
363 private static final int SELECT_P2 = 0;
364 private static final int SELECT_P3 = 0x10;
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 /** The singleton instance. */
367 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800368 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800372 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700373 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700375 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800377 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700379 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800380 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 /** User Activity */
383 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
385
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700386 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
387
Derek Tan97ebb422014-09-05 16:55:38 -0700388 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
389 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800390 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800391 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700392
Michelecea4cf22018-12-21 15:00:11 -0800393 // String to store multi SIM allowed
394 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
395
Derek Tan740e1672017-06-27 14:56:27 -0700396 // The AID of ISD-R.
397 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
398
yinxub1bed742017-04-17 11:45:04 -0700399 private NetworkScanRequestTracker mNetworkScanRequestTracker;
400
David Kelly5e06a7f2018-03-12 14:10:59 +0000401 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
402 private static final int MANUFACTURER_CODE_LENGTH = 8;
403
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800405 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406
Derek Tan89e89d42014-07-08 17:00:10 -0700407 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700408 * Experiment flag to enable erase modem config on reset network, default value is false
409 */
410 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
411 "reset_network_erase_modem_config_enabled";
412
Rambo Wang0f050d82021-02-12 11:43:36 -0800413 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjs0a502c42021-09-27 15:34:44 +0000414 /**
415 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
416 * one ICCID active at the same time.
417 * Apps should use below API signatures if targeting SDK is T and beyond.
418 *
419 * @hide
420 */
421 @ChangeId
422 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
423 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800424
Naina Nallurid63128d2019-09-17 14:10:30 -0700425 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class IccAPDUArgument {
429 public int channel, cla, command, p1, p2, p3;
430 public String data;
431
432 public IccAPDUArgument(int channel, int cla, int command,
433 int p1, int p2, int p3, String data) {
434 this.channel = channel;
435 this.cla = cla;
436 this.command = command;
437 this.p1 = p1;
438 this.p2 = p2;
439 this.p3 = p3;
440 this.data = data;
441 }
442 }
443
444 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class ManualNetworkSelectionArgument {
448 public OperatorInfo operatorInfo;
449 public boolean persistSelection;
450
451 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
452 this.operatorInfo = operatorInfo;
453 this.persistSelection = persistSelection;
454 }
455 }
456
457 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
459 * request after sending. The main thread will notify the request when it is complete.
460 */
461 private static final class MainThreadRequest {
462 /** The argument to use for the request */
463 public Object argument;
464 /** The result of the request that is run on the main thread */
465 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800466 // The subscriber id that this request applies to. Defaults to
467 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
468 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469
Nathan Harold92bed182018-10-12 18:16:49 -0700470 // In cases where subId is unavailable, the caller needs to specify the phone.
471 public Phone phone;
472
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 public WorkSource workSource;
474
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 public MainThreadRequest(Object argument) {
476 this.argument = argument;
477 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800478
Nathan Harold92bed182018-10-12 18:16:49 -0700479 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
480 this.argument = argument;
481 if (phone != null) {
482 this.phone = phone;
483 }
484 this.workSource = workSource;
485 }
486
vagdeviaf9a5b92018-08-15 16:01:53 -0700487 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800489 if (subId != null) {
490 this.subId = subId;
491 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700492 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 }
495
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800496 private static final class IncomingThirdPartyCallArgs {
497 public final ComponentName component;
498 public final String callId;
499 public final String callerDisplayName;
500
501 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
502 String callerDisplayName) {
503 this.component = component;
504 this.callId = callId;
505 this.callerDisplayName = callerDisplayName;
506 }
507 }
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 /**
510 * A handler that processes messages on the main thread in the phone process. Since many
511 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
512 * inbound binder threads to the main thread in the phone process. The Binder thread
513 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
514 * on, which will be notified when the operation completes and will contain the result of the
515 * request.
516 *
517 * <p>If a MainThreadRequest object is provided in the msg.obj field,
518 * note that request.result must be set to something non-null for the calling thread to
519 * unblock.
520 */
521 private final class MainThreadHandler extends Handler {
522 @Override
523 public void handleMessage(Message msg) {
524 MainThreadRequest request;
525 Message onCompleted;
526 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000527 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800529 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
531 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 case CMD_HANDLE_USSD_REQUEST: {
533 request = (MainThreadRequest) msg.obj;
534 final Phone phone = getPhoneFromRequest(request);
535 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
536 String ussdRequest = ussdObject.first;
537 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700538
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 if (!isUssdApiAllowed(request.subId)) {
540 // Carrier does not support use of this API, return failure.
541 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
542 UssdResponse response = new UssdResponse(ussdRequest, null);
543 Bundle returnData = new Bundle();
544 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
545 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700546
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 request.result = true;
548 notifyRequester(request);
549 return;
550 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700551
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 try {
553 request.result = phone != null
554 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
555 } catch (CallStateException cse) {
556 request.result = false;
557 }
558 // Wake up the requesting thread
559 notifyRequester(request);
560 break;
pkanwar32d516d2016-10-14 19:37:38 -0700561 }
562
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700565 final Phone phone = getPhoneFromRequest(request);
566 request.result = phone != null ?
567 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
568 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000577 uiccPort = getUiccPortFromRequest(request);
578 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 loge("iccTransmitApduLogicalChannel: No UICC");
580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
584 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000585 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument.channel, iccArgument.cla, iccArgument.command,
587 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
597 } else {
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800601 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800603 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
605 loge("iccTransmitApduLogicalChannel: Unknown exception");
606 }
607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
613 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000614 uiccPort = getUiccPortFromRequest(request);
615 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 loge("iccTransmitApduBasicChannel: No UICC");
617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 } else {
620 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
621 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000622 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
624 iccArgument.p3, iccArgument.data, onCompleted);
625 }
626 break;
627
628 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
633 } else {
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
635 if (ar.result == null) {
636 loge("iccTransmitApduBasicChannel: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("iccTransmitApduBasicChannel: CommandException: " +
639 ar.exception);
640 } else {
641 loge("iccTransmitApduBasicChannel: Unknown exception");
642 }
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 break;
646
647 case CMD_EXCHANGE_SIM_IO:
648 request = (MainThreadRequest) msg.obj;
649 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000650 uiccPort = getUiccPortFromRequest(request);
651 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 loge("iccExchangeSimIO: No UICC");
653 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
657 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000658 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
660 iccArgument.data, onCompleted);
661 }
662 break;
663
664 case EVENT_EXCHANGE_SIM_IO_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
667 if (ar.exception == null && ar.result != null) {
668 request.result = ar.result;
669 } else {
670 request.result = new IccIoResult(0x6f, 0, (byte[])null);
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 break;
674
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 case CMD_SEND_ENVELOPE:
676 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000677 uiccPort = getUiccPortFromRequest(request);
678 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 loge("sendEnvelopeWithStatus: No UICC");
680 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000684 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
688 case EVENT_SEND_ENVELOPE_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800693 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700694 request.result = new IccIoResult(0x6F, 0, (byte[])null);
695 if (ar.result == null) {
696 loge("sendEnvelopeWithStatus: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("sendEnvelopeWithStatus: CommandException: " +
699 ar.exception);
700 } else {
701 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
702 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 break;
706
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 case CMD_OPEN_CHANNEL:
708 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000709 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800710 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000711 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700712 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800713 request.result = new IccOpenLogicalChannelResponse(-1,
714 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700716 } else {
717 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000718 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800719 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700720 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 break;
722
723 case EVENT_OPEN_CHANNEL_DONE:
724 ar = (AsyncResult) msg.obj;
725 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 int[] result = (int[]) ar.result;
729 int channelId = result[0];
730 byte[] selectResponse = null;
731 if (result.length > 1) {
732 selectResponse = new byte[result.length - 1];
733 for (int i = 1; i < result.length; ++i) {
734 selectResponse[i - 1] = (byte) result[i];
735 }
736 }
737 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700738 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.result == null) {
741 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700743 if (ar.exception != null) {
744 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
745 }
746
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700747 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700748 if (ar.exception instanceof CommandException) {
749 CommandException.Error error =
750 ((CommandException) (ar.exception)).getCommandError();
751 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700752 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700753 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700754 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700755 }
756 }
757 openChannelResp = new IccOpenLogicalChannelResponse(
758 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700760 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 break;
763
764 case CMD_CLOSE_CHANNEL:
765 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000766 uiccPort = getUiccPortFromRequest(request);
767 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900769 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 } else {
772 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000773 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 break;
776
777 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800778 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
779 break;
780
781 case CMD_NV_READ_ITEM:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
785 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
788 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800791 if (ar.exception == null && ar.result != null) {
792 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800794 request.result = "";
795 if (ar.result == null) {
796 loge("nvReadItem: Empty response");
797 } else if (ar.exception instanceof CommandException) {
798 loge("nvReadItem: CommandException: " +
799 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800801 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 }
803 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 break;
806
Jake Hambye994d462014-02-03 13:10:13 -0800807 case CMD_NV_WRITE_ITEM:
808 request = (MainThreadRequest) msg.obj;
809 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
810 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800811 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700812 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800813 break;
814
815 case EVENT_NV_WRITE_ITEM_DONE:
816 handleNullReturnEvent(msg, "nvWriteItem");
817 break;
818
819 case CMD_NV_WRITE_CDMA_PRL:
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800822 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800823 break;
824
825 case EVENT_NV_WRITE_CDMA_PRL_DONE:
826 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
827 break;
828
chen xu6dac5ab2018-10-26 17:39:23 -0700829 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800830 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700831 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800832 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800833 break;
834
chen xu6dac5ab2018-10-26 17:39:23 -0700835 case EVENT_RESET_MODEM_CONFIG_DONE:
836 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800837 break;
838
Sooraj Sasindran37444802020-08-11 10:40:43 -0700839 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
842 request);
843 Phone phone = getPhoneFromRequest(request);
844 if (phone != null) {
845 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
846 } else {
847 loge("isNRDualConnectivityEnabled: No phone object");
848 request.result = false;
849 notifyRequester(request);
850 }
851 break;
852 }
853
854 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 // request.result must be set to something non-null
861 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700862 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700863 request.result = ar.result;
864 } else {
865 request.result = false;
866 }
867 if (ar.result == null) {
868 loge("isNRDualConnectivityEnabled: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("isNRDualConnectivityEnabled: CommandException: "
871 + ar.exception);
872 } else {
873 loge("isNRDualConnectivityEnabled: Unknown exception");
874 }
875 }
876 notifyRequester(request);
877 break;
878
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700879 case CMD_IS_VONR_ENABLED: {
880 request = (MainThreadRequest) msg.obj;
881 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
882 request);
883 Phone phone = getPhoneFromRequest(request);
884 if (phone != null) {
885 phone.isVoNrEnabled(onCompleted, request.workSource);
886 } else {
887 loge("isVoNrEnabled: No phone object");
888 request.result = false;
889 notifyRequester(request);
890 }
891 break;
892 }
893
894 case EVENT_IS_VONR_ENABLED_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
900 // request.result must be set to something non-null
901 // for the calling thread to unblock
902 if (ar.result != null) {
903 request.result = ar.result;
904 } else {
905 request.result = false;
906 }
907 if (ar.result == null) {
908 loge("isVoNrEnabled: Empty response");
909 } else if (ar.exception instanceof CommandException) {
910 loge("isVoNrEnabled: CommandException: "
911 + ar.exception);
912 } else {
913 loge("isVoNrEnabled: Unknown exception");
914 }
915 }
916 notifyRequester(request);
917 break;
918
Sooraj Sasindran37444802020-08-11 10:40:43 -0700919 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
922 Phone phone = getPhoneFromRequest(request);
923 if (phone != null) {
924 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
925 request.workSource);
926 } else {
927 loge("enableNrDualConnectivity: No phone object");
928 request.result =
929 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
930 notifyRequester(request);
931 }
932 break;
933 }
934
935 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 if (ar.exception == null) {
939 request.result =
940 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
941 } else {
942 request.result =
943 TelephonyManager
944 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
945 if (ar.exception instanceof CommandException) {
946 CommandException.Error error =
947 ((CommandException) (ar.exception)).getCommandError();
948 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
949 request.result =
950 TelephonyManager
951 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000952 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
953 request.result =
954 TelephonyManager
955 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700956 }
957 loge("enableNrDualConnectivity" + ": CommandException: "
958 + ar.exception);
959 } else {
960 loge("enableNrDualConnectivity" + ": Unknown exception");
961 }
962 }
963 notifyRequester(request);
964 break;
965 }
966
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700967 case CMD_ENABLE_VONR: {
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
970 Phone phone = getPhoneFromRequest(request);
971 if (phone != null) {
972 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
973 request.workSource);
974 } else {
975 loge("setVoNrEnabled: No phone object");
976 request.result =
977 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
978 notifyRequester(request);
979 }
980 break;
981 }
982
983 case EVENT_ENABLE_VONR_DONE: {
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception == null) {
987 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
988 } else {
989 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
994 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
995 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
996 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
997 } else {
998 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
999 }
1000 loge("setVoNrEnabled" + ": CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("setVoNrEnabled" + ": Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008 }
1009
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001011 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001012 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1013 request);
1014 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 break;
1016
SongFerngWang3ef3e072020-12-21 16:41:52 +08001017 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception == null && ar.result != null) {
1021 request.result = ar.result; // Integer
1022 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301023 // request.result must be set to something non-null
1024 // for the calling thread to unblock
1025 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001026 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001027 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001028 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 loge("getAllowedNetworkTypesBitmask: CommandException: "
1030 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001032 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001033 }
1034 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001035 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001036 break;
1037
SongFerngWang3ef3e072020-12-21 16:41:52 +08001038 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001039 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001040 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1041 request);
1042 Pair<Integer, Long> reasonWithNetworkTypes =
1043 (Pair<Integer, Long>) request.argument;
1044 getPhoneFromRequest(request).setAllowedNetworkTypes(
1045 reasonWithNetworkTypes.first,
1046 reasonWithNetworkTypes.second,
1047 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001048 break;
1049
SongFerngWang3ef3e072020-12-21 16:41:52 +08001050 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1051 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001052 break;
1053
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001054 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1055 request = (MainThreadRequest)msg.obj;
1056 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001057 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001058 break;
1059
1060 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1061 ar = (AsyncResult)msg.obj;
1062 request = (MainThreadRequest)ar.userObj;
1063 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001064 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001065 break;
1066
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001067 case CMD_SET_VOICEMAIL_NUMBER:
1068 request = (MainThreadRequest) msg.obj;
1069 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1070 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001071 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1072 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001073 break;
1074
1075 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1076 handleNullReturnEvent(msg, "setVoicemailNumber");
1077 break;
1078
Stuart Scott54788802015-03-30 13:18:01 -07001079 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1082 request);
1083 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1084 break;
1085
1086 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1087 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1088 break;
1089
Shishir Agrawal302c8692015-06-19 13:49:39 -07001090 case CMD_PERFORM_NETWORK_SCAN:
1091 request = (MainThreadRequest) msg.obj;
1092 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1093 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1094 break;
1095
Hall Liu27d24262020-09-18 19:04:59 -07001096 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001099 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1100 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1101 request.argument;
1102 int callForwardingReason = args.first;
1103 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001104 break;
Hall Liu27d24262020-09-18 19:04:59 -07001105 }
1106 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001109 TelephonyManager.CallForwardingInfoCallback callback =
1110 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1111 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001112 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001113 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001114 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1115 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1116 // Service Class is a bit mask per 3gpp 27.007. Search for
1117 // any service for voice call.
1118 if ((callForwardInfo.serviceClass
1119 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001120 callForwardingInfo = new CallForwardingInfo(
1121 callForwardInfo.status
1122 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001123 callForwardInfo.reason,
1124 callForwardInfo.number,
1125 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001126 break;
1127 }
1128 }
1129 // Didn't find a call forward info for voice call.
1130 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001131 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1132 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 } else {
1136 if (ar.result == null) {
1137 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1138 }
1139 if (ar.exception != null) {
1140 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1141 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001142 int errorCode = TelephonyManager
1143 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001144 if (ar.exception instanceof CommandException) {
1145 CommandException.Error error =
1146 ((CommandException) (ar.exception)).getCommandError();
1147 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001148 errorCode = TelephonyManager
1149 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001150 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001151 errorCode = TelephonyManager
1152 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001153 }
1154 }
Hall Liu27d24262020-09-18 19:04:59 -07001155 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157 break;
Hall Liu27d24262020-09-18 19:04:59 -07001158 }
Shuo Qian4a594052020-01-23 11:59:30 -08001159
Hall Liu27d24262020-09-18 19:04:59 -07001160 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 request = (MainThreadRequest) msg.obj;
1162 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001163 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001164 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001165 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1166 request.argument).first;
1167 request.phone.setCallForwardingOption(
1168 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001169 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001170 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001171 callForwardingInfoToSet.getReason(),
1172 callForwardingInfoToSet.getNumber(),
1173 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1174 break;
Hall Liu27d24262020-09-18 19:04:59 -07001175 }
Shuo Qian4a594052020-01-23 11:59:30 -08001176
Hall Liu27d24262020-09-18 19:04:59 -07001177 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001178 ar = (AsyncResult) msg.obj;
1179 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001180 Consumer<Integer> callback =
1181 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1182 request.argument).second;
1183 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001184 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001185 int errorCode = TelephonyManager.CallForwardingInfoCallback
1186 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001187 if (ar.exception instanceof CommandException) {
1188 CommandException.Error error =
1189 ((CommandException) (ar.exception)).getCommandError();
1190 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001191 errorCode = TelephonyManager.CallForwardingInfoCallback
1192 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001193 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager.CallForwardingInfoCallback
1195 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001196 }
1197 }
1198 callback.accept(errorCode);
1199 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001200 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001201 }
Shuo Qian4a594052020-01-23 11:59:30 -08001202 break;
Hall Liu27d24262020-09-18 19:04:59 -07001203 }
Shuo Qian4a594052020-01-23 11:59:30 -08001204
Hall Liu27d24262020-09-18 19:04:59 -07001205 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1208 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1209 break;
Hall Liu27d24262020-09-18 19:04:59 -07001210 }
Shuo Qian4a594052020-01-23 11:59:30 -08001211
Hall Liu27d24262020-09-18 19:04:59 -07001212 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001215 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001216 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1217 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001218 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 // Service Class is a bit mask per 3gpp 27.007.
1220 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001221 if (callForwardResults.length > 1
1222 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001223 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001224 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001225 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1226 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001228 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 }
1230 } else {
1231 if (ar.result == null) {
1232 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1233 }
1234 if (ar.exception != null) {
1235 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1236 }
1237 if (ar.exception instanceof CommandException) {
1238 CommandException.Error error =
1239 ((CommandException) (ar.exception)).getCommandError();
1240 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1241 callForwardingStatus =
1242 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1243 }
1244 }
1245 }
Hall Liu27d24262020-09-18 19:04:59 -07001246 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 break;
Hall Liu27d24262020-09-18 19:04:59 -07001248 }
Shuo Qian4a594052020-01-23 11:59:30 -08001249
Hall Liu27d24262020-09-18 19:04:59 -07001250 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001251 request = (MainThreadRequest) msg.obj;
1252 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001253 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1254 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001261 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1262 Consumer<Integer> callback =
1263 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1264 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001266 if (ar.exception instanceof CommandException) {
1267 CommandException.Error error =
1268 ((CommandException) (ar.exception)).getCommandError();
1269 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1270 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1271 } else {
1272 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1273 }
1274 } else {
1275 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1276 }
1277 } else {
1278 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1279 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281 break;
Hall Liu27d24262020-09-18 19:04:59 -07001282 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001283 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
1286 CellNetworkScanResult cellScanResult;
1287 if (ar.exception == null && ar.result != null) {
1288 cellScanResult = new CellNetworkScanResult(
1289 CellNetworkScanResult.STATUS_SUCCESS,
1290 (List<OperatorInfo>) ar.result);
1291 } else {
1292 if (ar.result == null) {
1293 loge("getCellNetworkScanResults: Empty response");
1294 }
1295 if (ar.exception != null) {
1296 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1297 }
1298 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1299 if (ar.exception instanceof CommandException) {
1300 CommandException.Error error =
1301 ((CommandException) (ar.exception)).getCommandError();
1302 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1303 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1304 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1305 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1306 }
1307 }
1308 cellScanResult = new CellNetworkScanResult(errorCode, null);
1309 }
1310 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001311 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001312 break;
1313
1314 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1315 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001316 ManualNetworkSelectionArgument selArg =
1317 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001318 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1319 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001320 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1321 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001322 break;
1323
1324 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001325 ar = (AsyncResult) msg.obj;
1326 request = (MainThreadRequest) ar.userObj;
1327 if (ar.exception == null) {
1328 request.result = true;
1329 } else {
1330 request.result = false;
1331 loge("setNetworkSelectionModeManual " + ar.exception);
1332 }
1333 notifyRequester(request);
1334 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001335 break;
1336
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001337 case CMD_GET_MODEM_ACTIVITY_INFO:
1338 request = (MainThreadRequest) msg.obj;
1339 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001340 if (defaultPhone != null) {
1341 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001342 } else {
1343 ResultReceiver result = (ResultReceiver) request.argument;
1344 Bundle bundle = new Bundle();
1345 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001346 new ModemActivityInfo(0, 0, 0,
1347 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001348 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001349 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001350 break;
1351
Hall Liud0f208c2020-10-14 16:54:44 -07001352 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001353 ar = (AsyncResult) msg.obj;
1354 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001355 ResultReceiver result = (ResultReceiver) request.argument;
1356
Hall Liud0f208c2020-10-14 16:54:44 -07001357 ModemActivityInfo ret = null;
1358 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001359 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001360 // Update the last modem activity info and the result of the request.
1361 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1362 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001363 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001364 int[] txTimeMs = info.getTransmitTimeMillis();
1365 int[] lastModemTxTimeMs = mLastModemActivityInfo
1366 .getTransmitTimeMillis();
1367 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1368 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1369 }
Hall Liu49656c02020-10-09 19:00:11 -07001370 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001371 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1372 + mLastModemActivityInfo.getSleepTimeMillis());
1373 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1374 + mLastModemActivityInfo.getIdleTimeMillis());
1375 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1376 mLastModemActivityInfo.setReceiveTimeMillis(
1377 info.getReceiveTimeMillis()
1378 + mLastModemActivityInfo.getReceiveTimeMillis());
1379 }
Hall Liu49656c02020-10-09 19:00:11 -07001380 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001381 mLastModemActivityInfo.getSleepTimeMillis(),
1382 mLastModemActivityInfo.getIdleTimeMillis(),
1383 mLastModemActivityInfo.getTransmitTimeMillis(),
1384 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001385 } else {
1386 if (ar.result == null) {
1387 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001388 error = TelephonyManager.ModemActivityInfoException
1389 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390 } else if (ar.exception instanceof CommandException) {
1391 loge("queryModemActivityInfo: CommandException: " +
1392 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001393 error = TelephonyManager.ModemActivityInfoException
1394 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001395 } else {
1396 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001397 error = TelephonyManager.ModemActivityInfoException
1398 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001399 }
1400 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001401 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001402 if (ret != null) {
1403 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1404 } else {
1405 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1406 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001408 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001409 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001410 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001411
Meng Wang1a7c35a2016-05-05 20:56:15 -07001412 case CMD_SET_ALLOWED_CARRIERS:
1413 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001414 CarrierRestrictionRules argument =
1415 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001417 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001418 break;
1419
1420 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception == null && ar.result != null) {
1424 request.result = ar.result;
1425 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001426 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1427 if (ar.exception instanceof CommandException) {
1428 loge("setAllowedCarriers: CommandException: " + ar.exception);
1429 CommandException.Error error =
1430 ((CommandException) (ar.exception)).getCommandError();
1431 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1432 request.result =
1433 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1434 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001435 } else {
1436 loge("setAllowedCarriers: Unknown exception");
1437 }
1438 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001440 break;
1441
1442 case CMD_GET_ALLOWED_CARRIERS:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001445 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001446 break;
1447
1448 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 if (ar.exception == null && ar.result != null) {
1452 request.result = ar.result;
1453 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001454 request.result = new IllegalStateException(
1455 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001456 if (ar.result == null) {
1457 loge("getAllowedCarriers: Empty response");
1458 } else if (ar.exception instanceof CommandException) {
1459 loge("getAllowedCarriers: CommandException: " +
1460 ar.exception);
1461 } else {
1462 loge("getAllowedCarriers: Unknown exception");
1463 }
1464 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001466 break;
1467
Nathan Haroldb3014052017-01-25 15:57:32 -08001468 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 if (ar.exception == null && ar.result != null) {
1472 request.result = ar.result;
1473 } else {
1474 request.result = new IllegalArgumentException(
1475 "Failed to retrieve Forbidden Plmns");
1476 if (ar.result == null) {
1477 loge("getForbiddenPlmns: Empty response");
1478 } else {
1479 loge("getForbiddenPlmns: Unknown exception");
1480 }
1481 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001482 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001483 break;
1484
1485 case CMD_GET_FORBIDDEN_PLMNS:
1486 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001487 uiccPort = getUiccPortFromRequest(request);
1488 if (uiccPort == null) {
1489 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001490 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001491 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001492 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001493 break;
1494 }
1495 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001496 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001497 if (uiccApp == null) {
1498 loge("getForbiddenPlmns() no app with specified type -- "
1499 + appType);
1500 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001502 break;
1503 } else {
1504 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1505 + " specified type -- " + appType);
1506 }
1507 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1508 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1509 onCompleted);
1510 break;
1511
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001512 case CMD_SWITCH_SLOTS:
1513 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001514 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001515 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001516 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001517 break;
1518
1519 case EVENT_SWITCH_SLOTS_DONE:
1520 ar = (AsyncResult) msg.obj;
1521 request = (MainThreadRequest) ar.userObj;
1522 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
1524 break;
1525 case CMD_GET_NETWORK_SELECTION_MODE:
1526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1528 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1529 break;
1530
1531 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception != null) {
1535 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1536 } else {
1537 int mode = ((int[]) ar.result)[0];
1538 if (mode == 0) {
1539 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1540 } else {
1541 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1542 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
1545 break;
1546 case CMD_GET_CDMA_ROAMING_MODE:
1547 request = (MainThreadRequest) msg.obj;
1548 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1549 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1550 break;
1551 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1552 ar = (AsyncResult) msg.obj;
1553 request = (MainThreadRequest) ar.userObj;
1554 if (ar.exception != null) {
1555 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1556 } else {
1557 request.result = ((int[]) ar.result)[0];
1558 }
1559 notifyRequester(request);
1560 break;
1561 case CMD_SET_CDMA_ROAMING_MODE:
1562 request = (MainThreadRequest) msg.obj;
1563 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1564 int mode = (int) request.argument;
1565 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1566 break;
1567 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
1570 request.result = ar.exception == null;
1571 notifyRequester(request);
1572 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001573 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1574 request = (MainThreadRequest) msg.obj;
1575 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1576 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1577 break;
1578 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 if (ar.exception != null) {
1582 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1583 } else {
1584 request.result = ((int[]) ar.result)[0];
1585 }
1586 notifyRequester(request);
1587 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001588 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1591 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001592 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1593 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001594 break;
1595 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1596 ar = (AsyncResult) msg.obj;
1597 request = (MainThreadRequest) ar.userObj;
1598 request.result = ar.exception == null;
1599 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001600 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001601 case CMD_GET_ALL_CELL_INFO:
1602 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001603 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001604 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001605 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001606 case EVENT_GET_ALL_CELL_INFO_DONE:
1607 ar = (AsyncResult) msg.obj;
1608 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001609 // If a timeout occurs, the response will be null
1610 request.result = (ar.exception == null && ar.result != null)
1611 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001612 synchronized (request) {
1613 request.notifyAll();
1614 }
1615 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001616 case CMD_REQUEST_CELL_INFO_UPDATE:
1617 request = (MainThreadRequest) msg.obj;
1618 request.phone.requestCellInfoUpdate(request.workSource,
1619 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1620 break;
1621 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1625 try {
1626 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001627 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001628 cb.onError(
1629 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1630 ar.exception.getClass().getName(),
1631 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001632 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001634 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001635 } else {
1636 // use the result as returned
1637 cb.onCellInfo((List<CellInfo>) ar.result);
1638 }
1639 } catch (RemoteException re) {
1640 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1641 }
1642 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001643 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001644 request = (MainThreadRequest) msg.obj;
1645 WorkSource ws = (WorkSource) request.argument;
1646 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001647 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001648 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001649 }
1650 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 ar = (AsyncResult) msg.obj;
1652 request = (MainThreadRequest) ar.userObj;
1653 if (ar.exception == null) {
1654 request.result = ar.result;
1655 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001656 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001658 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 }
1660
1661 synchronized (request) {
1662 request.notifyAll();
1663 }
1664 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001665 }
chen xu6dac5ab2018-10-26 17:39:23 -07001666 case CMD_MODEM_REBOOT:
1667 request = (MainThreadRequest) msg.obj;
1668 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001669 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001670 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001671 case EVENT_CMD_MODEM_REBOOT_DONE:
1672 handleNullReturnEvent(msg, "rebootModem");
1673 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001674 case CMD_REQUEST_ENABLE_MODEM:
1675 request = (MainThreadRequest) msg.obj;
1676 boolean enable = (boolean) request.argument;
1677 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001678 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001679 PhoneConfigurationManager.getInstance()
1680 .enablePhone(request.phone, enable, onCompleted);
1681 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001682 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001686 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001687 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001688 if ((boolean) request.result) {
1689 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1690 updateModemStateMetrics();
1691 } else {
1692 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1693 + ar.exception);
1694 }
1695 notifyRequester(request);
1696 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001697 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001698 case CMD_GET_MODEM_STATUS:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1701 PhoneConfigurationManager.getInstance()
1702 .getPhoneStatusFromModem(request.phone, onCompleted);
1703 break;
1704 case EVENT_GET_MODEM_STATUS_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 int id = request.phone.getPhoneId();
1708 if (ar.exception == null && ar.result != null) {
1709 request.result = ar.result;
1710 //update the cache as modem status has changed
1711 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1712 (boolean) request.result);
1713 } else {
1714 // Return true if modem status cannot be retrieved. For most cases,
1715 // modem status is on. And for older version modems, GET_MODEM_STATUS
1716 // and disable modem are not supported. Modem is always on.
1717 // TODO: this should be fixed in R to support a third
1718 // status UNKNOWN b/131631629
1719 request.result = true;
1720 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1721 + ar.exception);
1722 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001723 notifyRequester(request);
1724 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001725 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1726 request = (MainThreadRequest) msg.obj;
1727 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1728 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1729 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1730 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1731 break;
1732 }
1733 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1737 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1738 args.second.accept(ar.exception == null);
1739 notifyRequester(request);
1740 break;
1741 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001742 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1745 Phone phone = getPhoneFromRequest(request);
1746 if (phone != null) {
1747 phone.getSystemSelectionChannels(onCompleted);
1748 } else {
1749 loge("getSystemSelectionChannels: No phone object");
1750 request.result = new ArrayList<RadioAccessSpecifier>();
1751 notifyRequester(request);
1752 }
1753 break;
1754 }
1755 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1756 ar = (AsyncResult) msg.obj;
1757 request = (MainThreadRequest) ar.userObj;
1758 if (ar.exception == null && ar.result != null) {
1759 request.result = ar.result;
1760 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001761 request.result = new IllegalStateException(
1762 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001763 if (ar.result == null) {
1764 loge("getSystemSelectionChannels: Empty response");
1765 } else {
1766 loge("getSystemSelectionChannels: Unknown exception");
1767 }
1768 }
1769 notifyRequester(request);
1770 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001771 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1772 ar = (AsyncResult) msg.obj;
1773 request = (MainThreadRequest) ar.userObj;
1774 if (ar.exception == null && ar.result != null) {
1775 request.result = ar.result;
1776 } else {
1777 request.result = -1;
1778 loge("Failed to set Forbidden Plmns");
1779 if (ar.result == null) {
1780 loge("setForbidenPlmns: Empty response");
1781 } else if (ar.exception != null) {
1782 loge("setForbiddenPlmns: Exception: " + ar.exception);
1783 request.result = -1;
1784 } else {
1785 loge("setForbiddenPlmns: Unknown exception");
1786 }
1787 }
1788 notifyRequester(request);
1789 break;
1790 case CMD_SET_FORBIDDEN_PLMNS:
1791 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001792 uiccPort = getUiccPortFromRequest(request);
1793 if (uiccPort == null) {
1794 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001795 request.result = -1;
1796 notifyRequester(request);
1797 break;
1798 }
1799 Pair<Integer, List<String>> setFplmnsArgs =
1800 (Pair<Integer, List<String>>) request.argument;
1801 appType = setFplmnsArgs.first;
1802 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001803 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001804 if (uiccApp == null) {
1805 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1806 request.result = -1;
1807 loge("Failed to get UICC App");
1808 notifyRequester(request);
1809 } else {
1810 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1811 ((SIMRecords) uiccApp.getIccRecords())
1812 .setForbiddenPlmns(onCompleted, fplmns);
1813 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001814 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001815 case CMD_ERASE_MODEM_CONFIG:
1816 request = (MainThreadRequest) msg.obj;
1817 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1818 defaultPhone.eraseModemConfig(onCompleted);
1819 break;
1820 case EVENT_ERASE_MODEM_CONFIG_DONE:
1821 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001822 break;
zoey chene02881a2019-12-30 16:11:23 +08001823
Kai Shif70f46f2021-03-03 13:59:46 -08001824 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1825 request = (MainThreadRequest) msg.obj;
1826 request.result = defaultPhone.eraseDataInSharedPreferences();
1827 notifyRequester(request);
1828 break;
1829
zoey chene02881a2019-12-30 16:11:23 +08001830 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1833 Pair<String, String> changed = (Pair<String, String>) request.argument;
1834 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1835 changed.first, changed.second, onCompleted);
1836 break;
1837 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 if (ar.exception == null) {
1841 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001842 // If the operation is successful, update the PIN storage
1843 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1844 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001845 UiccController.getInstance().getPinStorage()
1846 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001847 } else {
1848 request.result = msg.arg1;
1849 }
1850 notifyRequester(request);
1851 break;
1852
Michele Berionne5e411512020-11-13 02:36:59 +00001853 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001854 request = (MainThreadRequest) msg.obj;
1855 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1856 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1857 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1858 enabled.first, enabled.second, onCompleted);
1859 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001860 }
zoey chene02881a2019-12-30 16:11:23 +08001861 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1862 ar = (AsyncResult) msg.obj;
1863 request = (MainThreadRequest) ar.userObj;
1864 if (ar.exception == null) {
1865 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001866 // If the operation is successful, update the PIN storage
1867 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1868 int phoneId = getPhoneFromRequest(request).getPhoneId();
1869 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001870 UiccController.getInstance().getPinStorage()
1871 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001872 } else {
1873 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1874 }
zoey chene02881a2019-12-30 16:11:23 +08001875 } else {
1876 request.result = msg.arg1;
1877 }
Michele Berionne5e411512020-11-13 02:36:59 +00001878
1879
zoey chene02881a2019-12-30 16:11:23 +08001880 notifyRequester(request);
1881 break;
1882
Peter Wangdafb9ac2020-01-15 14:13:38 -08001883 case MSG_NOTIFY_USER_ACTIVITY:
1884 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001885 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001886 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1887 getDefaultPhone().getContext().sendBroadcastAsUser(
1888 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1889 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001890
1891 case CMD_SET_DATA_THROTTLING: {
1892 request = (MainThreadRequest) msg.obj;
1893 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1894 DataThrottlingRequest dataThrottlingRequest =
1895 (DataThrottlingRequest) request.argument;
1896 Phone phone = getPhoneFromRequest(request);
1897 if (phone != null) {
1898 phone.setDataThrottling(onCompleted,
1899 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1900 dataThrottlingRequest.getCompletionDurationMillis());
1901 } else {
1902 loge("setDataThrottling: No phone object");
1903 request.result =
1904 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1905 notifyRequester(request);
1906 }
1907
1908 break;
1909 }
1910 case EVENT_SET_DATA_THROTTLING_DONE:
1911 ar = (AsyncResult) msg.obj;
1912 request = (MainThreadRequest) ar.userObj;
1913
1914 if (ar.exception == null) {
1915 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1916 } else if (ar.exception instanceof CommandException) {
1917 loge("setDataThrottling: CommandException: " + ar.exception);
1918 CommandException.Error error =
1919 ((CommandException) (ar.exception)).getCommandError();
1920
1921 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1922 request.result = TelephonyManager
1923 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1924 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1925 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001926 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1927 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001928 } else {
1929 request.result =
1930 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1931 }
1932 } else {
1933 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1934 }
1935 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1936 notifyRequester(request);
1937 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001938
1939 case CMD_SET_SIM_POWER: {
1940 request = (MainThreadRequest) msg.obj;
1941 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1942 request = (MainThreadRequest) msg.obj;
1943 int stateToSet =
1944 ((Pair<Integer, IIntegerConsumer>)
1945 request.argument).first;
1946 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1947 break;
1948 }
1949 case EVENT_SET_SIM_POWER_DONE: {
1950 ar = (AsyncResult) msg.obj;
1951 request = (MainThreadRequest) ar.userObj;
1952 IIntegerConsumer callback =
1953 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1954 if (ar.exception != null) {
1955 loge("setSimPower exception: " + ar.exception);
1956 int errorCode = TelephonyManager.CallForwardingInfoCallback
1957 .RESULT_ERROR_UNKNOWN;
1958 if (ar.exception instanceof CommandException) {
1959 CommandException.Error error =
1960 ((CommandException) (ar.exception)).getCommandError();
1961 if (error == CommandException.Error.SIM_ERR) {
1962 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1963 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1964 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1965 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1966 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1967 } else {
1968 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1969 }
1970 }
1971 try {
1972 callback.accept(errorCode);
1973 } catch (RemoteException e) {
1974 // Ignore if the remote process is no longer available to call back.
1975 Log.w(LOG_TAG, "setSimPower: callback not available.");
1976 }
1977 } else {
1978 try {
1979 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1980 } catch (RemoteException e) {
1981 // Ignore if the remote process is no longer available to call back.
1982 Log.w(LOG_TAG, "setSimPower: callback not available.");
1983 }
1984 }
1985 break;
1986 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001987 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1988 request = (MainThreadRequest) msg.obj;
1989
1990 final Phone phone = getPhoneFromRequest(request);
1991 if (phone == null || phone.getServiceStateTracker() == null) {
1992 request.result = new IllegalStateException("Phone or SST is null");
1993 notifyRequester(request);
1994 break;
1995 }
1996
1997 Pair<Integer, SignalStrengthUpdateRequest> pair =
1998 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1999 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2000 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002001 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002002 request.subId, pair.first /*callingUid*/,
2003 pair.second /*request*/, onCompleted);
2004 break;
2005 }
2006 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2007 ar = (AsyncResult) msg.obj;
2008 request = (MainThreadRequest) ar.userObj;
2009 // request.result will be the exception of ar if present, true otherwise.
2010 // Be cautious not to leave result null which will wait() forever
2011 request.result = ar.exception != null ? ar.exception : true;
2012 notifyRequester(request);
2013 break;
2014 }
2015 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2016 request = (MainThreadRequest) msg.obj;
2017
2018 Phone phone = getPhoneFromRequest(request);
2019 if (phone == null || phone.getServiceStateTracker() == null) {
2020 request.result = new IllegalStateException("Phone or SST is null");
2021 notifyRequester(request);
2022 break;
2023 }
2024
2025 Pair<Integer, SignalStrengthUpdateRequest> pair =
2026 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2027 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2028 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002029 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002030 request.subId, pair.first /*callingUid*/,
2031 pair.second /*request*/, onCompleted);
2032 break;
2033 }
2034 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2035 ar = (AsyncResult) msg.obj;
2036 request = (MainThreadRequest) ar.userObj;
2037 request.result = ar.exception != null ? ar.exception : true;
2038 notifyRequester(request);
2039 break;
2040 }
Jordan Liu109698e2020-11-24 14:50:34 -08002041
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002042 case CMD_GET_SLICING_CONFIG: {
2043 request = (MainThreadRequest) msg.obj;
2044 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2045 request.phone.getSlicingConfig(onCompleted);
2046 break;
2047 }
2048 case EVENT_GET_SLICING_CONFIG_DONE: {
2049 ar = (AsyncResult) msg.obj;
2050 request = (MainThreadRequest) ar.userObj;
2051 ResultReceiver result = (ResultReceiver) request.argument;
2052
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002053 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002054 Bundle bundle = new Bundle();
2055 int resultCode = 0;
2056 if (ar.exception != null) {
2057 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2058 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002059 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002060 } else if (ar.result == null) {
2061 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002062 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002063 } else {
2064 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002065 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2066 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002067 }
2068
2069 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002070 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002071 }
2072 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2073 result.send(resultCode, bundle);
2074 notifyRequester(request);
2075 break;
2076 }
2077
Michele Berionne5e411512020-11-13 02:36:59 +00002078 case CMD_PREPARE_UNATTENDED_REBOOT:
2079 request = (MainThreadRequest) msg.obj;
2080 request.result =
2081 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2082 notifyRequester(request);
2083 break;
2084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 default:
2086 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2087 break;
2088 }
2089 }
Jake Hambye994d462014-02-03 13:10:13 -08002090
Pengquan Menga1bb6272018-09-06 09:59:22 -07002091 private void notifyRequester(MainThreadRequest request) {
2092 synchronized (request) {
2093 request.notifyAll();
2094 }
2095 }
2096
Jake Hambye994d462014-02-03 13:10:13 -08002097 private void handleNullReturnEvent(Message msg, String command) {
2098 AsyncResult ar = (AsyncResult) msg.obj;
2099 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2100 if (ar.exception == null) {
2101 request.result = true;
2102 } else {
2103 request.result = false;
2104 if (ar.exception instanceof CommandException) {
2105 loge(command + ": CommandException: " + ar.exception);
2106 } else {
2107 loge(command + ": Unknown exception");
2108 }
2109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002110 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
2114 /**
2115 * Posts the specified command to be executed on the main thread,
2116 * waits for the request to complete, and returns the result.
2117 * @see #sendRequestAsync
2118 */
2119 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002120 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2121 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002122 }
2123
2124 /**
2125 * Posts the specified command to be executed on the main thread,
2126 * waits for the request to complete, and returns the result.
2127 * @see #sendRequestAsync
2128 */
2129 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2130 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002131 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002132 }
2133
2134 /**
2135 * Posts the specified command to be executed on the main thread,
2136 * waits for the request to complete, and returns the result.
2137 * @see #sendRequestAsync
2138 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002139 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002140 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2141 }
2142
2143 /**
2144 * Posts the specified command to be executed on the main thread,
2145 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2146 * if not timeout or null otherwise.
2147 * @see #sendRequestAsync
2148 */
2149 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2150 long timeoutInMs) {
2151 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002152 }
2153
2154 /**
2155 * Posts the specified command to be executed on the main thread,
2156 * waits for the request to complete, and returns the result.
2157 * @see #sendRequestAsync
2158 */
Nathan Harold92bed182018-10-12 18:16:49 -07002159 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002160 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002161 }
2162
2163 /**
2164 * Posts the specified command to be executed on the main thread,
2165 * waits for the request to complete, and returns the result.
2166 * @see #sendRequestAsync
2167 */
2168 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002169 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2170 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002171 }
2172
2173 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002174 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2175 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2176 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002177 * @see #sendRequestAsync
2178 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2180 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2182 throw new RuntimeException("This method will deadlock if called from the main thread.");
2183 }
2184
Nathan Harold92bed182018-10-12 18:16:49 -07002185 MainThreadRequest request = null;
2186 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2187 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2188 } else if (phone != null) {
2189 request = new MainThreadRequest(argument, phone, workSource);
2190 } else {
2191 request = new MainThreadRequest(argument, subId, workSource);
2192 }
2193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 Message msg = mMainThreadHandler.obtainMessage(command, request);
2195 msg.sendToTarget();
2196
Rambo Wang0f050d82021-02-12 11:43:36 -08002197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 if (timeoutInMs >= 0) {
2200 // Wait for at least timeoutInMs before returning null request result
2201 long now = SystemClock.elapsedRealtime();
2202 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002203 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002204 try {
2205 request.wait(deadline - now);
2206 } catch (InterruptedException e) {
2207 // Do nothing, go back and check if request is completed or timeout
2208 } finally {
2209 now = SystemClock.elapsedRealtime();
2210 }
2211 }
2212 } else {
2213 // Wait for the request to complete
2214 while (request.result == null) {
2215 try {
2216 request.wait();
2217 } catch (InterruptedException e) {
2218 // Do nothing, go back and wait until the request is complete
2219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002223 if (request.result == null) {
2224 Log.wtf(LOG_TAG,
2225 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 return request.result;
2228 }
2229
2230 /**
2231 * Asynchronous ("fire and forget") version of sendRequest():
2232 * Posts the specified command to be executed on the main thread, and
2233 * returns immediately.
2234 * @see #sendRequest
2235 */
2236 private void sendRequestAsync(int command) {
2237 mMainThreadHandler.sendEmptyMessage(command);
2238 }
2239
2240 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002242 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002243 */
2244 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 sendRequestAsync(command, argument, null, null);
2246 }
2247
2248 /**
2249 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2250 * @see {@link #sendRequest(int,Object)}
2251 */
2252 private void sendRequestAsync(
2253 int command, Object argument, Phone phone, WorkSource workSource) {
2254 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002255 Message msg = mMainThreadHandler.obtainMessage(command, request);
2256 msg.sendToTarget();
2257 }
2258
2259 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 * Initialize the singleton PhoneInterfaceManager instance.
2261 * This is only done once, at startup, from PhoneApp.onCreate().
2262 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 synchronized (PhoneInterfaceManager.class) {
2265 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002266 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 } else {
2268 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2269 }
2270 return sInstance;
2271 }
2272 }
2273
2274 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002275 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002278 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002279 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002281 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002283 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002284 mTelephonySharedPreferences =
2285 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002286 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002287 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002288 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002289 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 publish();
2292 }
2293
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002294 private Phone getDefaultPhone() {
2295 Phone thePhone = getPhone(getDefaultSubscription());
2296 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2297 }
2298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 private void publish() {
2300 if (DBG) log("publish: " + this);
2301
Peter Wangc035ce42020-01-08 21:00:22 -08002302 TelephonyFrameworkInitializer
2303 .getTelephonyServiceManager()
2304 .getTelephonyServiceRegisterer()
2305 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
Stuart Scott584921c2015-01-15 17:10:34 -08002308 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002309 if (request.phone != null) {
2310 return request.phone;
2311 } else {
2312 return getPhoneFromSubId(request.subId);
2313 }
2314 }
2315
2316 private Phone getPhoneFromSubId(int subId) {
2317 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2318 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002319 }
2320
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002321 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002322 Phone phone = getPhoneFromRequest(request);
2323 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002324 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002325 }
2326
Wink Saville36469e72014-06-11 15:17:00 -07002327 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002329 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331
Kai Shif70f46f2021-03-03 13:59:46 -08002332 private void sendEraseModemConfig(@NonNull Phone phone) {
2333 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2334 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2335 }
2336
2337 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2338 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2339 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002340 }
2341
Peter Wang44b186e2020-01-13 23:33:09 -08002342 private boolean isImsAvailableOnDevice() {
2343 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2344 if (pm == null) {
2345 // For some reason package manger is not available.. This will fail internally anyway,
2346 // so do not throw error and allow.
2347 return true;
2348 }
2349 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2350 }
2351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002353 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002354 }
2355
Wink Savilleb564aae2014-10-23 10:18:09 -07002356 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 if (DBG) log("dial: " + number);
2358 // No permission check needed here: This is just a wrapper around the
2359 // ACTION_DIAL intent, which is available to any app since it puts up
2360 // the UI before it does anything.
2361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 String url = createTelUrl(number);
2365 if (url == null) {
2366 return;
2367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 // PENDING: should we just silently fail if phone is offhook or ringing?
2370 PhoneConstants.State state = mCM.getState(subId);
2371 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2372 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2373 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2374 mApp.startActivity(intent);
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379 }
2380
2381 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002382 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
2384
Wink Savilleb564aae2014-10-23 10:18:09 -07002385 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 if (DBG) log("call: " + number);
2387
2388 // This is just a wrapper around the ACTION_CALL intent, but we still
2389 // need to do a permission check since we're calling startActivity()
2390 // from the context of the phone app.
2391 enforceCallPermission();
2392
Jordan Liu1617b712019-07-10 15:06:26 -07002393 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 != AppOpsManager.MODE_ALLOWED) {
2395 return;
2396 }
2397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 String url = createTelUrl(number);
2401 if (url == null) {
2402 return;
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002405 boolean isValid = false;
2406 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2407 if (slist != null) {
2408 for (SubscriptionInfo subInfoRecord : slist) {
2409 if (subInfoRecord.getSubscriptionId() == subId) {
2410 isValid = true;
2411 break;
2412 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002413 }
Wink Saville08874612014-08-31 19:19:58 -07002414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 if (!isValid) {
2416 return;
2417 }
Wink Saville08874612014-08-31 19:19:58 -07002418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2420 intent.putExtra(SUBSCRIPTION_KEY, subId);
2421 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2422 mApp.startActivity(intent);
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427
Wink Savilleb564aae2014-10-23 10:18:09 -07002428 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002429 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002430 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002434 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002435 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2436 }
2437
Wink Savilleb564aae2014-10-23 10:18:09 -07002438 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002443 Phone phone = getPhone(subId);
2444 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 checkSimPin.start();
2446 return checkSimPin.unlockSim(null, pin);
2447 } finally {
2448 Binder.restoreCallingIdentity(identity);
2449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 }
2451
Wink Savilleb564aae2014-10-23 10:18:09 -07002452 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454
2455 final long identity = Binder.clearCallingIdentity();
2456 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002457 Phone phone = getPhone(subId);
2458 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 checkSimPuk.start();
2460 return checkSimPuk.unlockSim(puk, pin);
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
2463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
2466 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002467 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 * a synchronous one.
2469 */
2470 private static class UnlockSim extends Thread {
2471
2472 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002473 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474
2475 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002476 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2477 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478
2479 // For replies from SimCard interface
2480 private Handler mHandler;
2481
2482 // For async handler to identify request type
2483 private static final int SUPPLY_PIN_COMPLETE = 100;
2484
Michele Berionne5e411512020-11-13 02:36:59 +00002485 UnlockSim(int phoneId, IccCard simCard) {
2486 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 mSimCard = simCard;
2488 }
2489
2490 @Override
2491 public void run() {
2492 Looper.prepare();
2493 synchronized (UnlockSim.this) {
2494 mHandler = new Handler() {
2495 @Override
2496 public void handleMessage(Message msg) {
2497 AsyncResult ar = (AsyncResult) msg.obj;
2498 switch (msg.what) {
2499 case SUPPLY_PIN_COMPLETE:
2500 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2501 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002502 mRetryCount = msg.arg1;
2503 if (ar.exception != null) {
2504 if (ar.exception instanceof CommandException &&
2505 ((CommandException)(ar.exception)).getCommandError()
2506 == CommandException.Error.PASSWORD_INCORRECT) {
2507 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002508 } //When UiccCardApp dispose,handle message and return exception
2509 else if (ar.exception instanceof CommandException &&
2510 ((CommandException) (ar.exception)).getCommandError()
2511 == CommandException.Error.ABORTED) {
2512 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002513 } else {
2514 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2515 }
2516 } else {
2517 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 mDone = true;
2520 UnlockSim.this.notifyAll();
2521 }
2522 break;
2523 }
2524 }
2525 };
2526 UnlockSim.this.notifyAll();
2527 }
2528 Looper.loop();
2529 }
2530
2531 /*
2532 * Use PIN or PUK to unlock SIM card
2533 *
2534 * If PUK is null, unlock SIM card with PIN
2535 *
2536 * If PUK is not null, unlock SIM card with PUK and set PIN code
2537 */
Wink Saville9de0f752013-10-22 19:04:03 -07002538 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
2540 while (mHandler == null) {
2541 try {
2542 wait();
2543 } catch (InterruptedException e) {
2544 Thread.currentThread().interrupt();
2545 }
2546 }
2547 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2548
2549 if (puk == null) {
2550 mSimCard.supplyPin(pin, callback);
2551 } else {
2552 mSimCard.supplyPuk(puk, pin, callback);
2553 }
2554
2555 while (!mDone) {
2556 try {
2557 Log.d(LOG_TAG, "wait for done");
2558 wait();
2559 } catch (InterruptedException e) {
2560 // Restore the interrupted status
2561 Thread.currentThread().interrupt();
2562 }
2563 }
2564 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002565 int[] resultArray = new int[2];
2566 resultArray[0] = mResult;
2567 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002568
2569 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002570 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002571 }
2572
Wink Saville9de0f752013-10-22 19:04:03 -07002573 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575 }
2576
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002577 /**
2578 * This method has been removed due to privacy and stability concerns.
2579 */
2580 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002582 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2583 return;
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Nathan Harold1f889d82020-06-04 17:05:26 -07002586 @Override
2587 public void updateServiceLocationWithPackageName(String callingPackage) {
2588 mApp.getSystemService(AppOpsManager.class)
2589 .checkPackage(Binder.getCallingUid(), callingPackage);
2590
Nathan Haroldf096d982020-11-18 17:18:06 -08002591 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002592 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2593 // Callers targeting S have no business invoking this method.
2594 return;
2595 }
2596
2597 LocationAccessPolicy.LocationPermissionResult locationResult =
2598 LocationAccessPolicy.checkLocationPermission(mApp,
2599 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2600 .setCallingPackage(callingPackage)
2601 .setCallingFeatureId(null)
2602 .setCallingPid(Binder.getCallingPid())
2603 .setCallingUid(Binder.getCallingUid())
2604 .setMethod("updateServiceLocation")
2605 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2606 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2607 .build());
2608 // Apps that lack location permission have no business calling this method;
2609 // however, because no permission was declared in the public API, denials must
2610 // all be "soft".
2611 switch (locationResult) {
2612 case DENIED_HARD: /* fall through */
2613 case DENIED_SOFT:
2614 return;
2615 }
2616
2617 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002620 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002622 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 @Override
2631 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 return isRadioOnWithFeature(callingPackage, null);
2633 }
2634
2635
2636 @Override
2637 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2638 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2639 callingFeatureId);
2640 }
2641
2642 @Deprecated
2643 @Override
2644 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2645 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002649 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2650 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002652 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 return false;
2654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 return isRadioOnForSubscriber(subId);
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002662 }
2663
2664 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
2669 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2670 } else {
2671 return false;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
2678 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
Wink Saville36469e72014-06-11 15:17:00 -07002681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 final Phone phone = getPhone(subId);
2688 if (phone != null) {
2689 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Wink Saville36469e72014-06-11 15:17:00 -07002694 }
2695
2696 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002697 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 if (phone == null) {
2707 return false;
2708 }
2709 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2710 toggleRadioOnOffForSubscriber(subId);
2711 }
2712 return true;
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
Wink Saville36469e72014-06-11 15:17:00 -07002717
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002719 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 /*
2721 * If any of the Radios are available, it will need to be
2722 * shutdown. So return true if any Radio is available.
2723 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2727 Phone phone = PhoneFactory.getPhone(i);
2728 if (phone != null && phone.isRadioAvailable()) return true;
2729 }
2730 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2731 return false;
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002734 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 }
2736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002738 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 enforceModifyPermission();
2740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2744 logv("Shutting down Phone " + i);
2745 shutdownRadioUsingPhoneId(i);
2746 }
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002749 }
2750 }
2751
2752 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002753 Phone phone = PhoneFactory.getPhone(phoneId);
2754 if (phone != null && phone.isRadioAvailable()) {
2755 phone.shutdownRadio();
2756 }
2757 }
2758
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2765 if (defaultPhone != null) {
2766 defaultPhone.setRadioPower(turnOn);
2767 return true;
2768 } else {
2769 loge("There's no default phone.");
2770 return false;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002774 }
Wink Saville36469e72014-06-11 15:17:00 -07002775 }
2776
Wink Savilleb564aae2014-10-23 10:18:09 -07002777 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(subId);
2783 if (phone != null) {
2784 phone.setRadioPower(turnOn);
2785 return true;
2786 } else {
2787 return false;
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Wink Saville36469e72014-06-11 15:17:00 -07002794 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 public boolean enableDataConnectivity() {
2797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 int subId = mSubscriptionController.getDefaultDataSubId();
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002804 if (phone.isUsingNewDataStack()) {
2805 phone.getDataSettingsManager().setDataEnabled(
2806 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2807 } else {
2808 phone.getDataEnabledSettings().setDataEnabled(
2809 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 return true;
2812 } else {
2813 return false;
2814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819
Wink Saville36469e72014-06-11 15:17:00 -07002820 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 public boolean disableDataConnectivity() {
2823 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824
2825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 int subId = mSubscriptionController.getDefaultDataSubId();
2828 final Phone phone = getPhone(subId);
2829 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002830 if (phone.isUsingNewDataStack()) {
2831 phone.getDataSettingsManager().setDataEnabled(
2832 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2833 } else {
2834 phone.getDataEnabledSettings().setDataEnabled(
2835 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 return true;
2838 } else {
2839 return false;
2840 }
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002847 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 final Phone phone = getPhone(subId);
2851 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002852 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 } else {
2854 return false;
2855 }
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
2861 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002862 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002863 }
2864
pkanwarae03a6b2016-11-06 20:37:09 -08002865 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866 enforceCallPermission();
2867
2868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2871 return;
2872 }
2873 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2874 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
2877 }
pkanwar32d516d2016-10-14 19:37:38 -07002878 };
2879
Wink Savilleb564aae2014-10-23 10:18:09 -07002880 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2886 return false;
2887 }
2888 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 }
2893
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002894 /**
2895 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2896 * tag on getCallState Binder call.
2897 */
2898 @Deprecated
2899 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002900 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002901 if (CompatChanges.isChangeEnabled(
2902 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2903 Binder.getCallingUid())) {
2904 // Do not allow this API to be called on API version 31+, it should only be
2905 // called on old apps using this Binder call directly.
2906 throw new SecurityException("This method can only be used for applications "
2907 + "targeting API version 30 or less.");
2908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 final long identity = Binder.clearCallingIdentity();
2910 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002911 Phone phone = getPhone(getDefaultSubscription());
2912 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2913 PhoneConstantConversions.convertCallState(phone.getState());
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
2917 }
2918
2919 @Override
2920 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2921 if (CompatChanges.isChangeEnabled(
2922 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2923 Binder.getCallingUid())) {
2924 // Check READ_PHONE_STATE for API version 31+
2925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2926 featureId, "getCallStateForSubscription")) {
2927 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2928 + "targeting API level 31+.");
2929 }
2930 }
2931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2935 PhoneConstantConversions.convertCallState(phone.getState());
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 }
2940
Sanket Padawe356d7632015-06-22 14:03:32 -07002941 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002942 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002943 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2944 }
2945
2946 @Override
2947 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 final long identity = Binder.clearCallingIdentity();
2949 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002950 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08002952 if (phone.isUsingNewDataStack()) {
2953 return phone.getDataNetworkController().getInternetDataNetworkState();
2954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2956 } else {
2957 return PhoneConstantConversions.convertDataState(
2958 PhoneConstants.DataState.DISCONNECTED);
2959 }
2960 } finally {
2961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002963 }
2964
Sanket Padawe356d7632015-06-22 14:03:32 -07002965 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002966 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002967 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2968 }
2969
2970 @Override
2971 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002974 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 if (phone != null) {
2976 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2977 } else {
2978 return TelephonyManager.DATA_ACTIVITY_NONE;
2979 }
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 }
2984
2985 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002986 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002988 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002989
2990 LocationAccessPolicy.LocationPermissionResult locationResult =
2991 LocationAccessPolicy.checkLocationPermission(mApp,
2992 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2993 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002994 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002995 .setCallingPid(Binder.getCallingPid())
2996 .setCallingUid(Binder.getCallingUid())
2997 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002998 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002999 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3000 .build());
3001 switch (locationResult) {
3002 case DENIED_HARD:
3003 throw new SecurityException("Not allowed to access cell location");
3004 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003005 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3006 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 }
3008
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003013 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003014 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
Svetoslav64fad262015-04-14 14:35:21 -07003018 }
3019
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003021 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003022 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3023 // registered cell info, so return a NULL country instead.
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003026 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3027 // Get default phone in this case.
3028 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3029 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003030 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003032 if (phone == null) return "";
3033 ServiceStateTracker sst = phone.getServiceStateTracker();
3034 if (sst == null) return "";
3035 LocaleTracker lt = sst.getLocaleTracker();
3036 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003037 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003041 }
3042
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003043 /**
3044 * This method was removed due to potential issues caused by performing partial
3045 * updates of service state, and lack of a credible use case.
3046 *
3047 * This has the ability to break the telephony implementation by disabling notification of
3048 * changes in device connectivity. DO NOT USE THIS!
3049 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003050 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 public void enableLocationUpdates() {
3052 mApp.enforceCallingOrSelfPermission(
3053 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 }
3055
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003056 /**
3057 * This method was removed due to potential issues caused by performing partial
3058 * updates of service state, and lack of a credible use case.
3059 *
3060 * This has the ability to break the telephony implementation by disabling notification of
3061 * changes in device connectivity. DO NOT USE THIS!
3062 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 @Override
3064 public void disableLocationUpdates() {
3065 mApp.enforceCallingOrSelfPermission(
3066 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 }
3068
3069 @Override
3070 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003071 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3072 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003073 try {
3074 mApp.getSystemService(AppOpsManager.class)
3075 .checkPackage(Binder.getCallingUid(), callingPackage);
3076 } catch (SecurityException e) {
3077 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3078 throw e;
3079 }
3080
Nathan Haroldf096d982020-11-18 17:18:06 -08003081 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003082 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3083 throw new SecurityException(
3084 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3085 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003086
Jordan Liu1617b712019-07-10 15:06:26 -07003087 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3089 return null;
3090 }
Svetoslav64fad262015-04-14 14:35:21 -07003091
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003092 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003094 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003095 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096
Nathan Haroldf180aac2018-06-01 18:43:55 -07003097 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3098 for (CellInfo ci : info) {
3099 if (ci instanceof CellInfoGsm) {
3100 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3101 } else if (ci instanceof CellInfoWcdma) {
3102 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003105 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003106 }
3107
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003108 private List<CellInfo> getCachedCellInfo() {
3109 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3110 for (Phone phone : PhoneFactory.getPhones()) {
3111 List<CellInfo> info = phone.getAllCellInfo();
3112 if (info != null) cellInfos.addAll(info);
3113 }
3114 return cellInfos;
3115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116
3117 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003118 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003119 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003120 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003121
3122 LocationAccessPolicy.LocationPermissionResult locationResult =
3123 LocationAccessPolicy.checkLocationPermission(mApp,
3124 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3125 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003126 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003127 .setCallingPid(Binder.getCallingPid())
3128 .setCallingUid(Binder.getCallingUid())
3129 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003130 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003131 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3132 .build());
3133 switch (locationResult) {
3134 case DENIED_HARD:
3135 throw new SecurityException("Not allowed to access cell info");
3136 case DENIED_SOFT:
3137 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 }
3139
Nathan Haroldf096d982020-11-18 17:18:06 -08003140 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003141 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3142 return getCachedCellInfo();
3143 }
3144
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003145 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003146 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3150 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003151 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003152 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 if (info != null) cellInfos.addAll(info);
3154 }
3155 return cellInfos;
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159 }
3160
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003161 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003162 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3163 String callingFeatureId) {
3164 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3165 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003166 }
3167
3168 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003169 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3170 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003171 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003173 }
3174
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003175 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3176 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003178 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003179
3180 LocationAccessPolicy.LocationPermissionResult locationResult =
3181 LocationAccessPolicy.checkLocationPermission(mApp,
3182 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3183 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003184 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setCallingPid(Binder.getCallingPid())
3186 .setCallingUid(Binder.getCallingUid())
3187 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003188 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3189 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003190 .build());
3191 switch (locationResult) {
3192 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003193 if (TelephonyPermissions
3194 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003195 // Safetynet logging for b/154934934
3196 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3197 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003198 throw new SecurityException("Not allowed to access cell info");
3199 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003200 if (TelephonyPermissions
3201 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003202 // Safetynet logging for b/154934934
3203 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3204 }
Nathan Harold5320c422019-05-09 10:26:08 -07003205 try {
3206 cb.onCellInfo(new ArrayList<CellInfo>());
3207 } catch (RemoteException re) {
3208 // Drop without consequences
3209 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003210 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003211 }
3212
Nathan Harolda939a962019-05-09 10:13:47 -07003213
3214 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003215 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3216
3217 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3218 }
3219
3220 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003222 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003223 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224
3225 final long identity = Binder.clearCallingIdentity();
3226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003231 }
3232
Shishir Agrawala9f32182016-04-12 12:00:16 -07003233 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003234 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003235 Phone phone = PhoneFactory.getPhone(slotIndex);
3236 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003237 return null;
3238 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003239 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003240 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003241 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003242 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003243 return null;
3244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245
3246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 return phone.getImei();
3249 } finally {
3250 Binder.restoreCallingIdentity(identity);
3251 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003252 }
3253
3254 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003255 public String getTypeAllocationCodeForSlot(int slotIndex) {
3256 Phone phone = PhoneFactory.getPhone(slotIndex);
3257 String tac = null;
3258 if (phone != null) {
3259 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003260 try {
3261 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3262 } catch (IndexOutOfBoundsException e) {
3263 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3264 return null;
3265 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003266 }
3267 return tac;
3268 }
3269
3270 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003271 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003272 try {
3273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3274 } catch (SecurityException se) {
3275 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3276 throw new SecurityException("Package " + callingPackage + " does not belong to "
3277 + Binder.getCallingUid());
3278 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003279 Phone phone = PhoneFactory.getPhone(slotIndex);
3280 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003281 return null;
3282 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003283
Jeff Davidson913390f2018-02-23 17:11:49 -08003284 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003285 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003286 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 return null;
3288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289
3290 final long identity = Binder.clearCallingIdentity();
3291 try {
3292 return phone.getMeid();
3293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
Jack Yu2af8d712017-03-15 17:14:14 -07003296 }
3297
3298 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003299 public String getManufacturerCodeForSlot(int slotIndex) {
3300 Phone phone = PhoneFactory.getPhone(slotIndex);
3301 String manufacturerCode = null;
3302 if (phone != null) {
3303 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003304 try {
3305 manufacturerCode =
3306 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3307 } catch (IndexOutOfBoundsException e) {
3308 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3309 return null;
3310 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003311 }
3312 return manufacturerCode;
3313 }
3314
3315 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003316 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3317 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003318 Phone phone = PhoneFactory.getPhone(slotIndex);
3319 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 return null;
3321 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003322 int subId = phone.getSubId();
3323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003324 mApp, subId, callingPackage, callingFeatureId,
3325 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003326 return null;
3327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328
3329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 return phone.getDeviceSvn();
3332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003335 }
3336
fionaxu43304da2017-11-27 22:51:16 -08003337 @Override
3338 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 final Phone phone = getPhone(subId);
3342 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
fionaxu43304da2017-11-27 22:51:16 -08003346 }
3347
3348 @Override
3349 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 final Phone phone = getPhone(subId);
3353 return phone == null ? null : phone.getCarrierName();
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
fionaxu43304da2017-11-27 22:51:16 -08003357 }
3358
calvinpanffe225e2018-11-01 19:43:06 +08003359 @Override
chen xu0026ca62019-03-06 15:28:50 -08003360 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 final Phone phone = getPhone(subId);
3364 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003365 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
chen xu0026ca62019-03-06 15:28:50 -08003372 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003373 final long identity = Binder.clearCallingIdentity();
3374 try {
3375 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003376 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
3380 }
3381
chen xu651eec72018-11-11 19:03:44 -08003382 @Override
chen xu864e11c2018-12-06 22:10:03 -08003383 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3384 if (!isSubscriptionMccMnc) {
3385 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3386 }
chen xu651eec72018-11-11 19:03:44 -08003387 final Phone phone = PhoneFactory.getPhone(slotIndex);
3388 if (phone == null) {
3389 return TelephonyManager.UNKNOWN_CARRIER_ID;
3390 }
3391 final long identity = Binder.clearCallingIdentity();
3392 try {
3393 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
3397 }
3398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 //
3400 // Internal helper methods.
3401 //
3402
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003403 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003404 * Make sure the caller is the calling package itself
3405 *
3406 * @throws SecurityException if the caller is not the calling package
3407 */
3408 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3409 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003410 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3411 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003412 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003413 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003414 } catch (PackageManager.NameNotFoundException e) {
3415 // packageUid is -1
3416 }
3417 if (packageUid != callingUid) {
3418 throw new SecurityException(message + ": Package " + callingPackage
3419 + " does not belong to " + callingUid);
3420 }
3421 }
3422
3423 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003424 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3425 *
3426 * @throws SecurityException if the caller does not have the required permission
3427 */
3428 private void enforceModifyPermission() {
3429 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3430 }
3431
Shuo Qian3b6ee772019-11-13 17:43:31 -08003432 private void enforceActiveEmergencySessionPermission() {
3433 mApp.enforceCallingOrSelfPermission(
3434 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3435 }
3436
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 /**
3438 * Make sure the caller has the CALL_PHONE permission.
3439 *
3440 * @throws SecurityException if the caller does not have the required permission
3441 */
3442 private void enforceCallPermission() {
3443 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3444 }
3445
paulhu5a773602019-08-23 19:17:33 +08003446 private void enforceSettingsPermission() {
3447 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003448 }
3449
Michele Berionne5e411512020-11-13 02:36:59 +00003450 private void enforceRebootPermission() {
3451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3452 }
3453
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 private String createTelUrl(String number) {
3455 if (TextUtils.isEmpty(number)) {
3456 return null;
3457 }
3458
Jake Hambye994d462014-02-03 13:10:13 -08003459 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003460 }
3461
Ihab Awadf9e92732013-12-05 18:02:52 -08003462 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3464 }
3465
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003466 private static void logv(String msg) {
3467 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3468 }
3469
Ihab Awadf9e92732013-12-05 18:02:52 -08003470 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3472 }
3473
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003474 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003475 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003476 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003477 }
3478
Sanket Padawe356d7632015-06-22 14:03:32 -07003479 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003480 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 final Phone phone = PhoneFactory.getPhone(slotIndex);
3484 if (phone == null) {
3485 return PhoneConstants.PHONE_TYPE_NONE;
3486 } else {
3487 return phone.getPhoneType();
3488 }
3489 } finally {
3490 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003492 }
3493
3494 /**
3495 * Returns the CDMA ERI icon index to display
3496 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003497 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003498 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3499 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3500 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003501 }
3502
Sanket Padawe356d7632015-06-22 14:03:32 -07003503 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003504 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3505 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003507 mApp, subId, callingPackage, callingFeatureId,
3508 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003509 return -1;
3510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 final Phone phone = getPhone(subId);
3515 if (phone != null) {
3516 return phone.getCdmaEriIconIndex();
3517 } else {
3518 return -1;
3519 }
3520 } finally {
3521 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 }
3524
3525 /**
3526 * Returns the CDMA ERI icon mode,
3527 * 0 - ON
3528 * 1 - FLASHING
3529 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003530 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003531 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3532 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3533 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003534 }
3535
Sanket Padawe356d7632015-06-22 14:03:32 -07003536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003537 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3538 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003540 mApp, subId, callingPackage, callingFeatureId,
3541 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003542 return -1;
3543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = getPhone(subId);
3548 if (phone != null) {
3549 return phone.getCdmaEriIconMode();
3550 } else {
3551 return -1;
3552 }
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003556 }
3557
3558 /**
3559 * Returns the CDMA ERI text,
3560 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003562 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3563 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3564 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003565 }
3566
Sanket Padawe356d7632015-06-22 14:03:32 -07003567 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003568 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3569 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003571 mApp, subId, callingPackage, callingFeatureId,
3572 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003573 return null;
3574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575
3576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 final Phone phone = getPhone(subId);
3579 if (phone != null) {
3580 return phone.getCdmaEriText();
3581 } else {
3582 return null;
3583 }
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003587 }
3588
3589 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003590 * Returns the CDMA MDN.
3591 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003592 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003593 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3595 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596
3597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003600 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601 return phone.getLine1Number();
3602 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003603 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 return null;
3605 }
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003608 }
3609 }
3610
3611 /**
3612 * Returns the CDMA MIN.
3613 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003615 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3617 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618
3619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 final Phone phone = getPhone(subId);
3622 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3623 return phone.getCdmaMin();
3624 } else {
3625 return null;
3626 }
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003629 }
3630 }
3631
Hall Liud892bec2018-11-30 14:51:45 -08003632 @Override
3633 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3634 INumberVerificationCallback callback, String callingPackage) {
3635 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3636 != PERMISSION_GRANTED) {
3637 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3638 }
3639 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3640
3641 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3642 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003643 throw new SecurityException("Calling package must be configured in the device config: "
3644 + "calling package: " + callingPackage
3645 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003646 }
3647
3648 if (range == null) {
3649 throw new NullPointerException("Range must be non-null");
3650 }
3651
3652 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003653 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003654
3655 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3656 }
3657
Junda Liuca05d5d2014-08-14 22:36:34 -07003658 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 * Returns true if CDMA provisioning needs to run.
3660 */
3661 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003664 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003668 }
3669
3670 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003671 * Sets the voice mail number of a given subId.
3672 */
3673 @Override
3674 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003675 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3676 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677
3678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3681 new Pair<String, String>(alphaTag, number), new Integer(subId));
3682 return success;
3683 } finally {
3684 Binder.restoreCallingIdentity(identity);
3685 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003686 }
3687
Ta-wei Yen87c49842016-05-13 21:19:52 -07003688 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003689 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003691 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3692 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003693 if (!TextUtils.equals(callingPackage, systemDialer)) {
3694 throw new SecurityException("caller must be system dialer");
3695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3700 if (phoneAccountHandle == null) {
3701 return null;
3702 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 } finally {
3705 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003706 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003707 }
3708
3709 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003710 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3711 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003714 mApp, subId, callingPackage, callingFeatureId,
3715 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003716 return null;
3717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003719 final long identity = Binder.clearCallingIdentity();
3720 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003721 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003722 } finally {
3723 Binder.restoreCallingIdentity(identity);
3724 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003725 }
3726
3727 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003728 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3729 VisualVoicemailSmsFilterSettings settings) {
3730 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003735 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003739 }
3740
3741 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003742 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3743 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744
3745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003748 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749 } finally {
3750 Binder.restoreCallingIdentity(identity);
3751 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003752 }
3753
3754 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003755 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3756 String callingPackage, int subId) {
3757 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758
3759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003762 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003766 }
3767
3768 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003769 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003770 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771
3772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003775 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003779 }
3780
3781 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003782 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3783 String callingAttributionTag, int subId, String number, int port, String text,
3784 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003785 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003786 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003787 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003788 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003789 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3790 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003791 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003792
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003793 /**
fionaxu0152e512016-11-14 13:36:14 -08003794 * Sets the voice activation state of a given subId.
3795 */
3796 @Override
3797 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3799 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800
3801 final long identity = Binder.clearCallingIdentity();
3802 try {
3803 final Phone phone = getPhone(subId);
3804 if (phone != null) {
3805 phone.setVoiceActivationState(activationState);
3806 } else {
3807 loge("setVoiceActivationState fails with invalid subId: " + subId);
3808 }
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003811 }
3812 }
3813
3814 /**
3815 * Sets the data activation state of a given subId.
3816 */
3817 @Override
3818 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3820 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821
3822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 final Phone phone = getPhone(subId);
3825 if (phone != null) {
3826 phone.setDataActivationState(activationState);
3827 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003828 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 }
3830 } finally {
3831 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003832 }
3833 }
3834
3835 /**
3836 * Returns the voice activation state of a given subId.
3837 */
3838 @Override
3839 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841
fionaxu0152e512016-11-14 13:36:14 -08003842 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843 final long identity = Binder.clearCallingIdentity();
3844 try {
3845 if (phone != null) {
3846 return phone.getVoiceActivationState();
3847 } else {
3848 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3849 }
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003852 }
3853 }
3854
3855 /**
3856 * Returns the data activation state of a given subId.
3857 */
3858 @Override
3859 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861
fionaxu0152e512016-11-14 13:36:14 -08003862 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 if (phone != null) {
3866 return phone.getDataActivationState();
3867 } else {
3868 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3869 }
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003872 }
3873 }
3874
3875 /**
Wink Saville36469e72014-06-11 15:17:00 -07003876 * Returns the unread count of voicemails for a subId
3877 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003878 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003879 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3880 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003882 mApp, subId, callingPackage, callingFeatureId,
3883 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003884 return 0;
3885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 final Phone phone = getPhone(subId);
3889 if (phone != null) {
3890 return phone.getVoiceMessageCount();
3891 } else {
3892 return 0;
3893 }
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 }
3898
3899 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003900 * returns true, if the device is in a state where both voice and data
3901 * are supported simultaneously. This can change based on location or network condition.
3902 */
3903 @Override
3904 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 final Phone phone = getPhone(subId);
3908 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
3911 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003912 }
3913
3914 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003915 * Send the dialer code if called from the current default dialer or the caller has
3916 * carrier privilege.
3917 * @param inputCode The dialer code to send
3918 */
3919 @Override
3920 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003921 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003923 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3924 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003925 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003926 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003929
3930 final long identity = Binder.clearCallingIdentity();
3931 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003932 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 } finally {
3934 Binder.restoreCallingIdentity(identity);
3935 }
fionaxu235cc5e2017-03-06 22:25:57 -08003936 }
3937
Pengquan Menga1bb6272018-09-06 09:59:22 -07003938 @Override
3939 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003940 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003941 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003942 mApp, subId, "getNetworkSelectionMode");
3943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 if (!isActiveSubscription(subId)) {
3946 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3947 }
3948 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003951 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003952 }
3953
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003955 public boolean isInEmergencySmsMode() {
3956 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 for (Phone phone : PhoneFactory.getPhones()) {
3960 if (phone.isInEmergencySmsMode()) {
3961 return true;
3962 }
3963 }
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
3967 return false;
3968 }
3969
shilu366312e2019-12-17 09:28:10 -08003970 /**
3971 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3972 * @param subId The subscription to use to check the configuration.
3973 * @param c The callback that will be used to send the result.
3974 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003975 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003976 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3977 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003978 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003979 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003980
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003981 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3982 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3983 "IMS not available on device.");
3984 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 final long token = Binder.clearCallingIdentity();
3986 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003987 int slotId = getSlotIndexOrException(subId);
3988 verifyImsMmTelConfiguredOrThrow(slotId);
3989 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003990 } catch (ImsException e) {
3991 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 } finally {
3993 Binder.restoreCallingIdentity(token);
3994 }
3995 }
3996
shilu366312e2019-12-17 09:28:10 -08003997 /**
3998 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3999 * @param subId The subscription to use to check the configuration.
4000 * @param c The callback that will be used to send the result.
4001 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004003 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004004 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004005 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004006 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4007 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4008 }
Meng Wangafbc5852019-09-19 17:37:13 -07004009 final long token = Binder.clearCallingIdentity();
4010 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4012 .removeRegistrationCallbackForSubscription(c, subId);
4013 } catch (ImsException e) {
4014 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4015 + "is inactive, ignoring unregister.");
4016 // If the subscription is no longer active, just return, since the callback
4017 // will already have been removed internally.
4018 } finally {
4019 Binder.restoreCallingIdentity(token);
4020 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 }
4022
Brad Ebingera34a6c22019-10-22 17:36:18 -07004023 /**
4024 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4025 */
4026 @Override
4027 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4028 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4031 "IMS not available on device.");
4032 }
4033 final long token = Binder.clearCallingIdentity();
4034 try {
4035 Phone phone = getPhone(subId);
4036 if (phone == null) {
4037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4038 + subId + "'");
4039 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4040 }
4041 phone.getImsRegistrationState(regState -> {
4042 try {
4043 consumer.accept((regState == null)
4044 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4045 } catch (RemoteException e) {
4046 // Ignore if the remote process is no longer available to call back.
4047 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4048 }
4049 });
4050 } finally {
4051 Binder.restoreCallingIdentity(token);
4052 }
4053 }
4054
4055 /**
4056 * Get the transport type for the IMS service registration state.
4057 */
4058 @Override
4059 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004060 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004061 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004062 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4063 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4064 "IMS not available on device.");
4065 }
4066 final long token = Binder.clearCallingIdentity();
4067 try {
4068 Phone phone = getPhone(subId);
4069 if (phone == null) {
4070 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4071 + subId + "'");
4072 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4073 }
4074 phone.getImsRegistrationTech(regTech -> {
4075 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4076 int regTechConverted = (regTech == null)
4077 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4078 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4079 regTechConverted);
4080 try {
4081 consumer.accept(regTechConverted);
4082 } catch (RemoteException e) {
4083 // Ignore if the remote process is no longer available to call back.
4084 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4085 }
4086 });
4087 } finally {
4088 Binder.restoreCallingIdentity(token);
4089 }
4090 }
4091
shilu366312e2019-12-17 09:28:10 -08004092 /**
4093 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4094 * @param subId The subscription to use to check the configuration.
4095 * @param c The callback that will be used to send the result.
4096 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004098 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4099 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004100 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004101 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004102 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4103 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4104 "IMS not available on device.");
4105 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 final long token = Binder.clearCallingIdentity();
4107 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004108 int slotId = getSlotIndexOrException(subId);
4109 verifyImsMmTelConfiguredOrThrow(slotId);
4110 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004111 } catch (ImsException e) {
4112 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 } finally {
4114 Binder.restoreCallingIdentity(token);
4115 }
4116 }
4117
shilu366312e2019-12-17 09:28:10 -08004118 /**
4119 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4120 * @param subId The subscription to use to check the configuration.
4121 * @param c The callback that will be used to send the result.
4122 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004124 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004125 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004126 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004127 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4128 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4129 }
Meng Wangafbc5852019-09-19 17:37:13 -07004130
4131 final long token = Binder.clearCallingIdentity();
4132 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004133 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004134 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004135 } catch (ImsException e) {
4136 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4137 + "is inactive, ignoring unregister.");
4138 // If the subscription is no longer active, just return, since the callback
4139 // will already have been removed internally.
4140 } finally {
4141 Binder.restoreCallingIdentity(token);
4142 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 }
4144
4145 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004146 public boolean isCapable(int subId, int capability, int regTech) {
4147 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004148 final long token = Binder.clearCallingIdentity();
4149 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004150 int slotId = getSlotIndexOrException(subId);
4151 verifyImsMmTelConfiguredOrThrow(slotId);
4152 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004153 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4155 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004157 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4158 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 } finally {
4160 Binder.restoreCallingIdentity(token);
4161 }
4162 }
4163
4164 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004165 public boolean isAvailable(int subId, int capability, int regTech) {
4166 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 final long token = Binder.clearCallingIdentity();
4168 try {
4169 Phone phone = getPhone(subId);
4170 if (phone == null) return false;
4171 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004172 } catch (com.android.ims.ImsException e) {
4173 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4174 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 } finally {
4176 Binder.restoreCallingIdentity(token);
4177 }
4178 }
4179
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004180 /**
4181 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4182 * subscription.
4183 * @param subId The subscription to use to check the configuration.
4184 * @param callback The callback that will be used to send the result.
4185 * @param capability The MmTelFeature capability that will be used to send the result.
4186 * @param transportType The transport type of the MmTelFeature capability.
4187 */
4188 @Override
4189 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4190 int transportType) {
4191 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4192 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4193 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4194 "IMS not available on device.");
4195 }
4196 final long token = Binder.clearCallingIdentity();
4197 try {
4198 int slotId = getSlotIndex(subId);
4199 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4200 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4201 + subId + "'");
4202 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4203 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004204 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004205 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4206 transportType, aBoolean -> {
4207 try {
4208 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4209 } catch (RemoteException e) {
4210 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4211 + "running. Ignore");
4212 }
4213 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004214 } catch (ImsException e) {
4215 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004216 } finally {
4217 Binder.restoreCallingIdentity(token);
4218 }
4219 }
4220
shilu366312e2019-12-17 09:28:10 -08004221 /**
4222 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4223 * @param subId The subscription to use to check the configuration.
4224 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 @Override
4226 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004227 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004228 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004229
Brad Ebinger35c841c2018-10-01 10:40:55 -07004230 final long token = Binder.clearCallingIdentity();
4231 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004232 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004233 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004234 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004235 } catch (ImsException e) {
4236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 } finally {
4238 Binder.restoreCallingIdentity(token);
4239 }
4240 }
4241
4242 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004243 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004245 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004246 final long identity = Binder.clearCallingIdentity();
4247 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004248 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004249 // This setting doesn't require an active ImsService connection, so do not verify. The
4250 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004251 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004252 } catch (ImsException e) {
4253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
4257 }
4258
shilu366312e2019-12-17 09:28:10 -08004259 /**
4260 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4261 * @param subId The subscription to use to check the configuration.
4262 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004263 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004264 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004265 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004266 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 final long identity = Binder.clearCallingIdentity();
4268 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004269 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004270 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004271 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004272 } catch (ImsException e) {
4273 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 } finally {
4275 Binder.restoreCallingIdentity(identity);
4276 }
4277 }
4278
4279 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004280 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004282 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 final long identity = Binder.clearCallingIdentity();
4284 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004286 // This setting doesn't require an active ImsService connection, so do not verify. The
4287 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
4294 }
4295
shilu366312e2019-12-17 09:28:10 -08004296 /**
4297 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4298 * @param subId The subscription to use to check the configuration.
4299 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 @Override
4301 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004302 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004303 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 final long identity = Binder.clearCallingIdentity();
4305 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004306 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004307 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004308 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004309 } catch (ImsException e) {
4310 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
4314 }
4315
4316 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004317 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004319 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 final long identity = Binder.clearCallingIdentity();
4321 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004323 // This setting doesn't require an active ImsService connection, so do not verify. The
4324 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004326 } catch (ImsException e) {
4327 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
shilu366312e2019-12-17 09:28:10 -08004333 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004334 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4335 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4336 * @param subId The subscription to use to check the configuration.
4337 */
4338 @Override
4339 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004340 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004341 mApp, subId, "isCrossSimCallingEnabledByUser");
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004344 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004345 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004346 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004347 } catch (ImsException e) {
4348 throw new ServiceSpecificException(e.getCode());
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
4351 }
4352 }
4353
4354 /**
4355 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4356 * Requires MODIFY_PHONE_STATE permission.
4357 * @param subId The subscription to use to check the configuration.
4358 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4359 * false otherwise
4360 */
4361 @Override
4362 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4364 "setCrossSimCallingEnabled");
4365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004367 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004368 // This setting doesn't require an active ImsService connection, so do not verify. The
4369 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004371 } catch (ImsException e) {
4372 throw new ServiceSpecificException(e.getCode());
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
4376 }
4377
4378 /**
shilu366312e2019-12-17 09:28:10 -08004379 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4380 * @param subId The subscription to use to check the configuration.
4381 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004383
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004385 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004386 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 final long identity = Binder.clearCallingIdentity();
4388 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004389 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004390 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004391 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004392 } catch (ImsException e) {
4393 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
4397 }
4398
4399 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004400 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004402 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004403 final long identity = Binder.clearCallingIdentity();
4404 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004405 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004406 // This setting doesn't require an active ImsService connection, so do not verify. The
4407 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004408 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004409 } catch (ImsException e) {
4410 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
4414 }
4415
4416 @Override
4417 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4419 "setVoWiFiNonPersistent");
4420 final long identity = Binder.clearCallingIdentity();
4421 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004422 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004423 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004424 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004425 } catch (ImsException e) {
4426 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
shilu366312e2019-12-17 09:28:10 -08004432 /**
4433 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4434 * @param subId The subscription to use to check the configuration.
4435 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 @Override
4437 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004438 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004439 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 final long identity = Binder.clearCallingIdentity();
4441 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004443 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004445 } catch (ImsException e) {
4446 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
4450 }
4451
4452 @Override
4453 public void setVoWiFiModeSetting(int subId, int mode) {
4454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4455 "setVoWiFiModeSetting");
4456 final long identity = Binder.clearCallingIdentity();
4457 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004459 // This setting doesn't require an active ImsService connection, so do not verify. The
4460 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public int getVoWiFiRoamingModeSetting(int subId) {
4471 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4472 final long identity = Binder.clearCallingIdentity();
4473 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004475 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004476 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004477 } catch (ImsException e) {
4478 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
4482 }
4483
4484 @Override
4485 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4487 "setVoWiFiRoamingModeSetting");
4488 final long identity = Binder.clearCallingIdentity();
4489 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004490 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004491 // This setting doesn't require an active ImsService connection, so do not verify. The
4492 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004494 } catch (ImsException e) {
4495 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
4499 }
4500
4501 @Override
4502 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4504 "setRttCapabilityEnabled");
4505 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. The
4509 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004511 } catch (ImsException e) {
4512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
shilu366312e2019-12-17 09:28:10 -08004518 /**
4519 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4520 * @param subId The subscription to use to check the configuration.
4521 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004522 @Override
4523 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004524 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004525 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004528 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004529 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004530 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004531 } catch (ImsException e) {
4532 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004538 @Override
4539 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4540 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004541
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004544 if (!isImsAvailableOnDevice()) {
4545 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4546 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004547 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004548 int slotId = getSlotIndexOrException(subId);
4549 verifyImsMmTelConfiguredOrThrow(slotId);
4550 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004551 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004552 } catch (ImsException e) {
4553 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
4557 }
4558
4559 @Override
4560 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4561 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004562
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004563 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004564 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4565 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4566 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004567 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004568 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004569 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004570 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004571 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4572 + "is inactive, ignoring unregister.");
4573 // If the subscription is no longer active, just return, since the callback will already
4574 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
4578 }
4579
joonhunshin2c3e4232021-11-28 07:32:01 +00004580 @Override
4581 public void registerFeatureProvisioningChangedCallback(int subId,
4582 IFeatureProvisioningCallback callback) {
4583 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4584 mApp, subId, "registerFeatureProvisioningChangedCallback");
4585
4586 final long identity = Binder.clearCallingIdentity();
4587 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4588 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4589 }
4590
4591 ImsProvisioningController.getInstance()
4592 .addFeatureProvisioningChangedCallback(subId, callback);
4593
4594 Binder.restoreCallingIdentity(identity);
4595 }
4596
4597 @Override
4598 public void unregisterFeatureProvisioningChangedCallback(int subId,
4599 IFeatureProvisioningCallback callback) {
4600 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4601 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4602
4603 final long identity = Binder.clearCallingIdentity();
4604 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4605 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4606 }
4607
4608 ImsProvisioningController.getInstance()
4609 .removeFeatureProvisioningChangedCallback(subId, callback);
4610
4611 Binder.restoreCallingIdentity(identity);
4612 }
allenwtsu99c623b2020-01-03 18:24:23 +08004613
4614 private void checkModifyPhoneStatePermission(int subId, String message) {
4615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4616 message);
4617 }
4618
4619 private boolean isImsProvisioningRequired(int subId, int capability,
4620 boolean isMmtelCapability) {
4621 Phone phone = getPhone(subId);
4622 if (phone == null) {
4623 loge("phone instance null for subid " + subId);
4624 return false;
4625 }
4626 if (isMmtelCapability) {
4627 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4628 return false;
4629 }
4630 } else {
4631 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4632 return false;
4633 }
4634 }
4635 return true;
4636 }
4637
4638 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004639 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004640 boolean isProvisioned) {
4641 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4642
4643 final long identity = Binder.clearCallingIdentity();
4644 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004645 ImsProvisioningController.getInstance()
4646 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4647 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
allenwtsu99c623b2020-01-03 18:24:23 +08004651 }
4652
4653
4654 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004655 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4656 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4657 mApp, subId, "getRcsProvisioningStatusForCapability");
4658
allenwtsu99c623b2020-01-03 18:24:23 +08004659 final long identity = Binder.clearCallingIdentity();
4660 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004661 return ImsProvisioningController.getInstance()
4662 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
4666 }
4667
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004668 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004669 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4670 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004671 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004672
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004673 final long identity = Binder.clearCallingIdentity();
4674 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004675 ImsProvisioningController.getInstance()
4676 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004677 } finally {
4678 Binder.restoreCallingIdentity(identity);
4679 }
4680 }
4681
4682 @Override
4683 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004684 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4685 mApp, subId, "getProvisioningStatusForCapability");
4686
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004687 final long identity = Binder.clearCallingIdentity();
4688 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004689 return ImsProvisioningController.getInstance()
4690 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004691
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
4695 }
4696
4697 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004698 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4699 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4700 mApp, subId, "isProvisioningRequiredForCapability");
4701
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
4704 return ImsProvisioningController.getInstance()
4705 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004709 }
4710
4711 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004712 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4713 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4714 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004715
joonhunshin2c3e4232021-11-28 07:32:01 +00004716 final long identity = Binder.clearCallingIdentity();
4717 try {
4718 return ImsProvisioningController.getInstance()
4719 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004723 }
4724
4725 private static String getMmTelProvisioningKey(int subId, int tech) {
4726 // resulting key is provision_ims_mmtel_{subId}_{tech}
4727 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4728 }
4729
4730 /**
4731 * Query CarrierConfig to see if the specified capability requires provisioning for the
4732 * carrier associated with the subscription id.
4733 */
4734 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4735 int capability) {
4736 CarrierConfigManager configManager = new CarrierConfigManager(context);
4737 PersistableBundle c = configManager.getConfigForSubId(subId);
4738 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004739 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004740 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4741 false);
4742 boolean requireVoiceVtProvisioning = c.getBoolean(
4743 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4744
4745 // First check to make sure that the capability requires provisioning.
4746 switch (capability) {
4747 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4748 // intentional fallthrough
4749 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4750 if (requireVoiceVtProvisioning) {
4751 // Voice and Video requires provisioning
4752 return true;
4753 }
4754 break;
4755 }
4756 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4757 if (requireUtProvisioning) {
4758 // UT requires provisioning
4759 return true;
4760 }
4761 break;
4762 }
4763 }
4764 return false;
4765 }
4766
allenwtsu99c623b2020-01-03 18:24:23 +08004767 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4768 int capability) {
4769 CarrierConfigManager configManager = new CarrierConfigManager(context);
4770 PersistableBundle c = configManager.getConfigForSubId(subId);
4771
4772 boolean requireRcsProvisioning = c.getBoolean(
4773 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4774
4775 // First check to make sure that the capability requires provisioning.
4776 switch (capability) {
4777 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4778 // intentional fallthrough
4779 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4780 if (requireRcsProvisioning) {
4781 // OPTION or PRESENCE requires provisioning
4782 return true;
4783 }
4784 break;
4785 }
4786 }
4787 return false;
4788 }
4789
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004790 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004791 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4793 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4794 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004795 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4796 mApp, subId, "getImsProvisioningInt");
4797
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004798 final long identity = Binder.clearCallingIdentity();
4799 try {
4800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004801 int slotId = getSlotIndex(subId);
4802 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4803 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4804 + subId + "' for key:" + key);
4805 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4806 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004807
4808 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4809 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4810 return retVal;
4811 }
4812
calvinpanb5a34062021-02-08 19:59:36 +08004813 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004814 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004815 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4816 + subId + "' for key:" + key);
4817 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004818 } finally {
4819 Binder.restoreCallingIdentity(identity);
4820 }
4821 }
4822
4823 @Override
4824 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004825 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4826 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4827 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004828 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4829 mApp, subId, "getImsProvisioningString");
4830
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004834 int slotId = getSlotIndex(subId);
4835 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4836 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4837 + subId + "' for key:" + key);
4838 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4839 }
calvinpanb5a34062021-02-08 19:59:36 +08004840 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004841 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004842 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4843 + subId + "' for key:" + key);
4844 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
4848 }
4849
4850 @Override
4851 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4853 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4854 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4856 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004857
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004858 final long identity = Binder.clearCallingIdentity();
4859 try {
4860 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004861 int slotId = getSlotIndex(subId);
4862 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4863 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4864 + subId + "' for key:" + key);
4865 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4866 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004867
4868 int retVal = ImsProvisioningController.getInstance()
4869 .setProvisioningValue(subId, key, value);
4870 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4871 return retVal;
4872 }
4873
calvinpanb5a34062021-02-08 19:59:36 +08004874 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4875 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004876 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004877 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004878 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
4882 }
4883
4884 @Override
4885 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004886 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4887 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4888 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4890 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004894 int slotId = getSlotIndex(subId);
4895 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4896 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4897 + subId + "' for key:" + key);
4898 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4899 }
calvinpanb5a34062021-02-08 19:59:36 +08004900 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4901 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004903 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004905 } finally {
4906 Binder.restoreCallingIdentity(identity);
4907 }
4908 }
4909
Brad Ebinger919631e2021-06-02 17:46:35 -07004910 /**
4911 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4912 * for the given slot ID or no ImsResolver instance has been created.
4913 * @param slotId The slot ID that the IMS service is created for.
4914 * @throws ImsException If there is no ImsService configured for this slot.
4915 */
4916 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4917 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4918 ImsFeature.FEATURE_MMTEL)) {
4919 throw new ImsException("This subscription does not support MMTEL over IMS",
4920 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4921 }
4922 }
4923
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004924 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004925 int slotId = SubscriptionManager.getSlotIndex(subId);
4926 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004927 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4928 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004929 }
4930 return slotId;
4931 }
4932
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 private int getSlotIndex(int subId) {
4934 int slotId = SubscriptionManager.getSlotIndex(subId);
4935 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4936 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4937 }
4938 return slotId;
4939 }
4940
Wink Saville36469e72014-06-11 15:17:00 -07004941 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004942 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004943 */
4944 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004945 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4946 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004947 try {
4948 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4949 } catch (SecurityException se) {
4950 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4951 throw new SecurityException("Package " + callingPackage + " does not belong to "
4952 + Binder.getCallingUid());
4953 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004954 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004955 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004956 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004957 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004958 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004959 mApp, subId, callingPackage, callingFeatureId,
4960 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004961 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4962 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 final Phone phone = getPhone(subId);
4967 if (phone != null) {
4968 return phone.getServiceState().getDataNetworkType();
4969 } else {
4970 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4971 }
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004975 }
4976
4977 /**
4978 * Returns the data network type
4979 */
4980 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004981 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004982 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4983 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004984 }
4985
4986 /**
4987 * Returns the data network type for a subId
4988 */
4989 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004990 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4991 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004992 String functionName = "getDataNetworkTypeForSubscriber";
4993 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4994 mApp, functionName)) {
4995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4996 mApp, subId, callingPackage, callingFeatureId, functionName)) {
4997 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4998 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004999 }
5000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 final long identity = Binder.clearCallingIdentity();
5002 try {
5003 final Phone phone = getPhone(subId);
5004 if (phone != null) {
5005 return phone.getServiceState().getDataNetworkType();
5006 } else {
5007 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5008 }
5009 } finally {
5010 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005012 }
5013
5014 /**
Wink Saville36469e72014-06-11 15:17:00 -07005015 * Returns the Voice network type for a subId
5016 */
5017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005018 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5019 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005020 String functionName = "getVoiceNetworkTypeForSubscriber";
5021 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5022 mApp, functionName)) {
5023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5024 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5025 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5026 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005027 }
5028
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().getVoiceNetworkType();
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 * @return true if a ICC card is present
5044 */
5045 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005046 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005047 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5048 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005049 }
5050
5051 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005052 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005053 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005054 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005055 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 final Phone phone = PhoneFactory.getPhone(slotIndex);
5059 if (phone != null) {
5060 return phone.getIccCard().hasIccCard();
5061 } else {
5062 return false;
5063 }
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005067 }
5068
5069 /**
5070 * Return if the current radio is LTE on CDMA. This
5071 * is a tri-state return value as for a period of time
5072 * the mode may be unknown.
5073 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005074 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005075 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005076 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005077 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005079 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5080 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5081 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005082 }
5083
Sanket Padawe356d7632015-06-22 14:03:32 -07005084 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005085 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5086 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005087 try {
5088 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5089 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005090 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5091 }
5092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 final Phone phone = getPhone(subId);
5096 if (phone == null) {
5097 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5098 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005099 return TelephonyProperties.lte_on_cdma_device()
5100 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 }
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005104 }
Wink Saville36469e72014-06-11 15:17:00 -07005105 }
5106
Wink Saville36469e72014-06-11 15:17:00 -07005107 /**
5108 * {@hide}
5109 * Returns Default subId, 0 in the case of single standby.
5110 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005111 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005112 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005113 }
5114
Shishir Agrawala9f32182016-04-12 12:00:16 -07005115 private int getSlotForDefaultSubscription() {
5116 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5117 }
5118
Wink Savilleb564aae2014-10-23 10:18:09 -07005119 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005120 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005121 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005122
Pengquan Menge92a50d2018-09-21 15:54:48 -07005123 private boolean isActiveSubscription(int subId) {
5124 return mSubscriptionController.isActiveSubId(subId);
5125 }
5126
Ihab Awadf2177b72013-11-25 13:33:23 -08005127 /**
5128 * @see android.telephony.TelephonyManager.WifiCallingChoices
5129 */
5130 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 final long identity = Binder.clearCallingIdentity();
5132 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005133 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5135 getWhenToMakeWifiCallsDefaultPreference());
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005139 }
5140
5141 /**
5142 * @see android.telephony.TelephonyManager.WifiCallingChoices
5143 */
5144 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005148 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005153 }
5154
Sailesh Nepald1e68152013-12-12 19:08:02 -08005155 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005156 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005157 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005158 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005159
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005160 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5161 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5162 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005163 if (phoneId == -1) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005164 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5165 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005166 }
5167 return PhoneFactory.getPhone(phoneId);
5168 }
5169
Shishir Agrawal566b7612013-10-28 14:41:00 -07005170 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005171 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5172 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5174 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005176 if (DBG) {
5177 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5178 }
5179 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5180 p2);
5181 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005182
Jordan Liu4c733742019-02-28 12:03:40 -08005183
5184 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005185 public IccOpenLogicalChannelResponse iccOpenLogicalChannelByPort(
5186 int slotIndex, int portIndex, String callingPackage, String aid, int p2) {
Jordan Liu4c733742019-02-28 12:03:40 -08005187 enforceModifyPermission();
5188 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5189 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005190 log("iccOpenLogicalChannelByPort: slot=" + slotIndex + " port=" + portIndex + " aid="
5191 + aid + " p2=" + p2);
Jordan Liu4c733742019-02-28 12:03:40 -08005192 }
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005193 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotPortIndexOrThrowException(
5194 slotIndex, portIndex), callingPackage, aid, p2);
Jordan Liu4c733742019-02-28 12:03:40 -08005195 }
5196
5197 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5198 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 if (TextUtils.equals(ISDR_AID, aid)) {
5202 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005203 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5204 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 if (bestComponent == null
5206 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5207 loge("The calling package is not allowed to access ISD-R.");
5208 throw new SecurityException(
5209 "The calling package is not allowed to access ISD-R.");
5210 }
Derek Tan740e1672017-06-27 14:56:27 -07005211 }
Derek Tan740e1672017-06-27 14:56:27 -07005212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005214 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5215 null /* workSource */);
5216 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 return response;
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005221 }
5222
5223 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005224 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5226 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005227 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5228 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5229 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005230
Jordan Liu4c733742019-02-28 12:03:40 -08005231 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005232 public boolean iccCloseLogicalChannelByPort(int slotIndex, int portIndex, int channel) {
Jordan Liu4c733742019-02-28 12:03:40 -08005233 enforceModifyPermission();
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005234 if (DBG) log("iccCloseLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5235 + portIndex + " chnl=" + channel);
5236 return iccCloseLogicalChannelWithPermission(
5237 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel);
Jordan Liu4c733742019-02-28 12:03:40 -08005238 }
5239
5240 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 if (channel < 0) {
5244 return false;
5245 }
Jordan Liu4c733742019-02-28 12:03:40 -08005246 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5247 null /* workSource */);
5248 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 return success;
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005252 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005253 }
5254
5255 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005256 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005257 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5259 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005260 if (DBG) {
5261 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5262 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5263 + p3 + " data=" + data);
5264 }
5265 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5266 command, p1, p2, p3, data);
5267 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005268
Jordan Liu4c733742019-02-28 12:03:40 -08005269 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005270 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5271 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005272 enforceModifyPermission();
5273 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005274 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5275 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5276 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005277 }
5278 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005279 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5280 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005281 }
5282
5283 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5284 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
5286 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005287 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 return "";
5289 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005292 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5293 null /* workSource */);
5294 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 // Append the returned status code to the end of the response payload.
5297 String s = Integer.toHexString(
5298 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5299 if (response.payload != null) {
5300 s = IccUtils.bytesToHexString(response.payload) + s;
5301 }
5302 return s;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005305 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005306 }
Jake Hambye994d462014-02-03 13:10:13 -08005307
Evan Charltonc66da362014-05-16 14:06:40 -07005308 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005309 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5310 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5312 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005314 if (DBG) {
5315 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5316 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5317 }
5318 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5319 cla, command, p1, p2, p3, data);
5320 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005321
Jordan Liu4c733742019-02-28 12:03:40 -08005322 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005323 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5324 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005325 enforceModifyPermission();
5326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5327 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005328 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5329 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5330 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005331 }
5332
5333 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005334 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5335 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005336 }
5337
5338 // open APDU basic channel assuming the caller has sufficient permissions
5339 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5340 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5344 && TextUtils.equals(ISDR_AID, data)) {
5345 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005346 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5347 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 if (bestComponent == null
5349 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5350 loge("The calling package is not allowed to select ISD-R.");
5351 throw new SecurityException(
5352 "The calling package is not allowed to select ISD-R.");
5353 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005354 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005357 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5358 null /* workSource */);
5359 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 // Append the returned status code to the end of the response payload.
5362 String s = Integer.toHexString(
5363 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5364 if (response.payload != null) {
5365 s = IccUtils.bytesToHexString(response.payload) + s;
5366 }
5367 return s;
5368 } finally {
5369 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005370 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005371 }
5372
5373 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005374 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005375 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5377 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 if (DBG) {
5382 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5383 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5384 }
5385
5386 IccIoResult response =
5387 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5388 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5389 subId);
5390
5391 if (DBG) {
5392 log("Exchange SIM_IO [R]" + response);
5393 }
5394
5395 byte[] result = null;
5396 int length = 2;
5397 if (response.payload != null) {
5398 length = 2 + response.payload.length;
5399 result = new byte[length];
5400 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5401 } else {
5402 result = new byte[length];
5403 }
5404
5405 result[length - 1] = (byte) response.sw2;
5406 result[length - 2] = (byte) response.sw1;
5407 return result;
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005410 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005411 }
5412
Nathan Haroldb3014052017-01-25 15:57:32 -08005413 /**
5414 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5415 * on a particular subscription
5416 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005417 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5418 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005420 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005421 return null;
5422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423
5424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 if (appType != TelephonyManager.APPTYPE_USIM
5427 && appType != TelephonyManager.APPTYPE_SIM) {
5428 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5429 return null;
5430 }
5431 Object response = sendRequest(
5432 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5433 if (response instanceof String[]) {
5434 return (String[]) response;
5435 }
yincheng zhao2737e882019-09-06 17:06:54 -07005436 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005438 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 } finally {
5440 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005441 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005442 }
5443
yincheng zhao2737e882019-09-06 17:06:54 -07005444 /**
5445 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5446 * subscription.
5447 *
5448 * @param subId the id of the subscription.
5449 * @param appType the uicc app type, must be USIM or SIM.
5450 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5451 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005452 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005453 * @return number of fplmns that is successfully written to the SIM.
5454 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005455 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5456 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5458 mApp, subId, "setForbiddenPlmns");
5459
yincheng zhao2737e882019-09-06 17:06:54 -07005460 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5461 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5462 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5463 }
5464 if (fplmns == null) {
5465 throw new IllegalArgumentException("Fplmn List provided is null");
5466 }
5467 for (String fplmn : fplmns) {
5468 if (!CellIdentity.isValidPlmn(fplmn)) {
5469 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5470 }
5471 }
5472 final long identity = Binder.clearCallingIdentity();
5473 try {
5474 Object response = sendRequest(
5475 CMD_SET_FORBIDDEN_PLMNS,
5476 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5477 subId);
5478 return (int) response;
5479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
5482 }
5483
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005484 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005485 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5487 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 final long identity = Binder.clearCallingIdentity();
5490 try {
5491 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5492 if (response.payload == null) {
5493 return "";
5494 }
Evan Charltonc66da362014-05-16 14:06:40 -07005495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 // Append the returned status code to the end of the response payload.
5497 String s = Integer.toHexString(
5498 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5499 s = IccUtils.bytesToHexString(response.payload) + s;
5500 return s;
5501 } finally {
5502 Binder.restoreCallingIdentity(identity);
5503 }
Evan Charltonc66da362014-05-16 14:06:40 -07005504 }
5505
Jake Hambye994d462014-02-03 13:10:13 -08005506 /**
5507 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5508 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5509 *
5510 * @param itemID the ID of the item to read
5511 * @return the NV item as a String, or null on error.
5512 */
5513 @Override
5514 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005515 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5517 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518
5519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005522 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5524 return value;
5525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Jake Hambye994d462014-02-03 13:10:13 -08005528 }
5529
5530 /**
5531 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5532 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5533 *
5534 * @param itemID the ID of the item to read
5535 * @param itemValue the value to write, as a String
5536 * @return true on success; false on any failure
5537 */
5538 @Override
5539 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5542 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543
5544 final long identity = Binder.clearCallingIdentity();
5545 try {
5546 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5547 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005548 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5550 return success;
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
Jake Hambye994d462014-02-03 13:10:13 -08005554 }
5555
5556 /**
5557 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5558 * Used for device configuration by some CDMA operators.
5559 *
5560 * @param preferredRoamingList byte array containing the new PRL
5561 * @return true on success; false on any failure
5562 */
5563 @Override
5564 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5566 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5571 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5572 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5573 return success;
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
Jake Hambye994d462014-02-03 13:10:13 -08005577 }
5578
5579 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005580 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005581 * Used for device configuration by some CDMA operators.
5582 *
chen xu6dac5ab2018-10-26 17:39:23 -07005583 * @param slotIndex - device slot.
5584 *
Jake Hambye994d462014-02-03 13:10:13 -08005585 * @return true on success; false on any failure
5586 */
5587 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005588 public boolean resetModemConfig(int slotIndex) {
5589 Phone phone = PhoneFactory.getPhone(slotIndex);
5590 if (phone != null) {
5591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5592 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593
chen xu6dac5ab2018-10-26 17:39:23 -07005594 final long identity = Binder.clearCallingIdentity();
5595 try {
5596 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5597 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5598 return success;
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 }
chen xu6dac5ab2018-10-26 17:39:23 -07005603 return false;
5604 }
5605
5606 /**
5607 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5608 *
5609 * @param slotIndex - device slot.
5610 *
5611 * @return true on success; false on any failure
5612 */
5613 @Override
5614 public boolean rebootModem(int slotIndex) {
5615 Phone phone = PhoneFactory.getPhone(slotIndex);
5616 if (phone != null) {
5617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5618 mApp, phone.getSubId(), "rebootModem");
5619
5620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5623 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5624 return success;
5625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
5628 }
5629 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005630 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005631
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005632 public String[] getPcscfAddress(String apnType, String callingPackage,
5633 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005634 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5636 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005637 return new String[0];
5638 }
5639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 final long identity = Binder.clearCallingIdentity();
5641 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005642 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Wink Saville36469e72014-06-11 15:17:00 -07005646 }
5647
Brad Ebinger51f743a2017-01-23 13:50:20 -08005648 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005649 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5650 * {@link #disableIms(int)}.
5651 * @param slotIndex device slot.
5652 */
5653 public void resetIms(int slotIndex) {
5654 enforceModifyPermission();
5655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
5658 if (mImsResolver == null) {
5659 // may happen if the does not support IMS.
5660 return;
5661 }
5662 mImsResolver.disableIms(slotIndex);
5663 mImsResolver.enableIms(slotIndex);
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
5667 }
5668
5669 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005670 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5671 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005672 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005673 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005678 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005679 // may happen if the device does not support IMS.
5680 return;
5681 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005682 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005686 }
5687
5688 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005689 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5690 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005691 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005692 public void disableIms(int slotId) {
5693 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005697 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005698 // may happen if the device does not support IMS.
5699 return;
5700 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005701 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005705 }
5706
5707 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005708 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5709 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005710 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005711 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005712 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714
5715 final long identity = Binder.clearCallingIdentity();
5716 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005717 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005718 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5719 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005720 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005721 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005725 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005726 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005727 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5728 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005729 @Override
5730 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005731 enforceModifyPermission();
5732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005736 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
5740 }
5741
5742 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005743 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005744 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005745 */
5746 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5747 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005751 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005752 // may happen if the device does not support IMS.
5753 return null;
5754 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005755 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005759 }
5760
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 /**
5762 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005764 */
5765 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005771 // may happen if the device does not support IMS.
5772 return null;
5773 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005774 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005778 }
5779
Brad Ebinger884c07b2018-02-15 16:17:40 -08005780 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005781 * Sets the ImsService Package Name that Telephony will bind to.
5782 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005783 * @param slotIndex the slot ID that the ImsService should bind for.
5784 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005785 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 * @param featureTypes An integer array of feature types associated with a packageName.
5787 * @param packageName The name of the package that the current configuration will be replaced
5788 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005789 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005790 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005791 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5792 int[] featureTypes, String packageName) {
5793 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5796 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005797 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 final long identity = Binder.clearCallingIdentity();
5800 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005801 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005802 // may happen if the device does not support IMS.
5803 return false;
5804 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005805 Map<Integer, String> featureConfig = new HashMap<>();
5806 for (int featureType : featureTypes) {
5807 featureConfig.put(featureType, packageName);
5808 }
5809 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5810 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 } finally {
5812 Binder.restoreCallingIdentity(identity);
5813 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005814 }
5815
5816 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005817 * Clears any carrier ImsService overrides for the slot index specified that were previously
5818 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5819 *
5820 * This should only be used for testing.
5821 *
5822 * @param slotIndex the slot ID that the ImsService should bind for.
5823 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5824 */
5825 @Override
5826 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5827 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5829 "clearCarrierImsServiceOverride");
5830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5831 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5832 "clearCarrierImsServiceOverride");
5833
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
5836 if (mImsResolver == null) {
5837 // may happen if the device does not support IMS.
5838 return false;
5839 }
5840 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
5844 }
5845
5846 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005847 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005848 *
5849 * @param slotId The slot that the ImsService is associated with.
5850 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5851 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005853 * @return the package name of the ImsService configuration.
5854 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5856 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005857 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005859 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005860 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5861 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 final long identity = Binder.clearCallingIdentity();
5864 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005865 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005866 // may happen if the device does not support IMS.
5867 return "";
5868 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005869 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5871 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005875 }
5876
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005877 /**
5878 * Get the MmTelFeature state associated with the requested subscription id.
5879 * @param subId The subscription that the MmTelFeature is associated with.
5880 * @param callback A callback with an integer containing the
5881 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5882 */
5883 @Override
5884 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5885 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5886 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5887 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5888 "IMS not available on device.");
5889 }
5890 final long token = Binder.clearCallingIdentity();
5891 try {
5892 int slotId = getSlotIndex(subId);
5893 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5894 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5895 + subId + "'");
5896 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5897 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005898 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005899 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5900 try {
5901 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5902 } catch (RemoteException e) {
5903 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5904 + "Ignore");
5905 }
5906 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005907 } catch (ImsException e) {
5908 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005909 } finally {
5910 Binder.restoreCallingIdentity(token);
5911 }
5912 }
5913
Daniel Brightbb5840b2021-01-12 15:48:18 -08005914 /**
5915 * Sets the ims registration state on all valid {@link Phone}s.
5916 */
5917 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005918 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919
5920 final long identity = Binder.clearCallingIdentity();
5921 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005922 // NOTE: Before S, this method only set the default phone.
5923 for (final Phone phone : PhoneFactory.getPhones()) {
5924 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5925 phone.setImsRegistrationState(registered);
5926 }
5927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 } finally {
5929 Binder.restoreCallingIdentity(identity);
5930 }
Wink Saville36469e72014-06-11 15:17:00 -07005931 }
5932
5933 /**
Stuart Scott54788802015-03-30 13:18:01 -07005934 * Set the network selection mode to automatic.
5935 *
5936 */
5937 @Override
5938 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5940 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941
5942 final long identity = Binder.clearCallingIdentity();
5943 try {
shilufc958392020-01-20 11:36:01 -08005944 if (!isActiveSubscription(subId)) {
5945 return;
5946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005948 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5949 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
Stuart Scott54788802015-03-30 13:18:01 -07005953 }
5954
Jack Yud10cdd42020-09-28 20:28:01 -07005955 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005956 * Ask the radio to connect to the input network and change selection mode to manual.
5957 *
5958 * @param subId the id of the subscription.
5959 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5960 * the operator to attach to.
5961 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5962 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5963 * normal network selection next time.
5964 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005965 */
5966 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005967 public boolean setNetworkSelectionModeManual(
5968 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5970 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005971
5972 if (!isActiveSubscription(subId)) {
5973 return false;
5974 }
5975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 final long identity = Binder.clearCallingIdentity();
5977 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005978 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005980 if (DBG) {
5981 log("setNetworkSelectionModeManual: subId: " + subId
5982 + " operator: " + operatorInfo);
5983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
5987 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005988 }
shilu84f6e8b2019-12-19 13:58:01 -08005989 /**
5990 * Get the manual network selection
5991 *
5992 * @param subId the id of the subscription.
5993 *
5994 * @return the previously saved user selected PLMN
5995 */
5996 @Override
5997 public String getManualNetworkSelectionPlmn(int subId) {
5998 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005999 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006000 mApp, subId, "getManualNetworkSelectionPlmn");
6001
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
6004 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006005 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006006 }
6007
6008 final Phone phone = getPhone(subId);
6009 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006010 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006011 }
6012 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6013 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6014 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
6018 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006019
6020 /**
6021 * Scans for available networks.
6022 */
6023 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006024 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6025 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6027 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006028 LocationAccessPolicy.LocationPermissionResult locationResult =
6029 LocationAccessPolicy.checkLocationPermission(mApp,
6030 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6031 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006032 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006033 .setCallingPid(Binder.getCallingPid())
6034 .setCallingUid(Binder.getCallingUid())
6035 .setMethod("getCellNetworkScanResults")
6036 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006037 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6038 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006039 .build());
6040 switch (locationResult) {
6041 case DENIED_HARD:
6042 throw new SecurityException("Not allowed to access scan results -- location");
6043 case DENIED_SOFT:
6044 return null;
6045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046
Pengquan Menga1bb6272018-09-06 09:59:22 -07006047 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 try {
6049 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006050 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 } finally {
6053 Binder.restoreCallingIdentity(identity);
6054 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006055 }
6056
6057 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006058 * Get the call forwarding info, given the call forwarding reason.
6059 */
6060 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006061 public void getCallForwarding(int subId, int callForwardingReason,
6062 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006063 enforceReadPrivilegedPermission("getCallForwarding");
6064 long identity = Binder.clearCallingIdentity();
6065 try {
6066 if (DBG) {
6067 log("getCallForwarding: subId " + subId
6068 + " callForwardingReason" + callForwardingReason);
6069 }
Hall Liu27d24262020-09-18 19:04:59 -07006070
6071 Phone phone = getPhone(subId);
6072 if (phone == null) {
6073 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006074 callback.onError(
6075 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006076 } catch (RemoteException e) {
6077 // ignore
6078 }
6079 return;
6080 }
6081
6082 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6083 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6084 @Override
6085 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6086 try {
6087 callback.onCallForwardingInfoAvailable(info);
6088 } catch (RemoteException e) {
6089 // ignore
6090 }
6091 }
6092
6093 @Override
6094 public void onError(int error) {
6095 try {
6096 callback.onError(error);
6097 } catch (RemoteException e) {
6098 // ignore
6099 }
6100 }
6101 });
6102 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006103 } finally {
6104 Binder.restoreCallingIdentity(identity);
6105 }
6106 }
6107
6108 /**
6109 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6110 * reason, the number to forward, and the timeout before the forwarding is attempted.
6111 */
6112 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006113 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6114 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006115 enforceModifyPermission();
6116 long identity = Binder.clearCallingIdentity();
6117 try {
6118 if (DBG) {
6119 log("setCallForwarding: subId " + subId
6120 + " callForwardingInfo" + callForwardingInfo);
6121 }
Hall Liu27d24262020-09-18 19:04:59 -07006122
6123 Phone phone = getPhone(subId);
6124 if (phone == null) {
6125 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006126 callback.accept(
6127 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006128 } catch (RemoteException e) {
6129 // ignore
6130 }
6131 return;
6132 }
6133
6134 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6135 FunctionalUtils.ignoreRemoteException(callback::accept));
6136
6137 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006138 } finally {
6139 Binder.restoreCallingIdentity(identity);
6140 }
6141 }
6142
6143 /**
Hall Liu27d24262020-09-18 19:04:59 -07006144 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006145 */
6146 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006147 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006148 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006149 long identity = Binder.clearCallingIdentity();
6150 try {
Hall Liu27d24262020-09-18 19:04:59 -07006151 Phone phone = getPhone(subId);
6152 if (phone == null) {
6153 try {
6154 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6155 } catch (RemoteException e) {
6156 // ignore
6157 }
6158 return;
6159 }
SongFerngWang0e767992021-03-31 22:08:45 +08006160 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6161 PersistableBundle c = configManager.getConfigForSubId(subId);
6162 boolean requireUssd = c.getBoolean(
6163 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006164
Shuo Qian4a594052020-01-23 11:59:30 -08006165 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006166 if (requireUssd) {
6167 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6168 getSubscriptionCarrierId(subId));
6169 String newUssdCommand = "";
6170 try {
6171 newUssdCommand = carrierXmlParser.getFeature(
6172 CarrierXmlParser.FEATURE_CALL_WAITING)
6173 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6174 } catch (NullPointerException e) {
6175 loge("Failed to generate USSD number" + e);
6176 }
6177 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6178 mMainThreadHandler, callback, carrierXmlParser,
6179 CarrierXmlParser.SsEntry.SSAction.QUERY);
6180 final String ussdCommand = newUssdCommand;
6181 Executors.newSingleThreadExecutor().execute(() -> {
6182 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6183 });
6184 } else {
6185 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6186 callback::accept);
6187 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6188 }
Shuo Qian4a594052020-01-23 11:59:30 -08006189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
6193
6194 /**
Hall Liu27d24262020-09-18 19:04:59 -07006195 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006196 */
6197 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006198 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006199 enforceModifyPermission();
6200 long identity = Binder.clearCallingIdentity();
6201 try {
Hall Liu27d24262020-09-18 19:04:59 -07006202 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6203
6204 Phone phone = getPhone(subId);
6205 if (phone == null) {
6206 try {
6207 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6208 } catch (RemoteException e) {
6209 // ignore
6210 }
6211 return;
6212 }
6213
SongFerngWang0e767992021-03-31 22:08:45 +08006214 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6215 PersistableBundle c = configManager.getConfigForSubId(subId);
6216 boolean requireUssd = c.getBoolean(
6217 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006218
SongFerngWang0e767992021-03-31 22:08:45 +08006219 if (DBG) log("getCallWaitingStatus: subId " + subId);
6220 if (requireUssd) {
6221 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6222 getSubscriptionCarrierId(subId));
6223 CarrierXmlParser.SsEntry.SSAction ssAction =
6224 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6225 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6226 String newUssdCommand = "";
6227 try {
6228 newUssdCommand = carrierXmlParser.getFeature(
6229 CarrierXmlParser.FEATURE_CALL_WAITING)
6230 .makeCommand(ssAction, null);
6231 } catch (NullPointerException e) {
6232 loge("Failed to generate USSD number" + e);
6233 }
6234 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6235 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6236 final String ussdCommand = newUssdCommand;
6237 Executors.newSingleThreadExecutor().execute(() -> {
6238 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6239 });
6240 } else {
6241 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6242 FunctionalUtils.ignoreRemoteException(callback::accept));
6243
6244 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6245 }
Shuo Qian4a594052020-01-23 11:59:30 -08006246 } finally {
6247 Binder.restoreCallingIdentity(identity);
6248 }
6249 }
6250
6251 /**
yinxub1bed742017-04-17 11:45:04 -07006252 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006253 *
yinxub1bed742017-04-17 11:45:04 -07006254 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006255 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6256 * location related information which will be sent if the caller already possess
6257 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006258 * @param request contains the radio access networks with bands/channels to scan
6259 * @param messenger callback messenger for scan results or errors
6260 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006261 * @return the id of the requested scan which can be used to stop the scan.
6262 */
6263 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006264 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6265 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006266 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6268 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006269 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006270 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6271 if (!renounceFineLocationAccess) {
6272 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6273 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6274 .setCallingPackage(callingPackage)
6275 .setCallingFeatureId(callingFeatureId)
6276 .setCallingPid(Binder.getCallingPid())
6277 .setCallingUid(Binder.getCallingUid())
6278 .setMethod("requestNetworkScan")
6279 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6280 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6281 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6282 .build());
6283 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006284 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006285 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6286 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006287 if (e != null) {
6288 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6289 throw e;
6290 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006291 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006292 return TelephonyScanManager.INVALID_SCAN_ID;
6293 }
6294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 }
Hall Liu912dfd32019-04-25 14:02:26 -07006296 int callingUid = Binder.getCallingUid();
6297 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006298 final long identity = Binder.clearCallingIdentity();
6299 try {
6300 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006301 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006302 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006303 } finally {
6304 Binder.restoreCallingIdentity(identity);
6305 }
yinxu504e1392017-04-12 16:03:22 -07006306 }
6307
Hall Liub2ac8ef2019-02-28 15:56:23 -08006308 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006309 NetworkScanRequest request, int subId, String callingPackage) {
6310 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006311 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6312 boolean hasNetworkScanPermission =
6313 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6314 == PERMISSION_GRANTED;
6315
6316 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6317 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6318 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006319 }
6320
6321 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6322 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006323 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6324 return new SecurityException("Specific channels must not be"
6325 + " scanned without location access.");
6326 }
6327 }
6328 }
6329
Hall Liub2ac8ef2019-02-28 15:56:23 -08006330 return null;
6331 }
6332
yinxu504e1392017-04-12 16:03:22 -07006333 /**
6334 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006335 *
6336 * @param subId id of the subscription
6337 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006338 */
6339 @Override
6340 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6342 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343
Hall Liu912dfd32019-04-25 14:02:26 -07006344 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 final long identity = Binder.clearCallingIdentity();
6346 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006347 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
yinxu504e1392017-04-12 16:03:22 -07006351 }
6352
6353 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006354 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006355 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006356 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006357 */
6358 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006359 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006360 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006361 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006362 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
6365 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006366 if (DBG) log("getAllowedNetworkTypesBitmask");
6367 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6368 int networkTypesBitmask = (result != null ? result[0] : -1);
6369 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6370 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006374 }
6375
6376 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006377 * Get the allowed network types for certain reason.
6378 *
6379 * @param subId the id of the subscription.
6380 * @param reason the reason the allowed network type change is taking place
6381 * @return the allowed network types.
6382 */
6383 @Override
6384 public long getAllowedNetworkTypesForReason(int subId,
6385 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006386 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006387 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
6394 }
6395
6396 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006397 * Enable/Disable E-UTRA-NR Dual Connectivity
6398 * @param subId subscription id of the sim card
6399 * @param nrDualConnectivityState expected NR dual connectivity state
6400 * This can be passed following states
6401 * <ol>
6402 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6403 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6404 * <li>Disable NR dual connectivity and force secondary cell to be released
6405 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6406 * </ol>
6407 * @return operation result.
6408 */
6409 @Override
6410 public int setNrDualConnectivityState(int subId,
6411 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6413 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006414 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006415 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6416 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6417 }
6418
Sooraj Sasindran37444802020-08-11 10:40:43 -07006419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6420 final long identity = Binder.clearCallingIdentity();
6421 try {
6422 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6423 nrDualConnectivityState, subId,
6424 workSource);
6425 if (DBG) log("enableNRDualConnectivity result: " + result);
6426 return result;
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
6432 /**
6433 * Is E-UTRA-NR Dual Connectivity enabled
6434 * @return true if dual connectivity is enabled else false
6435 */
6436 @Override
6437 public boolean isNrDualConnectivityEnabled(int subId) {
6438 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006439 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006440 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006441 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006442 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6443 return false;
6444 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6449 null, subId, workSource);
6450 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6451 return isEnabled;
6452 } finally {
6453 Binder.restoreCallingIdentity(identity);
6454 }
6455 }
6456
6457 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006458 * Set the allowed network types of the device and
6459 * provide the reason triggering the allowed network change.
6460 *
6461 * @param subId the id of the subscription.
6462 * @param reason the reason the allowed network type change is taking place
6463 * @param allowedNetworkTypes the allowed network types.
6464 * @return true on success; false on any failure.
6465 */
6466 @Override
6467 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006468 @TelephonyManager.AllowedNetworkTypesReason int reason,
6469 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6471 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006472 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006473 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6474 return false;
6475 }
6476 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6477 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006478 return false;
6479 }
6480
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006481 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6482 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6483
6484
6485 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6486 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6487 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006488 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006489
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006490 final long identity = Binder.clearCallingIdentity();
6491 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006492 Boolean success = (Boolean) sendRequest(
6493 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6494 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6495
6496 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6497 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006498 } finally {
6499 Binder.restoreCallingIdentity(identity);
6500 }
6501 }
6502
6503 /**
Miaoa84611c2019-03-15 09:21:10 +08006504 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006505 *
Miaoa84611c2019-03-15 09:21:10 +08006506 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006507 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006508 * @hide
6509 */
6510 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006511 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006512 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006514 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 try {
Miaoa84611c2019-03-15 09:21:10 +08006516 if (phone != null) {
6517 return phone.hasMatchedTetherApnSetting();
6518 } else {
6519 return false;
6520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521 } finally {
6522 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006523 }
Junda Liu475951f2014-11-07 16:45:03 -08006524 }
6525
6526 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006527 * Get the user enabled state of Mobile Data.
6528 *
6529 * TODO: remove and use isUserDataEnabled.
6530 * This can't be removed now because some vendor codes
6531 * calls through ITelephony directly while they should
6532 * use TelephonyManager.
6533 *
6534 * @return true on enabled
6535 */
6536 @Override
6537 public boolean getDataEnabled(int subId) {
6538 return isUserDataEnabled(subId);
6539 }
6540
6541 /**
6542 * Get whether mobile data is enabled per user setting.
6543 *
6544 * There are other factors deciding whether mobile data is actually enabled, but they are
6545 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006546 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006547 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6548 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006549 *
6550 * @return {@code true} if data is enabled else {@code false}
6551 */
6552 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006553 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006554 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006555 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006556 try {
6557 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6558 functionName);
6559 } catch (Exception e) {
6560 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6561 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006562 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006564 mApp, subId, functionName);
6565
Robert Greenwalt646120a2014-05-23 11:54:03 -07006566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567
6568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 int phoneId = mSubscriptionController.getPhoneId(subId);
6571 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6572 Phone phone = PhoneFactory.getPhone(phoneId);
6573 if (phone != null) {
6574 boolean retVal = phone.isUserDataEnabled();
6575 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6576 return retVal;
6577 } else {
6578 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6579 return false;
6580 }
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006583 }
6584 }
6585
6586 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006587 * Checks if the device is capable of mobile data by considering whether whether the
6588 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6589 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006590 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006591 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006592 */
6593 @Override
6594 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006595 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006596 try {
6597 try {
6598 mApp.enforceCallingOrSelfPermission(
6599 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006600 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006601 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006602 try {
6603 mApp.enforceCallingOrSelfPermission(
6604 android.Manifest.permission.READ_PHONE_STATE,
6605 functionName);
6606 } catch (Exception e2) {
6607 mApp.enforceCallingOrSelfPermission(
6608 permission.READ_BASIC_PHONE_STATE, functionName);
6609 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006610 }
6611 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006612 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614
6615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 Phone phone = PhoneFactory.getPhone(phoneId);
6619 if (phone != null) {
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006620 boolean retVal;
6621 if (phone.isUsingNewDataStack()) {
Sarah Chin8619e162022-03-09 13:57:52 -08006622 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006623 } else {
6624 retVal = phone.getDataEnabledSettings().isDataEnabled();
6625 }
6626 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 return retVal;
6628 } else {
6629 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6630 return false;
6631 }
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006634 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006635 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006636
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006637 /**
6638 * Check if data is enabled for a specific reason
6639 * @param subId Subscription index
6640 * @param reason the reason the data enable change is taking place
6641 * @return {@code true} if the overall data is enabled; {@code false} if not.
6642 */
6643 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006644 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006645 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006646 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006647 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006648 try {
6649 mApp.enforceCallingOrSelfPermission(
6650 android.Manifest.permission.ACCESS_NETWORK_STATE,
6651 functionName);
6652 } catch (Exception e) {
6653 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6654 functionName);
6655 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006656 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006657 try {
6658 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006659 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006660 } catch (Exception e2) {
6661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006662 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006663 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006664 }
6665
6666
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
6669 int phoneId = mSubscriptionController.getPhoneId(subId);
6670 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006671 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006672 + " reason=" + reason);
6673 }
6674 Phone phone = PhoneFactory.getPhone(phoneId);
6675 if (phone != null) {
6676 boolean retVal;
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006677 if (phone.isUsingNewDataStack()) {
6678 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006679 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006680 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6681 retVal = phone.isUserDataEnabled();
6682 } else {
6683 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6684 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006686 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006687 return retVal;
6688 } else {
6689 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006690 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006691 + subId + " retVal=false");
6692 }
6693 return false;
6694 }
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
6697 }
6698 }
6699
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006700 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006701 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006702 if (uid == Process.PHONE_UID) {
6703 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6704 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006705 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6706 }
6707
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006708 //load access rules from carrier configs, and check those as well: b/139133814
6709 SubscriptionController subController = SubscriptionController.getInstance();
6710 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6711 || subController == null) return privilegeFromSim;
6712
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006713 PackageManager pkgMgr = phone.getContext().getPackageManager();
6714 String[] packages = pkgMgr.getPackagesForUid(uid);
6715
6716 final long identity = Binder.clearCallingIdentity();
6717 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006718 int subId = phone.getSubId();
6719 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6720 // A test override is in place for the privileges for this subId, so don't try to
6721 // read the subscription privileges.
6722 return privilegeFromSim;
6723 }
6724 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006725 SubscriptionManager subManager = (SubscriptionManager)
6726 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6727 for (String pkg : packages) {
6728 if (subManager.canManageSubscription(subInfo, pkg)) {
6729 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6730 }
6731 }
6732 return privilegeFromSim;
6733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
6736 }
6737
6738 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6739 String pkgName) {
6740 //load access rules from carrier configs, and check those as well: b/139133814
6741 SubscriptionController subController = SubscriptionController.getInstance();
6742 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6743 || subController == null) return privilegeFromSim;
6744
6745 final long identity = Binder.clearCallingIdentity();
6746 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006747 int subId = phone.getSubId();
6748 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6749 // A test override is in place for the privileges for this subId, so don't try to
6750 // read the subscription privileges.
6751 return privilegeFromSim;
6752 }
6753 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006754 SubscriptionManager subManager = (SubscriptionManager)
6755 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6756 return subManager.canManageSubscription(subInfo, pkgName)
6757 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
6761 }
6762
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006763 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006764 public int getCarrierPrivilegeStatus(int subId) {
6765 final Phone phone = getPhone(subId);
6766 if (phone == null) {
6767 loge("getCarrierPrivilegeStatus: Invalid subId");
6768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6769 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006770 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6771 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006772 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6774 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006775
6776 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006777 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006778 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006779 }
Junda Liu29340342014-07-10 15:23:27 -07006780
6781 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006783 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006784 final Phone phone = getPhone(subId);
6785 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006786 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6788 }
6789 UiccProfile profile =
6790 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6791 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006792 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006793 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6794 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006795 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006796 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006797 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006798 }
6799
6800 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006801 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006802 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006803 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006804 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006805 }
6806
6807 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006808 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6809 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006810 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006811 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6812 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006813 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006814 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006815 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006816 }
6817
6818 @Override
6819 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006820 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006821 if (TextUtils.isEmpty(pkgName))
6822 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006823 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6824 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006825 UiccPort port = UiccController.getInstance().getUiccPort(i);
6826 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006827 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006828 continue;
6829 }
6830
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006831 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006832 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006833 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006834 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6835 break;
6836 }
6837 }
6838
6839 return result;
Junda Liu29340342014-07-10 15:23:27 -07006840 }
Derek Tan89e89d42014-07-08 17:00:10 -07006841
6842 @Override
Junda Liue64de782015-04-16 17:19:16 -07006843 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006844 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006845 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6846 loge("phoneId " + phoneId + " is not valid.");
6847 return null;
6848 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006849 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6850 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006851 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006852 return null ;
6853 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006854 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006855 }
6856
Amith Yamasani6e118872016-02-19 12:53:51 -08006857 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006858 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006859 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006860 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006861 List<String> privilegedPackages = new ArrayList<>();
6862 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006863 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006864 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006865 if (port != null) {
6866 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006867 if (packages == null) {
6868 // Only check packages in user 0 for now
6869 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006870 PackageManager.MATCH_DISABLED_COMPONENTS
6871 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006872 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006873 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006874 }
6875 for (int p = packages.size() - 1; p >= 0; p--) {
6876 PackageInfo pkgInfo = packages.get(p);
6877 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006878 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006879 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006880 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006881 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006882 privilegedPackages.add(pkgInfo.packageName);
6883 }
6884 }
6885 }
6886 }
6887 return privilegedPackages;
6888 }
6889
chen xuf7e9fe82019-05-09 19:31:02 -07006890 @Override
6891 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006892 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6893
6894 final long identity = Binder.clearCallingIdentity();
6895
chen xuf7e9fe82019-05-09 19:31:02 -07006896 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006897 try {
6898 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6899 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6900 }
6901 } finally {
6902 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006903 }
6904 return privilegedPackages;
6905 }
6906
Wink Savilleb564aae2014-10-23 10:18:09 -07006907 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006908 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006909 UiccPort port = phone == null ? null : phone.getUiccPort();
6910 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006911 return null;
6912 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006913 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006914 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006915 return null;
6916 }
6917 return iccId;
6918 }
6919
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006920 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006921 public void setCallComposerStatus(int subId, int status) {
6922 enforceModifyPermission();
6923
6924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 Phone phone = getPhone(subId);
6927 if (phone != null) {
6928 Phone defaultPhone = phone.getImsPhone();
6929 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6930 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6931 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006932 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6933 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006934 }
6935 }
Shuo Qian284ae752020-12-22 19:10:14 -08006936 } catch (ImsException e) {
6937 throw new ServiceSpecificException(e.getCode());
6938 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006939 Binder.restoreCallingIdentity(identity);
6940 }
6941 }
6942
6943 @Override
6944 public int getCallComposerStatus(int subId) {
6945 enforceReadPrivilegedPermission("getCallComposerStatus");
6946
6947 final long identity = Binder.clearCallingIdentity();
6948 try {
6949 Phone phone = getPhone(subId);
6950 if (phone != null) {
6951 Phone defaultPhone = phone.getImsPhone();
6952 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6953 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6954 return imsPhone.getCallComposerStatus();
6955 }
6956 }
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
6959 }
6960 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6961 }
6962
6963 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006964 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6965 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006966 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006967 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 final long identity = Binder.clearCallingIdentity();
6970 try {
6971 final String iccId = getIccId(subId);
6972 final Phone phone = getPhone(subId);
6973 if (phone == null) {
6974 return false;
6975 }
6976 final String subscriberId = phone.getSubscriberId();
6977
6978 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006979 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 + subscriberId + " to " + number);
6981 }
6982
6983 if (TextUtils.isEmpty(iccId)) {
6984 return false;
6985 }
6986
6987 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6988
6989 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6990 if (alphaTag == null) {
6991 editor.remove(alphaTagPrefKey);
6992 } else {
6993 editor.putString(alphaTagPrefKey, alphaTag);
6994 }
6995
6996 // Record both the line number and IMSI for this ICCID, since we need to
6997 // track all merged IMSIs based on line number
6998 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6999 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7000 if (number == null) {
7001 editor.remove(numberPrefKey);
7002 editor.remove(subscriberPrefKey);
7003 } else {
7004 editor.putString(numberPrefKey, number);
7005 editor.putString(subscriberPrefKey, subscriberId);
7006 }
7007
7008 editor.commit();
7009 return true;
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007012 }
Derek Tan7226c842014-07-02 17:42:23 -07007013 }
7014
7015 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007016 public String getLine1NumberForDisplay(int subId, String callingPackage,
7017 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007018 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007020 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007021 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007022 return null;
7023 }
Derek Tan97ebb422014-09-05 16:55:38 -07007024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 String iccId = getIccId(subId);
7028 if (iccId != null) {
7029 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7030 if (DBG_MERGE) {
7031 log("getLine1NumberForDisplay returning "
7032 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7033 }
7034 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7037 return null;
7038 } finally {
7039 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007040 }
Derek Tan7226c842014-07-02 17:42:23 -07007041 }
7042
7043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007044 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7045 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007047 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007048 return null;
7049 }
Derek Tan97ebb422014-09-05 16:55:38 -07007050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 String iccId = getIccId(subId);
7054 if (iccId != null) {
7055 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7056 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7057 }
7058 return null;
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007061 }
Derek Tan7226c842014-07-02 17:42:23 -07007062 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007063
7064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007065 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7066 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007067 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7068 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007070 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007071 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007072 return null;
7073 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007074
Jordan Liub49b04b2019-05-06 14:45:15 -07007075 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7076 // the process, where TelephonyManager was instantiated.
7077 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007078 final long identity = Binder.clearCallingIdentity();
7079 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007080 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 final TelephonyManager tele = TelephonyManager.from(context);
7082 final SubscriptionManager sub = SubscriptionManager.from(context);
7083
7084 // Figure out what subscribers are currently active
7085 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086
Jordan Liub49b04b2019-05-06 14:45:15 -07007087 // Only consider subs which match the current subId
7088 // This logic can be simplified. See b/131189269 for progress.
7089 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007090 activeSubscriberIds.add(tele.getSubscriberId(subId));
7091 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092
7093 // First pass, find a number override for an active subscriber
7094 String mergeNumber = null;
7095 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7096 for (String key : prefs.keySet()) {
7097 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7098 final String subscriberId = (String) prefs.get(key);
7099 if (activeSubscriberIds.contains(subscriberId)) {
7100 final String iccId = key.substring(
7101 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7102 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7103 mergeNumber = (String) prefs.get(numberKey);
7104 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007105 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 + " for active subscriber " + subscriberId);
7107 }
7108 if (!TextUtils.isEmpty(mergeNumber)) {
7109 break;
7110 }
7111 }
7112 }
7113 }
7114
7115 // Shortcut when no active merged subscribers
7116 if (TextUtils.isEmpty(mergeNumber)) {
7117 return null;
7118 }
7119
7120 // Second pass, find all subscribers under that line override
7121 final ArraySet<String> result = new ArraySet<>();
7122 for (String key : prefs.keySet()) {
7123 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7124 final String number = (String) prefs.get(key);
7125 if (mergeNumber.equals(number)) {
7126 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7127 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7128 final String subscriberId = (String) prefs.get(subscriberKey);
7129 if (!TextUtils.isEmpty(subscriberId)) {
7130 result.add(subscriberId);
7131 }
7132 }
7133 }
7134 }
7135
7136 final String[] resultArray = result.toArray(new String[result.size()]);
7137 Arrays.sort(resultArray);
7138 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007139 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7141 }
7142 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007143 } finally {
7144 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007145 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007146 }
7147
7148 @Override
zoey chen38003472019-12-13 17:16:31 +08007149 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7150 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
7154 final TelephonyManager telephonyManager = mApp.getSystemService(
7155 TelephonyManager.class);
7156 String subscriberId = telephonyManager.getSubscriberId(subId);
7157 if (subscriberId == null) {
7158 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007159 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007160 + subId);
7161 }
7162 return null;
7163 }
7164
7165 final SubscriptionInfo info = SubscriptionController.getInstance()
7166 .getSubscriptionInfo(subId);
7167 final ParcelUuid groupUuid = info.getGroupUuid();
7168 // If it doesn't belong to any group, return just subscriberId of itself.
7169 if (groupUuid == null) {
7170 return new String[]{subscriberId};
7171 }
7172
7173 // Get all subscriberIds from the group.
7174 final List<String> mergedSubscriberIds = new ArrayList<>();
7175 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007176 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007177 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007178 for (SubscriptionInfo subInfo : groupInfos) {
7179 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7180 if (subscriberId != null) {
7181 mergedSubscriberIds.add(subscriberId);
7182 }
7183 }
7184
7185 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188
7189 }
7190 }
7191
7192 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007193 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007194 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007195 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 final Phone phone = getPhone(subId);
7200 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
7203 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007204 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007205
7206 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007207 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007208 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7209 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007210 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7211 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 final Phone phone = getPhone(subId);
7216 if (phone == null) {
7217 return false;
7218 }
7219 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7220 cdmaNonRoamingList);
7221 } finally {
7222 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007223 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007224 }
7225
7226 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007227 @Deprecated
7228 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7229 enforceModifyPermission();
7230
7231 int returnValue = 0;
7232 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007233 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007234 if(result.exception == null) {
7235 if (result.result != null) {
7236 byte[] responseData = (byte[])(result.result);
7237 if(responseData.length > oemResp.length) {
7238 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7239 responseData.length + "bytes. Buffer Size is " +
7240 oemResp.length + "bytes.");
7241 }
7242 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7243 returnValue = responseData.length;
7244 }
7245 } else {
7246 CommandException ex = (CommandException) result.exception;
7247 returnValue = ex.getCommandError().ordinal();
7248 if(returnValue > 0) returnValue *= -1;
7249 }
7250 } catch (RuntimeException e) {
7251 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7252 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7253 if(returnValue > 0) returnValue *= -1;
7254 }
7255
7256 return returnValue;
7257 }
7258
7259 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007260 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007261 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007262 try {
7263 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007264 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007265 mApp, phone.getSubId(), "getRadioAccessFamily");
7266 } catch (SecurityException e) {
7267 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7268 throw e;
7269 }
chen xub97461a2018-10-26 14:17:57 -07007270 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007271 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007272 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 final long identity = Binder.clearCallingIdentity();
7275 try {
chen xub97461a2018-10-26 14:17:57 -07007276 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007277 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007278 mApp, phone.getSubId(), "getRadioAccessFamily");
7279 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
chen xub97461a2018-10-26 14:17:57 -07007283 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007284 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007285
7286 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007287 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007288 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007289 try {
7290 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7291 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007292 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007293 }
7294 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007295 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007296 }
7297 RoleManager rm = mApp.getSystemService(RoleManager.class);
7298 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7299 if (!dialerRoleHolders.contains(callingPackage)) {
7300 throw new SecurityException("App must be the dialer role holder to"
7301 + " upload a call composer pic");
7302 }
7303
7304 Executors.newSingleThreadExecutor().execute(() -> {
7305 ByteArrayOutputStream output = new ByteArrayOutputStream(
7306 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7307 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7308 boolean readUntilEnd = false;
7309 int totalBytesRead = 0;
7310 byte[] buffer = new byte[16 * 1024];
7311 while (true) {
7312 int numRead;
7313 try {
7314 numRead = input.read(buffer);
7315 } catch (IOException e) {
7316 try {
7317 fd.checkError();
7318 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7319 null);
7320 } catch (IOException e1) {
7321 // This means that the other side closed explicitly with an error. If this
7322 // happens, log and ignore.
7323 loge("Remote end of call composer picture pipe closed: " + e1);
7324 }
7325 break;
7326 }
7327 if (numRead == -1) {
7328 readUntilEnd = true;
7329 break;
7330 }
7331 totalBytesRead += numRead;
7332 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7333 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7334 try {
7335 input.close();
7336 } catch (IOException e) {
7337 // ignore
7338 }
7339 break;
7340 }
7341 output.write(buffer, 0, numRead);
7342 }
7343 // Generally, the remote end will close the file descriptors. The only case where we
7344 // close is above, where the picture size is too big.
7345
7346 try {
7347 fd.checkError();
7348 } catch (IOException e) {
7349 loge("Remote end for call composer closed with an error: " + e);
7350 return;
7351 }
7352
Hall Liuaa4211e2021-01-20 15:43:39 -08007353 if (!readUntilEnd) {
7354 loge("Did not finish reading entire image; aborting");
7355 return;
7356 }
Hall Liu82694d52020-12-11 18:22:04 -08007357
Hall Liuaa4211e2021-01-20 15:43:39 -08007358 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7359 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7360 new CallComposerPictureTransfer.Factory() {},
7361 imageData,
7362 (result) -> {
7363 if (result.first != null) {
7364 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7365 Bundle outputResult = new Bundle();
7366 outputResult.putParcelable(
7367 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7368 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7369 outputResult);
7370 } else {
7371 callback.send(result.second, null);
7372 }
7373 }
7374 );
Hall Liu82694d52020-12-11 18:22:04 -08007375 });
7376 }
7377
7378 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007379 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007380 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007381 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382
7383 final long identity = Binder.clearCallingIdentity();
7384 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007385 ImsManager.getInstance(defaultPhone.getContext(),
7386 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 } finally {
7388 Binder.restoreCallingIdentity(identity);
7389 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007390 }
7391
7392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007394 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7396 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007397 return false;
7398 }
Svet Ganovb320e182015-04-16 12:30:10 -07007399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 // Check the user preference and the system-level IMS setting. Even if the user has
7403 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7404 // In the long run, we may instead need to check if there exists a connection service
7405 // which can support video calling.
7406 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007407 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 return imsManager.isVtEnabledByPlatform()
7409 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7410 && imsManager.isVtEnabledByUser();
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007414 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007415
Andrew Leea1239f22015-03-02 17:44:07 -08007416 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007417 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7418 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007420 mApp, subId, callingPackage, callingFeatureId,
7421 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 return false;
7423 }
7424
7425 final long identity = Binder.clearCallingIdentity();
7426 try {
7427 CarrierConfigManager configManager =
7428 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007429 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7431 } finally {
7432 Binder.restoreCallingIdentity(identity);
7433 }
Andrew Leea1239f22015-03-02 17:44:07 -08007434 }
7435
7436 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 return false;
7441 }
7442
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
7445 CarrierConfigManager configManager =
7446 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007447 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
Andrew Leea1239f22015-03-02 17:44:07 -08007452 }
7453
Andrew Lee9431b832015-03-09 18:46:45 -07007454 @Override
7455 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007456 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007457 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007458 }
7459
7460 @Override
7461 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 final long identity = Binder.clearCallingIdentity();
7463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467 }
Andrew Lee9431b832015-03-09 18:46:45 -07007468 }
7469
Hall Liuf6668912018-10-31 17:05:23 -07007470 /**
7471 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7472 * support for the feature and device firmware support.
7473 *
7474 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7475 */
7476 @Override
7477 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007479 final Phone phone = getPhone(subscriptionId);
7480 if (phone == null) {
7481 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7482 return false;
7483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007485 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7487 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007488 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 return isCarrierSupported && isDeviceSupported;
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Hall Liu98187582018-01-22 19:15:32 -08007493 }
7494
Hall Liuf6668912018-10-31 17:05:23 -07007495 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007496 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7497 * RTT setting, will return true if the device and carrier both support RTT.
7498 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007499 */
7500 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 final long identity = Binder.clearCallingIdentity();
7502 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007503 boolean isRttSupported = isRttSupported(subscriptionId);
7504 boolean isUserRttSettingOn = Settings.Secure.getInt(
7505 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7506 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7507 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7508 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007512 }
7513
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007514 @Deprecated
7515 @Override
7516 public String getDeviceId(String callingPackage) {
7517 return getDeviceIdWithFeature(callingPackage, null);
7518 }
7519
Sanket Padawe7310cc72015-01-14 09:53:20 -08007520 /**
7521 * Returns the unique device ID of phone, for example, the IMEI for
7522 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7523 *
7524 * <p>Requires Permission:
7525 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7526 */
7527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007528 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007529 try {
7530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7531 } catch (SecurityException se) {
7532 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7533 throw new SecurityException("Package " + callingPackage + " does not belong to "
7534 + Binder.getCallingUid());
7535 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007536 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007537 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007538 return null;
7539 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007540 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007541 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007542 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007543 return null;
7544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545
7546 final long identity = Binder.clearCallingIdentity();
7547 try {
7548 return phone.getDeviceId();
7549 } finally {
7550 Binder.restoreCallingIdentity(identity);
7551 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007552 }
7553
Ping Sunc67b7c22016-03-02 19:16:45 +08007554 /**
7555 * {@hide}
7556 * Returns the IMS Registration Status on a particular subid
7557 *
7558 * @param subId
7559 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007560 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007561 Phone phone = getPhone(subId);
7562 if (phone != null) {
7563 return phone.isImsRegistered();
7564 } else {
7565 return false;
7566 }
7567 }
7568
Santos Cordon7a1885b2015-02-03 11:15:19 -08007569 @Override
7570 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 final long identity = Binder.clearCallingIdentity();
7572 try {
7573 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
7576 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007577 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007578
Tyler Gunnf70ed162019-04-03 15:28:53 -07007579 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007580 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007581 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007583 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007584 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7585 }
7586 final long identity = Binder.clearCallingIdentity();
7587 try {
7588 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7589 } finally {
7590 Binder.restoreCallingIdentity(identity);
7591 }
7592 }
7593
7594 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007595 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007596 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007597 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007598 mApp,
7599 subscriptionId,
7600 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 Phone phone = getPhone(subscriptionId);
7604 if (phone == null) {
7605 return null;
7606 }
7607 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
7610 }
7611 }
7612
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007613 /**
7614 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007615 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007616 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 final long identity = Binder.clearCallingIdentity();
7618 try {
7619 Phone phone = getPhone(subId);
7620 if (phone != null) {
7621 return phone.isWifiCallingEnabled();
7622 } else {
7623 return false;
7624 }
7625 } finally {
7626 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007627 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007628 }
7629
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007630 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007631 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007632 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007633 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 Phone phone = getPhone(subId);
7637 if (phone != null) {
7638 return phone.isVideoEnabled();
7639 } else {
7640 return false;
7641 }
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007644 }
7645 }
7646
7647 /**
7648 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7649 * defined in {@link ImsRegistrationImplBase}.
7650 */
7651 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 Phone phone = getPhone(subId);
7655 if (phone != null) {
7656 return phone.getImsRegistrationTech();
7657 } else {
7658 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7659 }
7660 } finally {
7661 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007663 }
7664
Stuart Scott8eef64f2015-04-08 15:13:54 -07007665 @Override
7666 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007667 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007668 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7669 return;
7670 }
Kai Shif70f46f2021-03-03 13:59:46 -08007671 Phone defaultPhone = getDefaultPhone();
7672 if (defaultPhone != null) {
7673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7674 mApp, getDefaultPhone().getSubId(), "factoryReset");
7675 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007676 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007677
Svet Ganovcc087f82015-05-12 20:35:54 -07007678 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007679 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7680 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007681 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007682 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007683 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007684 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007685 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007686 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007687 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007688 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007689 // There has been issues when Sms raw table somehow stores orphan
7690 // fragments. They lead to garbled message when new fragments come
7691 // in and combined with those stale ones. In case this happens again,
7692 // user can reset all network settings which will clean up this table.
7693 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007694 // Clean up IMS settings as well here.
7695 int slotId = getSlotIndex(subId);
7696 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7697 ImsManager.getInstance(mApp, slotId).factoryReset();
7698 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007699
Kai Shif70f46f2021-03-03 13:59:46 -08007700 if (defaultPhone == null) {
7701 return;
7702 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007703 // Erase modem config if erase modem on network setting is enabled.
7704 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7705 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7706 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007707 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007708 }
Kai Shif70f46f2021-03-03 13:59:46 -08007709
7710 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007711 } finally {
7712 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007713 }
7714 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007715
SongFerngWangfd89b102021-05-27 22:44:54 +08007716 @VisibleForTesting
7717 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7718 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7719 return;
7720 }
7721 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7722 RILConstants.PREFERRED_NETWORK_MODE);
7723 SubscriptionManager.setSubscriptionProperty(subId,
7724 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7725 "user=" + defaultNetworkType);
7726 phone.loadAllowedNetworksFromSubscriptionDatabase();
7727 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7728 defaultNetworkType, null);
7729 }
7730
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007731 private void cleanUpSmsRawTable(Context context) {
7732 ContentResolver resolver = context.getContentResolver();
7733 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7734 resolver.delete(uri, null, null);
7735 }
7736
Narayan Kamath1c496c22015-04-16 14:40:19 +01007737 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007738 public String getSimLocaleForSubscriber(int subId) {
7739 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7740 final Phone phone = getPhone(subId);
7741 if (phone == null) {
7742 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007743 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 final long identity = Binder.clearCallingIdentity();
7746 try {
chen xu5d3637b2019-01-21 23:31:38 -08007747 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007748 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007749 if (info == null) {
7750 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7751 return null;
7752 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 // Try and fetch the locale from the carrier properties or from the SIM language
7754 // preferences (EF-PL and EF-LI)...
7755 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007757 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7758 if (localeFromDefaultSim != null) {
7759 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7760 if (DBG) log("Using locale from subId: " + subId + " locale: "
7761 + localeFromDefaultSim);
7762 return localeFromDefaultSim.toLanguageTag();
7763 } else {
7764 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 }
7766 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 // The SIM language preferences only store a language (e.g. fr = French), not an
7769 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7770 // the SIM and carrier preferences does not include a country we add the country
7771 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007772 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007774 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 return mccLocale.toLanguageTag();
7776 }
7777
7778 if (DBG) log("No locale found - returning null");
7779 return null;
7780 } finally {
7781 Binder.restoreCallingIdentity(identity);
7782 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007783 }
7784
7785 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007786 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007787 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007788 }
7789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 /**
7791 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7792 */
7793 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007794 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007795 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007796 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007797
Chenjie Yu1ba97252018-01-11 18:16:20 -08007798 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007799 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007800
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007801 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007802 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7803 * representing the state of the modem.
7804 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007805 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7806 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007807 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007808 */
7809 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007810 public void requestModemActivityInfo(ResultReceiver result) {
7811 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813
7814 final long identity = Binder.clearCallingIdentity();
7815 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007816 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 } finally {
7818 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007819 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007820 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007821
Siddharth Rayb8114062018-06-17 15:02:38 -07007822 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7823 // less than total activity duration.
7824 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7825 if (info == null) {
7826 return false;
7827 }
7828 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007829 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7830 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7831
Siddharth Rayb8114062018-06-17 15:02:38 -07007832 return (info.isValid()
7833 && (info.getSleepTimeMillis() <= activityDurationMs)
7834 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007835 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007836 && (totalTxTimeMs <= activityDurationMs));
7837 }
7838
Jack Yu85bd38a2015-11-09 11:34:32 -08007839 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007840 * Returns the service state information on specified subscription.
7841 */
7842 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007843 public ServiceState getServiceStateForSubscriber(int subId,
7844 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7845 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007847 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007848 return null;
7849 }
7850
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007851 boolean hasFinePermission = false;
7852 boolean hasCoarsePermission = false;
7853 if (!renounceFineLocationAccess) {
7854 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7855 LocationAccessPolicy.checkLocationPermission(mApp,
7856 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7857 .setCallingPackage(callingPackage)
7858 .setCallingFeatureId(callingFeatureId)
7859 .setCallingPid(Binder.getCallingPid())
7860 .setCallingUid(Binder.getCallingUid())
7861 .setMethod("getServiceStateForSubscriber")
7862 .setLogAsInfo(true)
7863 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7864 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7865 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7866 .build());
7867 hasFinePermission =
7868 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7869 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007870
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007871 if (!renounceCoarseLocationAccess) {
7872 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7873 LocationAccessPolicy.checkLocationPermission(mApp,
7874 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7875 .setCallingPackage(callingPackage)
7876 .setCallingFeatureId(callingFeatureId)
7877 .setCallingPid(Binder.getCallingPid())
7878 .setCallingUid(Binder.getCallingUid())
7879 .setMethod("getServiceStateForSubscriber")
7880 .setLogAsInfo(true)
7881 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7882 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7883 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7884 .build());
7885 hasCoarsePermission =
7886 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7887 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007888
Jack Yu479f40e2020-10-27 21:29:25 -07007889 final Phone phone = getPhone(subId);
7890 if (phone == null) {
7891 return null;
7892 }
7893
Jordan Liu0f2bc442020-11-18 16:47:37 -08007894 final long identity = Binder.clearCallingIdentity();
7895
Jack Yu479f40e2020-10-27 21:29:25 -07007896 boolean isCallingPackageDataService = phone.getDataServicePackages()
7897 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007899 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7900 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7901 Rlog.d(LOG_TAG,
7902 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7903 return null;
7904 }
7905
Hall Liuf19c44f2018-11-27 14:38:17 -08007906 ServiceState ss = phone.getServiceState();
7907
7908 // Scrub out the location info in ServiceState depending on what level of access
7909 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007910 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007911 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7912 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913 } finally {
7914 Binder.restoreCallingIdentity(identity);
7915 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007916 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007917
7918 /**
7919 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7920 *
7921 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7922 * voicemail ringtone.
7923 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7924 * PhoneAccount.
7925 */
7926 @Override
7927 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007928 final long identity = Binder.clearCallingIdentity();
7929 try {
7930 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7931 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007932 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7936 } finally {
7937 Binder.restoreCallingIdentity(identity);
7938 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007939 }
7940
7941 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007942 * Sets the per-account voicemail ringtone.
7943 *
7944 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7945 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7946 *
7947 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7948 * voicemail ringtone.
7949 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7950 * PhoneAccount.
7951 */
7952 @Override
7953 public void setVoicemailRingtoneUri(String callingPackage,
7954 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007955 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007956 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007957 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7958 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7960 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7961 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963
7964 final long identity = Binder.clearCallingIdentity();
7965 try {
7966 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7967 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007968 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 }
7970 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007973 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007974 }
7975
7976 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007977 * Returns whether vibration is set for voicemail notification in Phone settings.
7978 *
7979 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7980 * voicemail vibration setting.
7981 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7982 */
7983 @Override
7984 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 final long identity = Binder.clearCallingIdentity();
7986 try {
7987 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7988 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007989 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7993 } finally {
7994 Binder.restoreCallingIdentity(identity);
7995 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007996 }
7997
Youhan Wange64578a2016-05-02 15:32:42 -07007998 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007999 * Sets the per-account voicemail vibration.
8000 *
8001 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8002 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8003 *
8004 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8005 * voicemail vibration setting.
8006 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8007 * specific PhoneAccount.
8008 */
8009 @Override
8010 public void setVoicemailVibrationEnabled(String callingPackage,
8011 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008012 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008014 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8015 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8017 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8018 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 }
8020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 final long identity = Binder.clearCallingIdentity();
8022 try {
8023 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8024 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008025 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 }
8027 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8028 } finally {
8029 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008030 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008031 }
8032
8033 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008034 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8035 *
8036 * @throws SecurityException if the caller does not have the required permission
8037 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008038 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008039 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008040 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008041 }
8042
8043 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008044 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8045 * permission.
8046 *
8047 * @throws SecurityException if the caller does not have the required permission
8048 */
8049 private void enforceSendSmsPermission() {
8050 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8051 }
8052
8053 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008054 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008055 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008056 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008057 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008058 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059 final long identity = Binder.clearCallingIdentity();
8060 try {
8061 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008062 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 if (componentName == null) {
8064 throw new SecurityException(
8065 "Caller not current active visual voicemail package[null]");
8066 }
8067 String vvmPackage = componentName.getPackageName();
8068 if (!callingPackage.equals(vvmPackage)) {
8069 throw new SecurityException("Caller not current active visual voicemail package["
8070 + vvmPackage + "]");
8071 }
8072 } finally {
8073 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008074 }
8075 }
8076
8077 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008078 * Return the application ID for the app type.
8079 *
8080 * @param subId the subscription ID that this request applies to.
8081 * @param appType the uicc app type.
8082 * @return Application ID for specificied app type, or null if no uicc.
8083 */
8084 @Override
8085 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008086 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008087 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088
8089 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008090 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 if (phone == null) {
8092 return null;
8093 }
8094 String aid = null;
8095 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008096 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 .getApplicationByType(appType).getAid();
8098 } catch (Exception e) {
8099 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8100 }
8101 return aid;
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008104 }
Youhan Wange64578a2016-05-02 15:32:42 -07008105 }
8106
Youhan Wang4001d252016-05-11 10:29:41 -07008107 /**
8108 * Return the Electronic Serial Number.
8109 *
8110 * @param subId the subscription ID that this request applies to.
8111 * @return ESN or null if error.
8112 */
8113 @Override
8114 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008115 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008116 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117
8118 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008119 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 if (phone == null) {
8121 return null;
8122 }
8123 String esn = null;
8124 try {
8125 esn = phone.getEsn();
8126 } catch (Exception e) {
8127 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8128 }
8129 return esn;
8130 } finally {
8131 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008132 }
Youhan Wang4001d252016-05-11 10:29:41 -07008133 }
8134
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008135 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008136 * Return the Preferred Roaming List Version.
8137 *
8138 * @param subId the subscription ID that this request applies to.
8139 * @return PRLVersion or null if error.
8140 */
8141 @Override
8142 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008143 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008144 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008145
8146 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008147 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148 if (phone == null) {
8149 return null;
8150 }
8151 String cdmaPrlVersion = null;
8152 try {
8153 cdmaPrlVersion = phone.getCdmaPrlVersion();
8154 } catch (Exception e) {
8155 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8156 }
8157 return cdmaPrlVersion;
8158 } finally {
8159 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008160 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008161 }
8162
8163 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008164 * Get snapshot of Telephony histograms
8165 * @return List of Telephony histograms
8166 * @hide
8167 */
8168 @Override
8169 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8171 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008172
8173 final long identity = Binder.clearCallingIdentity();
8174 try {
8175 return RIL.getTelephonyRILTimingHistograms();
8176 } finally {
8177 Binder.restoreCallingIdentity(identity);
8178 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008179 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008180
8181 /**
8182 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008183 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8184 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008185 * Require system privileges. In the future we may add this to carrier APIs.
8186 *
Michele Berionne482f8202018-11-27 18:57:59 -08008187 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008188 */
8189 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008190 @TelephonyManager.SetCarrierRestrictionResult
8191 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008192 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008193 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008194
Michele Berionne482f8202018-11-27 18:57:59 -08008195 if (carrierRestrictionRules == null) {
8196 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008197 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199 final long identity = Binder.clearCallingIdentity();
8200 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008201 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008202 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008203 } finally {
8204 Binder.restoreCallingIdentity(identity);
8205 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008206 }
8207
8208 /**
8209 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008210 * Get the allowed carrier list and the excluded carrier list, including the priority between
8211 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008212 * Require system privileges. In the future we may add this to carrier APIs.
8213 *
Michele Berionne482f8202018-11-27 18:57:59 -08008214 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008215 */
8216 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008217 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008218 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008219 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220
8221 final long identity = Binder.clearCallingIdentity();
8222 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008223 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8224 if (response instanceof CarrierRestrictionRules) {
8225 return (CarrierRestrictionRules) response;
8226 }
8227 // Response is an Exception of some kind,
8228 // which is signalled to the user as a NULL retval
8229 return null;
8230 } catch (Exception e) {
8231 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8232 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 } finally {
8234 Binder.restoreCallingIdentity(identity);
8235 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008236 }
8237
fionaxu59545b42016-05-25 15:53:37 -07008238 /**
fionaxu59545b42016-05-25 15:53:37 -07008239 * Action set from carrier signalling broadcast receivers to enable/disable radio
8240 * @param subId the subscription ID that this action applies to.
8241 * @param enabled control enable or disable radio.
8242 * {@hide}
8243 */
8244 @Override
8245 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8246 enforceModifyPermission();
8247 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248
8249 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008250 if (phone == null) {
8251 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8252 return;
8253 }
8254 try {
8255 phone.carrierActionSetRadioEnabled(enabled);
8256 } catch (Exception e) {
8257 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 } finally {
8259 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008260 }
8261 }
8262
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008263 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008264 * Enable or disable Voice over NR (VoNR)
8265 * @param subId the subscription ID that this action applies to.
8266 * @param enabled enable or disable VoNR.
8267 * @return operation result.
8268 */
8269 @Override
8270 public int setVoNrEnabled(int subId, boolean enabled) {
8271 enforceModifyPermission();
8272 final Phone phone = getPhone(subId);
8273
8274 final long identity = Binder.clearCallingIdentity();
8275 if (phone == null) {
8276 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8277 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8278 }
8279
8280 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8281 try {
8282 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8283 workSource);
8284 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008285
8286 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8287 if (DBG) {
8288 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8289 }
8290 SubscriptionManager.setSubscriptionProperty(
8291 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8292 (enabled ? "1" : "0"));
8293 }
8294
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008295 return result;
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
8299 }
8300
8301 /**
8302 * Is voice over NR enabled
8303 * @return true if VoNR is enabled else false
8304 */
8305 @Override
8306 public boolean isVoNrEnabled(int subId) {
8307 enforceReadPrivilegedPermission("isVoNrEnabled");
8308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8312 null, subId, workSource);
8313 if (DBG) log("isVoNrEnabled: " + isEnabled);
8314 return isEnabled;
8315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
8318 }
8319
8320 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008321 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8322 * network status based on which carrier apps could apply actions accordingly,
8323 * enable/disable default url handler for example.
8324 *
8325 * @param subId the subscription ID that this action applies to.
8326 * @param report control start/stop reporting the default network status.
8327 * {@hide}
8328 */
8329 @Override
8330 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8331 enforceModifyPermission();
8332 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333
8334 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008335 if (phone == null) {
8336 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8337 return;
8338 }
8339 try {
8340 phone.carrierActionReportDefaultNetworkStatus(report);
8341 } catch (Exception e) {
8342 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 } finally {
8344 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008345 }
8346 }
8347
8348 /**
fionaxud9622282017-07-17 17:51:30 -07008349 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8350 * @param subId the subscription ID that this action applies to.
8351 * {@hide}
8352 */
8353 @Override
8354 public void carrierActionResetAll(int subId) {
8355 enforceModifyPermission();
8356 final Phone phone = getPhone(subId);
8357 if (phone == null) {
8358 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8359 return;
8360 }
8361 try {
8362 phone.carrierActionResetAll();
8363 } catch (Exception e) {
8364 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8365 }
8366 }
8367
8368 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008369 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8370 * bug report is being generated.
8371 */
8372 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008373 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008374 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8375 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008376 writer.println("Permission Denial: can't dump Phone from pid="
8377 + Binder.getCallingPid()
8378 + ", uid=" + Binder.getCallingUid()
8379 + "without permission "
8380 + android.Manifest.permission.DUMP);
8381 return;
8382 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008383 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008384 }
Jack Yueb89b242016-06-22 13:27:47 -07008385
Brad Ebingerdac2f002018-04-03 15:17:52 -07008386 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008387 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8388 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8389 @NonNull String[] args) {
8390 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8391 this, in.getFileDescriptor(), out.getFileDescriptor(),
8392 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008393 }
8394
Jack Yueb89b242016-06-22 13:27:47 -07008395 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008396 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008397 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008398 * @param reason the reason the data enable change is taking place
8399 * @param enabled True if enabling the data, otherwise disabling.
8400 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008401 */
8402 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008403 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008404 boolean enabled) {
8405 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8406 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8407 try {
8408 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008409 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008410 } catch (SecurityException se) {
8411 enforceModifyPermission();
8412 }
8413 } else {
8414 enforceModifyPermission();
8415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008416
8417 final long identity = Binder.clearCallingIdentity();
8418 try {
8419 Phone phone = getPhone(subId);
8420 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008421 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8422 phone.carrierActionSetMeteredApnsEnabled(enabled);
8423 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008424 if (phone.isUsingNewDataStack()) {
8425 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8426 } else {
8427 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8428 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 }
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008433 }
8434 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008435
8436 /**
8437 * Get Client request stats
8438 * @return List of Client Request Stats
8439 * @hide
8440 */
8441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008442 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8443 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008444 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008445 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008446 return null;
8447 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008448 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 if (phone != null) {
8453 return phone.getClientRequestStats();
8454 }
8455
8456 return null;
8457 } finally {
8458 Binder.restoreCallingIdentity(identity);
8459 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008460 }
8461
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008462 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008463 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008464 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008465 }
Jack Yueb4124c2017-02-16 15:32:43 -08008466
8467 /**
Grace Chen70990072017-03-24 17:21:30 -07008468 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008469 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008470 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008471 * @param state State of SIM (power down, power up, pass through)
8472 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8473 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8474 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008475 *
8476 **/
8477 @Override
Grace Chen70990072017-03-24 17:21:30 -07008478 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008479 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008480 Phone phone = PhoneFactory.getPhone(slotIndex);
8481
vagdeviaf9a5b92018-08-15 16:01:53 -07008482 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008484 final long identity = Binder.clearCallingIdentity();
8485 try {
8486 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008487 phone.setSimPowerState(state, null, workSource);
8488 }
8489 } finally {
8490 Binder.restoreCallingIdentity(identity);
8491 }
8492 }
8493
8494 /**
8495 * Set SIM card power state.
8496 *
8497 * @param slotIndex SIM slot id.
8498 * @param state State of SIM (power down, power up, pass through)
8499 * @param callback callback to trigger after success or failure
8500 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8501 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8502 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8503 *
8504 **/
8505 @Override
8506 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8507 IIntegerConsumer callback) {
8508 enforceModifyPermission();
8509 Phone phone = PhoneFactory.getPhone(slotIndex);
8510
8511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8512
8513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 if (phone != null) {
8516 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8517 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008518 }
8519 } finally {
8520 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008521 }
8522 }
Shuo Qiandd210312017-04-12 22:11:33 +00008523
Tyler Gunn65d45c22017-06-05 11:22:26 -07008524 private boolean isUssdApiAllowed(int subId) {
8525 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008526 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008527 if (configManager == null) {
8528 return false;
8529 }
8530 PersistableBundle pb = configManager.getConfigForSubId(subId);
8531 if (pb == null) {
8532 return false;
8533 }
8534 return pb.getBoolean(
8535 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8536 }
8537
Shuo Qiandd210312017-04-12 22:11:33 +00008538 /**
8539 * Check if phone is in emergency callback mode
8540 * @return true if phone is in emergency callback mode
8541 * @param subId sub id
8542 */
goneil9c5f4872017-12-05 14:07:56 -08008543 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008544 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008545 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008546 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547
8548 final long identity = Binder.clearCallingIdentity();
8549 try {
8550 if (phone != null) {
8551 return phone.isInEcm();
8552 } else {
8553 return false;
8554 }
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008557 }
8558 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008559
8560 /**
8561 * Get the current signal strength information for the given subscription.
8562 * Because this information is not updated when the device is in a low power state
8563 * it should not be relied-upon to be current.
8564 * @param subId Subscription index
8565 * @return the most recent cached signal strength info from the modem
8566 */
8567 @Override
8568 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569 final long identity = Binder.clearCallingIdentity();
8570 try {
8571 Phone p = getPhone(subId);
8572 if (p == null) {
8573 return null;
8574 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008576 return p.getSignalStrength();
8577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008580 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008581
Pengquan Meng77b7f132018-08-22 14:49:57 -07008582 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008583 * Get the current modem radio state for the given slot.
8584 * @param slotIndex slot index.
8585 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008586 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008587 * @return the current radio power state from the modem
8588 */
8589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008590 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008591 Phone phone = PhoneFactory.getPhone(slotIndex);
8592 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8594 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008595 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8596 }
8597
8598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 return phone.getRadioPowerState();
8601 } finally {
8602 Binder.restoreCallingIdentity(identity);
8603 }
8604 }
8605 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8606 }
8607
8608 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008609 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8610 *
8611 * <p>Requires one of the following permissions:
8612 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008613 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008614 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8615 * privileges.
8616 *
8617 * @param subId subscription id
8618 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8619 * {@code false}.
8620 */
8621 @Override
8622 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008623 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008624 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008625 try {
8626 mApp.enforceCallingOrSelfPermission(
8627 android.Manifest.permission.ACCESS_NETWORK_STATE,
8628 functionName);
8629 } catch (Exception e) {
8630 mApp.enforceCallingOrSelfPermission(
8631 permission.READ_BASIC_PHONE_STATE, functionName);
8632 }
Shuo Qian093013d2020-08-13 15:42:55 -07008633 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008634 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008635 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008636 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008637
Pengquan Menga1bb6272018-09-06 09:59:22 -07008638 boolean isEnabled = false;
8639 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008640 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008641 Phone phone = getPhone(subId);
8642 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008643 } finally {
8644 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008646 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008647 }
8648
8649
8650 /**
8651 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8652 *
8653 * <p> Requires permission:
8654 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8655 * privileges.
8656 *
8657 * @param subId subscription id
8658 * @param isEnabled {@code true} means enable, {@code false} means disable.
8659 */
8660 @Override
8661 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8663 mApp, subId, "setDataRoamingEnabled");
8664
Pengquan Menga1bb6272018-09-06 09:59:22 -07008665 final long identity = Binder.clearCallingIdentity();
8666 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008667 Phone phone = getPhone(subId);
8668 if (phone != null) {
8669 phone.setDataRoamingEnabled(isEnabled);
8670 }
8671 } finally {
8672 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008673 }
8674 }
8675
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008676 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008677 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008678 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008679 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008680 mApp, subId, "isManualNetworkSelectionAllowed");
8681
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008682 boolean isAllowed = true;
8683 final long identity = Binder.clearCallingIdentity();
8684 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008685 Phone phone = getPhone(subId);
8686 if (phone != null) {
8687 isAllowed = phone.isCspPlmnEnabled();
8688 }
8689 } finally {
8690 Binder.restoreCallingIdentity(identity);
8691 }
8692 return isAllowed;
8693 }
8694
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008695 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8696 UiccProfile profile = port.getUiccProfile();
8697 if (profile == null ||
8698 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8699 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8700 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008701 }
8702 return true;
8703 }
8704
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008705 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008706 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008707 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008708 mApp.getSystemService(AppOpsManager.class)
8709 .checkPackage(Binder.getCallingUid(), callingPackage);
8710
Jordan Liu1e142fc2019-04-22 15:10:43 -07008711 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008712 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008713 try {
8714 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008715 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008716 } catch (SecurityException e) {
8717 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8718 // has carrier privileges on an active UICC
8719 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8720 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008721 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008722 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008723 }
sandeepjs0a502c42021-09-27 15:34:44 +00008724 // checking compatibility, if calling app's target SDK is T and beyond.
8725 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8726 Binder.getCallingUid())) {
8727 isIccIdAccessRestricted = true;
8728 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008729 final long identity = Binder.clearCallingIdentity();
8730 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008731 UiccController uiccController = UiccController.getInstance();
8732 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008733 if (hasReadPermission) {
8734 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008735 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008736
8737 // Remove private info if the caller doesn't have access
8738 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8739 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008740 //setting the value after compatibility check
8741 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008742 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8743 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008744 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008745 if (card == null) {
8746 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008747 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008748 continue;
8749 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008750 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8751 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008752 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008753 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008754 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008755 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8756 for (UiccPortInfo portInfo : portInfos) {
8757 UiccPort port = uiccController.getUiccPortForSlot(
8758 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8759 if (port == null) {
8760 // assume no access if port is null
8761 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8762 continue;
8763 }
8764 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8765 uiccPortInfos.add(portInfo);
8766 } else {
8767 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8768 }
8769 }
8770 filteredInfos.add(new UiccCardInfo(
8771 cardInfo.isEuicc(),
8772 cardInfo.getCardId(),
8773 null,
8774 cardInfo.getPhysicalSlotIndex(),
8775 cardInfo.isRemovable(),
8776 cardInfo.isMultipleEnabledProfilesSupported(),
8777 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008778 }
8779 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008780 } finally {
8781 Binder.restoreCallingIdentity(identity);
8782 }
8783 }
8784
sandeepjs0a502c42021-09-27 15:34:44 +00008785 /**
8786 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8787 * generally private and require carrier privileges to view.
8788 *
8789 * @hide
8790 */
8791 @NonNull
8792 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8793 List<UiccPortInfo> portinfo = new ArrayList<>();
8794 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8795 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8796 }
8797 return new UiccCardInfo(
8798 cardInfo.isEuicc(),
8799 cardInfo.getCardId(),
8800 null,
8801 cardInfo.getPhysicalSlotIndex(),
8802 cardInfo.isRemovable(),
8803 cardInfo.isMultipleEnabledProfilesSupported(),
8804 portinfo
8805 );
8806 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008807
sandeepjs0a502c42021-09-27 15:34:44 +00008808 /**
8809 * @hide
8810 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8811 * These values are generally private and require carrier privileges to view.
8812 */
8813 @NonNull
8814 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8815 return new UiccPortInfo(
8816 UiccPortInfo.ICCID_REDACTED,
8817 portInfo.getPortIndex(),
8818 portInfo.getLogicalSlotIndex(),
8819 portInfo.isActive()
8820 );
8821 }
8822 @Override
8823 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008824 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008825 mApp.getSystemService(AppOpsManager.class)
8826 .checkPackage(Binder.getCallingUid(), callingPackage);
8827
8828 boolean hasReadPermission = false;
8829 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008830
8831 try {
8832 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8833 hasReadPermission = true;
8834 } catch (SecurityException e) {
8835 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8836 // has carrier privileges on an active UICC
8837 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8838 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8839 hasReadPermission = true;
8840 }
8841 }
8842
8843 // checking compatibility, if calling app's target SDK is T and beyond.
8844 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8845 Binder.getCallingUid())) {
8846 isLogicalSlotAccessRestricted = true;
8847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848 final long identity = Binder.clearCallingIdentity();
8849 try {
8850 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8851 if (slots == null) {
8852 Rlog.i(LOG_TAG, "slots is null.");
8853 return null;
8854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008855 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8856 for (int i = 0; i < slots.length; i++) {
8857 UiccSlot slot = slots[i];
8858 if (slot == null) {
8859 continue;
8860 }
8861
Jordan Liu7be7e652019-05-06 18:55:02 +00008862 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008863 UiccCard card = slot.getUiccCard();
8864 if (card != null) {
8865 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008866 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008867 cardId = slot.getEid();
8868 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008869 // If cardId is null, use iccId of default port as cardId. Check if has
8870 // read permission otherwise set to null.(card is null which means no
8871 // carrier permission)
8872 cardId = hasReadPermission ? slot.getIccId(
8873 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008875 }
8876
Jordan Liu857451f2019-05-09 16:35:35 -07008877 if (cardId != null) {
8878 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8879 // if cardId is an EID, it's all digits so this is fine
8880 cardId = IccUtils.stripTrailingFs(cardId);
8881 }
8882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008883 int cardState = 0;
8884 switch (slot.getCardState()) {
8885 case CARDSTATE_ABSENT:
8886 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8887 break;
8888 case CARDSTATE_PRESENT:
8889 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8890 break;
8891 case CARDSTATE_ERROR:
8892 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8893 break;
8894 case CARDSTATE_RESTRICTED:
8895 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8896 break;
8897 default:
8898 break;
8899
8900 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008901 List<UiccPortInfo> portInfos = new ArrayList<>();
8902 int[] portIndexes = slot.getPortList();
8903 for (int portIdx : portIndexes) {
8904 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8905 callingPackage, hasReadPermission));
8906 if (slot.isPortActive(portIdx)) {
8907 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8908 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8909 port.getPhoneId(), true));
8910 } else {
8911 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8912 }
8913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008914 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 slot.isEuicc(),
8916 cardId,
8917 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008918 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008919 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008920 //setting the value after compatibility check
8921 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008922 }
8923 return infos;
8924 } finally {
8925 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008926 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008927 }
8928
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008929 /* Returns null if doesn't have read permission or carrier privilege access. */
8930 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8931 boolean hasReadPermission) {
8932 String iccId = slot.getIccId(portIndex);
8933 if (hasReadPermission) { // if has read permission
8934 return iccId;
8935 } else {
8936 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8937 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8938 // if no read permission, checking carrier privilege access
8939 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8940 return iccId;
8941 }
8942 }
8943 }
8944 // No read permission or carrier privilege access.
8945 return UiccPortInfo.ICCID_REDACTED;
8946 }
8947
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008948 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008949 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008950 public boolean switchSlots(int[] physicalSlots) {
8951 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008952
8953 final long identity = Binder.clearCallingIdentity();
8954 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008955 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8956 for (int i = 0; i < physicalSlots.length; i++) {
8957 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8958 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8959 physicalSlots[i], i));
8960 }
8961 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 } finally {
8963 Binder.restoreCallingIdentity(identity);
8964 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008965 }
Jack Yu4c988042018-02-27 15:30:01 -08008966
8967 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008968 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8969 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8970 enforceModifyPermission();
8971
8972 final long identity = Binder.clearCallingIdentity();
8973 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008974 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00008975 } finally {
8976 Binder.restoreCallingIdentity(identity);
8977 }
8978 }
8979
8980 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008981 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 return UiccController.getInstance().getCardIdForDefaultEuicc();
8985 } finally {
8986 Binder.restoreCallingIdentity(identity);
8987 }
8988 }
8989
Pengquan Meng85728fb2018-03-12 16:31:21 -07008990 /**
goneil47ffb6e2018-04-06 15:40:58 -07008991 * A test API to reload the UICC profile.
8992 *
8993 * <p>Requires that the calling app has permission
8994 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8995 * @hide
8996 */
8997 @Override
8998 public void refreshUiccProfile(int subId) {
8999 enforceModifyPermission();
9000
9001 final long identity = Binder.clearCallingIdentity();
9002 try {
9003 Phone phone = getPhone(subId);
9004 if (phone == null) {
9005 return;
9006 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009007 UiccPort uiccPort = phone.getUiccPort();
9008 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009009 return;
9010 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009011 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009012 if (uiccProfile == null) {
9013 return;
9014 }
9015 uiccProfile.refresh();
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
9018 }
9019 }
9020
9021 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009022 * Returns false if the mobile data is disabled by default, otherwise return true.
9023 */
9024 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009025 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009026 }
9027
9028 /**
9029 * Returns true if the data roaming is enabled by default, i.e the system property
9030 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9031 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9032 */
9033 private boolean getDefaultDataRoamingEnabled(int subId) {
9034 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009035 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009036 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009037 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9038 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9039 return isDataRoamingEnabled;
9040 }
9041
9042 /**
9043 * Returns the default network type for the given {@code subId}, if the default network type is
9044 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9045 */
9046 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009047 List<Integer> list = TelephonyProperties.default_network();
9048 int phoneId = mSubscriptionController.getPhoneId(subId);
9049 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9050 return list.get(phoneId);
9051 }
9052 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009053 }
fionaxua13278b2018-03-21 00:08:13 -07009054
9055 @Override
9056 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009057 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009059
9060 final long identity = Binder.clearCallingIdentity();
9061 try {
9062 final Phone phone = getPhone(subId);
9063 if (phone == null) {
9064 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9065 return;
9066 }
chen xueaba88a2019-03-15 13:15:10 -07009067 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9068 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009069 if (carrierPrivilegeRules == null) {
9070 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9071 } else {
9072 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074 } finally {
9075 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009076 }
fionaxua13278b2018-03-21 00:08:13 -07009077 }
9078
9079 @Override
9080 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009081 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009082
9083 final long identity = Binder.clearCallingIdentity();
9084 try {
9085 final Phone phone = getPhone(subId);
9086 if (phone == null) {
9087 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9088 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9089 }
9090 return phone.getCarrierIdListVersion();
9091 } finally {
9092 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009093 }
fionaxua13278b2018-03-21 00:08:13 -07009094 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009095
9096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009097 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9098 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009100 mApp, subId, callingPackage, callingFeatureId,
9101 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009102 return -1;
9103 }
9104
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
9107 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9108 } finally {
9109 Binder.restoreCallingIdentity(identity);
9110 }
9111 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009112
9113 @Override
9114 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009115 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009116 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009117 mApp, subId, "getCdmaRoamingMode");
9118
9119 final long identity = Binder.clearCallingIdentity();
9120 try {
9121 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9122 } finally {
9123 Binder.restoreCallingIdentity(identity);
9124 }
9125 }
9126
9127 @Override
9128 public boolean setCdmaRoamingMode(int subId, int mode) {
9129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9130 mApp, subId, "setCdmaRoamingMode");
9131
9132 final long identity = Binder.clearCallingIdentity();
9133 try {
9134 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9135 } finally {
9136 Binder.restoreCallingIdentity(identity);
9137 }
9138 }
9139
9140 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009141 public int getCdmaSubscriptionMode(int subId) {
9142 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009143 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009144 mApp, subId, "getCdmaSubscriptionMode");
9145
9146 final long identity = Binder.clearCallingIdentity();
9147 try {
9148 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
9152 }
9153
9154 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009155 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9157 mApp, subId, "setCdmaSubscriptionMode");
9158
9159 final long identity = Binder.clearCallingIdentity();
9160 try {
9161 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
9165 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009166
sqianc5eccab2018-10-19 18:46:41 -07009167 @Override
sqian8c685422019-02-22 15:55:18 -08009168 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009169 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009171 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9172 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009173 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9174 }
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
sqian854d44b2018-12-12 16:48:18 -08009177 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9178 for (Phone phone: PhoneFactory.getPhones()) {
9179 if (phone.getEmergencyNumberTracker() != null
9180 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9181 emergencyNumberListInternal.put(
9182 phone.getSubId(),
9183 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9184 }
sqian11b7a0e2018-12-05 18:48:28 -08009185 }
sqian854d44b2018-12-12 16:48:18 -08009186 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
sqianc5eccab2018-10-19 18:46:41 -07009190 }
9191
9192 @Override
sqian8c685422019-02-22 15:55:18 -08009193 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009194 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009195 if (!exactMatch) {
9196 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009197 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009198 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009199 }
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
sqian854d44b2018-12-12 16:48:18 -08009202 for (Phone phone: PhoneFactory.getPhones()) {
9203 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009204 && phone.getEmergencyNumberTracker()
9205 .isEmergencyNumber(number, exactMatch)) {
9206 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009207 }
sqian11b7a0e2018-12-05 18:48:28 -08009208 }
9209 return false;
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
9214
sqianf4ca7ed2019-01-15 18:32:07 -08009215 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009216 * Start emergency callback mode for GsmCdmaPhone for testing.
9217 */
9218 @Override
9219 public void startEmergencyCallbackMode() {
9220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9221 "startEmergencyCallbackMode");
9222 enforceModifyPermission();
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 for (Phone phone : PhoneFactory.getPhones()) {
9226 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9227 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9228 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9229 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9230 gsmCdmaPhone.obtainMessage(
9231 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9232 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9233 }
9234 }
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
9240 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009241 * Update emergency number list for test mode.
9242 */
9243 @Override
9244 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9246 "updateEmergencyNumberListTestMode");
9247
9248 final long identity = Binder.clearCallingIdentity();
9249 try {
9250 for (Phone phone: PhoneFactory.getPhones()) {
9251 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9252 if (tracker != null) {
9253 tracker.executeEmergencyNumberTestModeCommand(action, num);
9254 }
9255 }
9256 } finally {
9257 Binder.restoreCallingIdentity(identity);
9258 }
9259 }
9260
9261 /**
9262 * Get the full emergency number list for test mode.
9263 */
9264 @Override
9265 public List<String> getEmergencyNumberListTestMode() {
9266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9267 "getEmergencyNumberListTestMode");
9268
9269 final long identity = Binder.clearCallingIdentity();
9270 try {
9271 Set<String> emergencyNumbers = new HashSet<>();
9272 for (Phone phone: PhoneFactory.getPhones()) {
9273 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9274 if (tracker != null) {
9275 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9276 emergencyNumbers.add(num.getNumber());
9277 }
9278 }
9279 }
9280 return new ArrayList<>(emergencyNumbers);
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 }
9285
chen xud6b45bd2018-10-30 22:27:10 -07009286 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009287 public int getEmergencyNumberDbVersion(int subId) {
9288 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9289
9290 final long identity = Binder.clearCallingIdentity();
9291 try {
9292 final Phone phone = getPhone(subId);
9293 if (phone == null) {
9294 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9295 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9296 }
9297 return phone.getEmergencyNumberDbVersion();
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
9302
9303 @Override
9304 public void notifyOtaEmergencyNumberDbInstalled() {
9305 enforceModifyPermission();
9306
9307 final long identity = Binder.clearCallingIdentity();
9308 try {
9309 for (Phone phone: PhoneFactory.getPhones()) {
9310 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9311 if (tracker != null) {
9312 tracker.updateOtaEmergencyNumberDatabase();
9313 }
9314 }
9315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
9319
9320 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009321 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009322 enforceActiveEmergencySessionPermission();
9323
9324 final long identity = Binder.clearCallingIdentity();
9325 try {
9326 for (Phone phone: PhoneFactory.getPhones()) {
9327 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9328 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009329 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9330 }
9331 }
9332 } finally {
9333 Binder.restoreCallingIdentity(identity);
9334 }
9335 }
9336
9337 @Override
9338 public void resetOtaEmergencyNumberDbFilePath() {
9339 enforceActiveEmergencySessionPermission();
9340
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 for (Phone phone: PhoneFactory.getPhones()) {
9344 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9345 if (tracker != null) {
9346 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009347 }
9348 }
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
9354 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009355 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9356 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9357 Phone phone = getPhone(subId);
9358 if (phone == null) {
9359 return null;
9360 }
9361 final long identity = Binder.clearCallingIdentity();
9362 try {
9363 UiccProfile profile = UiccController.getInstance()
9364 .getUiccProfileForPhone(phone.getPhoneId());
9365 if (profile != null) {
9366 return profile.getCertsFromCarrierPrivilegeAccessRules();
9367 }
9368 } finally {
9369 Binder.restoreCallingIdentity(identity);
9370 }
9371 return null;
9372 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009373
9374 /**
9375 * Enable or disable a modem stack.
9376 */
9377 @Override
9378 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9379 enforceModifyPermission();
9380
9381 final long identity = Binder.clearCallingIdentity();
9382 try {
9383 Phone phone = PhoneFactory.getPhone(slotIndex);
9384 if (phone == null) {
9385 return false;
9386 } else {
9387 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9388 }
9389 } finally {
9390 Binder.restoreCallingIdentity(identity);
9391 }
9392 }
Michelecea4cf22018-12-21 15:00:11 -08009393
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009394 /**
9395 * Whether a modem stack is enabled or not.
9396 */
9397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009398 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9399 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009400 Phone phone = PhoneFactory.getPhone(slotIndex);
9401 if (phone == null) return false;
9402
9403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009404 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9405 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009406 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9407 }
9408
9409 final long identity = Binder.clearCallingIdentity();
9410 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009411 try {
9412 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9413 } catch (NoSuchElementException ex) {
9414 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9415 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
9420
Michelecea4cf22018-12-21 15:00:11 -08009421 @Override
Michele0ea7d782019-03-19 14:58:42 -07009422 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009423 enforceModifyPermission();
9424
9425 final long identity = Binder.clearCallingIdentity();
9426 try {
9427 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009428 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009429 .commit();
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
9435 @Override
Michele0ea7d782019-03-19 14:58:42 -07009436 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009437 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009439 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9440 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009441 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009442 }
Michelecea4cf22018-12-21 15:00:11 -08009443
9444 final long identity = Binder.clearCallingIdentity();
9445 try {
Michele0ea7d782019-03-19 14:58:42 -07009446 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009447 } finally {
9448 Binder.restoreCallingIdentity(identity);
9449 }
9450 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009451
Michele0ea7d782019-03-19 14:58:42 -07009452 @TelephonyManager.IsMultiSimSupportedResult
9453 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009454 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9455 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9456 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009457 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9458 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009459 }
9460 // Check if the hardware supports multisim functionality. If usage of multisim is not
9461 // supported by the modem, indicate that it is restricted.
9462 PhoneCapability staticCapability =
9463 mPhoneConfigurationManager.getStaticPhoneCapability();
9464 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009465 loge("isMultiSimSupportedInternal: no static configuration available");
9466 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009467 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009468 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009469 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9470 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009471 }
9472 // Check if support of multiple SIMs is restricted by carrier
9473 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009474 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009475 }
9476
Michele0ea7d782019-03-19 14:58:42 -07009477 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009478 }
9479
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009480 /**
9481 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009482 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9483 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9484 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009485 * @param numOfSims number of active sims we want to switch to
9486 */
9487 @Override
9488 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009489 if (numOfSims == 1) {
9490 enforceModifyPermission();
9491 } else {
9492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9493 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9494 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009495 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009496
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009497 try {
Michele30b57b22019-03-01 12:01:14 -08009498 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009499 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009500 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9501 return;
9502 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009503 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9504 } finally {
9505 Binder.restoreCallingIdentity(identity);
9506 }
9507 }
9508
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009509 @Override
9510 public boolean isApplicationOnUicc(int subId, int appType) {
9511 enforceReadPrivilegedPermission("isApplicationOnUicc");
9512 Phone phone = getPhone(subId);
9513 if (phone == null) {
9514 return false;
9515 }
9516 final long identity = Binder.clearCallingIdentity();
9517 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009518 UiccPort uiccPort = phone.getUiccPort();
9519 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009520 return false;
9521 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009522 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009523 if (uiccProfile == null) {
9524 return false;
9525 }
9526 if (TelephonyManager.APPTYPE_SIM <= appType
9527 && appType <= TelephonyManager.APPTYPE_ISIM) {
9528 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9529 }
9530 return false;
9531 } finally {
9532 Binder.restoreCallingIdentity(identity);
9533 }
9534 }
9535
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009536 /**
chen xub4baa772019-04-03 10:23:41 -07009537 * Get whether making changes to modem configurations will trigger reboot.
9538 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009539 */
9540 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009541 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9542 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009544 mApp, subId, callingPackage, callingFeatureId,
9545 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009546 return false;
9547 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009548 final long identity = Binder.clearCallingIdentity();
9549 try {
9550 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 }
9555
Nathan Harold29f5f052019-02-15 13:41:57 -08009556 private void updateModemStateMetrics() {
9557 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9558 // TODO: check the state for each modem if the api is ready.
9559 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9560 }
9561
Pengquan Meng3889a572019-01-23 11:16:29 -08009562 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009563 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009564 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009565 // Verify that the callingPackage belongs to the calling UID
9566 mApp.getSystemService(AppOpsManager.class)
9567 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009568 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009569 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009570 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009571 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9572 if (slotInfos != null) {
9573 for (int i = 0; i < slotInfos.length; i++) {
9574 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9575 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9576 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9577 portInfo.getLogicalSlotIndex()));
9578 }
9579 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009580 }
9581 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009582 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009587
9588 /**
9589 * Get the IRadio HAL Version
9590 */
9591 @Override
9592 public int getRadioHalVersion() {
9593 Phone phone = getDefaultPhone();
9594 if (phone == null) return -1;
9595 HalVersion hv = phone.getHalVersion();
9596 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9597 return hv.major * 100 + hv.minor;
9598 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009599
9600 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009601 * Get the current calling package name.
9602 * @return the current calling package name
9603 */
9604 @Override
9605 public String getCurrentPackageName() {
9606 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9607 }
9608
9609 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009610 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9611 * corresponding network requests on a subId.
9612 *
9613 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009614 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009615 * 2) APN is un-metered for this subscription, or
9616 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009617 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009618 *
9619 * @return whether data is allowed for a apn type.
9620 *
9621 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009622 */
9623 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009624 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009625 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9626 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009627
9628 // Now that all security checks passes, perform the operation as ourselves.
9629 final long identity = Binder.clearCallingIdentity();
9630 try {
9631 Phone phone = getPhone(subId);
9632 if (phone == null) return false;
9633
Jack Yu41407ee2019-05-13 16:54:09 -07009634 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009635 boolean isDataEnabled;
9636 if (phone.isUsingNewDataStack()) {
9637 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9638 } else {
9639 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9640 }
9641 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009642 } finally {
9643 Binder.restoreCallingIdentity(identity);
9644 }
9645 }
9646
9647 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009648 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009649 enforceReadPrivilegedPermission("isApnMetered");
9650
9651 // Now that all security checks passes, perform the operation as ourselves.
9652 final long identity = Binder.clearCallingIdentity();
9653 try {
9654 Phone phone = getPhone(subId);
9655 if (phone == null) return true; // By default return true.
9656
Jack Yu41407ee2019-05-13 16:54:09 -07009657 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009658 } finally {
9659 Binder.restoreCallingIdentity(identity);
9660 }
9661 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009662
9663 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009664 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9665 int subscriptionId, IBooleanConsumer resultCallback) {
9666 enforceModifyPermission();
9667 long token = Binder.clearCallingIdentity();
9668 try {
9669 Phone phone = getPhone(subscriptionId);
9670 if (phone == null) {
9671 try {
9672 if (resultCallback != null) {
9673 resultCallback.accept(false);
9674 }
9675 } catch (RemoteException e) {
9676 // ignore
9677 }
9678 return;
9679 }
9680 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9681 Pair.create(specifiers, (x) -> {
9682 try {
9683 if (resultCallback != null) {
9684 resultCallback.accept(x);
9685 }
9686 } catch (RemoteException e) {
9687 // ignore
9688 }
9689 });
9690 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9691 } finally {
9692 Binder.restoreCallingIdentity(token);
9693 }
9694 }
9695
9696 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009697 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9698 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009699 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009700 mApp, subId, "getSystemSelectionChannels");
9701 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9702 final long identity = Binder.clearCallingIdentity();
9703 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009704 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9705 if (result instanceof IllegalStateException) {
9706 throw (IllegalStateException) result;
9707 }
9708 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009709 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9710 return specifiers;
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715
9716 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009717 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009718 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009719 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9720 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9721 if (iccRecords == null) {
9722 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9723 return false;
9724 }
9725 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9726 }
9727
9728 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009729 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9730 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009731 if (callingPackage == null) {
9732 callingPackage = getCurrentPackageName();
9733 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009734 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9735 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009736 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9737 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009738 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9739 }
9740 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9741 Intent intent = new Intent();
9742 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9743 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9744 // Bring up choose default SMS subscription dialog right now
9745 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9746 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9747 mApp.startActivity(intent);
9748 }
chen xud5ca2d52019-05-28 15:20:57 -07009749
9750 @Override
9751 public String getMmsUAProfUrl(int subId) {
9752 //TODO investigate if this API should require proper permission check in R b/133791609
9753 final long identity = Binder.clearCallingIdentity();
9754 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009755 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9756 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9757 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9758 return carrierUAProfUrl;
9759 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009760 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9761 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009762 } finally {
9763 Binder.restoreCallingIdentity(identity);
9764 }
9765 }
9766
9767 @Override
9768 public String getMmsUserAgent(int subId) {
9769 //TODO investigate if this API should require proper permission check in R b/133791609
9770 final long identity = Binder.clearCallingIdentity();
9771 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009772 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9773 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9774 if (!TextUtils.isEmpty(carrierUserAgent)) {
9775 return carrierUserAgent;
9776 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009777 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9778 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
Jack Yub07d4972019-05-28 16:12:25 -07009783
9784 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009785 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9786 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009787
Jack Yub07d4972019-05-28 16:12:25 -07009788 final long identity = Binder.clearCallingIdentity();
9789 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009790 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009791 if (phone == null) return false;
9792
Hall Liua62f5da2020-09-25 10:42:19 -07009793 switch (policy) {
9794 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009795 if (phone.isUsingNewDataStack()) {
9796 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9797 } else {
9798 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9799 }
Hall Liua62f5da2020-09-25 10:42:19 -07009800 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009801 if (phone.isUsingNewDataStack()) {
9802 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9803 } else {
9804 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9805 }
Hall Liua62f5da2020-09-25 10:42:19 -07009806 default:
9807 throw new IllegalArgumentException(policy + " is not a valid policy");
9808 }
Jack Yub07d4972019-05-28 16:12:25 -07009809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 }
9813
9814 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009815 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009816 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009817 enforceModifyPermission();
9818
changbettyd5c246e2019-12-24 15:40:37 +08009819 final long identity = Binder.clearCallingIdentity();
9820 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009821 Phone phone = getPhone(subscriptionId);
9822 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009823
Hall Liua62f5da2020-09-25 10:42:19 -07009824 switch (policy) {
9825 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009826 if (phone.isUsingNewDataStack()) {
9827 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9828 } else {
9829 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9830 }
Hall Liua62f5da2020-09-25 10:42:19 -07009831 break;
9832 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009833 if (phone.isUsingNewDataStack()) {
9834 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9835 } else {
9836 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9837 }
Hall Liua62f5da2020-09-25 10:42:19 -07009838 break;
9839 default:
9840 throw new IllegalArgumentException(policy + " is not a valid policy");
9841 }
changbettyd5c246e2019-12-24 15:40:37 +08009842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
9846
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009847 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009848 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009849 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9850 * otherwise.
9851 */
9852 @Override
9853 public void setCepEnabled(boolean isCepEnabled) {
9854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9855
9856 final long identity = Binder.clearCallingIdentity();
9857 try {
9858 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9859 for (Phone phone : PhoneFactory.getPhones()) {
9860 Phone defaultPhone = phone.getImsPhone();
9861 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9862 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9863 ImsPhoneCallTracker imsPhoneCallTracker =
9864 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9865 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9866 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9867 + imsPhone.getMsisdn());
9868 }
9869 }
9870 } finally {
9871 Binder.restoreCallingIdentity(identity);
9872 }
9873 }
allenwtsu46dcc572020-01-08 18:24:03 +08009874
9875 /**
9876 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9877 *
9878 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9879 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9880 * before being read.
9881 */
9882 @Override
9883 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9884 isCompressed) {
9885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9886 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9888 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9889 }
9890 if (!isImsAvailableOnDevice()) {
9891 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9892 "IMS not available on device.");
9893 }
9894
9895 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009896 try {
Hui Wang761a6682020-10-31 05:12:53 +00009897 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9898 } finally {
9899 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009900 }
9901 }
zoey chene02881a2019-12-30 16:11:23 +08009902
9903 @Override
9904 public boolean isIccLockEnabled(int subId) {
9905 enforceReadPrivilegedPermission("isIccLockEnabled");
9906
9907 // Now that all security checks passes, perform the operation as ourselves.
9908 final long identity = Binder.clearCallingIdentity();
9909 try {
9910 Phone phone = getPhone(subId);
9911 if (phone != null && phone.getIccCard() != null) {
9912 return phone.getIccCard().getIccLockEnabled();
9913 } else {
9914 return false;
9915 }
9916 } finally {
9917 Binder.restoreCallingIdentity(identity);
9918 }
9919 }
9920
9921 /**
9922 * Set the ICC pin lock enabled or disabled.
9923 *
9924 * @return an integer representing the status of IccLock enabled or disabled in the following
9925 * three cases:
9926 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9927 * successfully.
9928 * - Positive number and zero for remaining password attempts.
9929 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9930 *
9931 */
9932 @Override
9933 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9934 enforceModifyPermission();
9935
9936 Phone phone = getPhone(subId);
9937 if (phone == null) {
9938 return 0;
9939 }
9940 // Now that all security checks passes, perform the operation as ourselves.
9941 final long identity = Binder.clearCallingIdentity();
9942 try {
9943 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9944 new Pair<Boolean, String>(enabled, password), phone, null);
9945 return attemptsRemaining;
9946
9947 } catch (Exception e) {
9948 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 return 0;
9953 }
9954
9955 /**
9956 * Change the ICC password used in ICC pin lock.
9957 *
9958 * @return an integer representing the status of IccLock changed in the following three cases:
9959 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9960 * - Positive number and zero for remaining password attempts.
9961 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9962 *
9963 */
9964 @Override
9965 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9966 enforceModifyPermission();
9967
9968 Phone phone = getPhone(subId);
9969 if (phone == null) {
9970 return 0;
9971 }
9972 // Now that all security checks passes, perform the operation as ourselves.
9973 final long identity = Binder.clearCallingIdentity();
9974 try {
9975 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9976 new Pair<String, String>(oldPassword, newPassword), phone, null);
9977 return attemptsRemaining;
9978
9979 } catch (Exception e) {
9980 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 return 0;
9985 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009986
9987 /**
9988 * Request for receiving user activity notification
9989 */
9990 @Override
9991 public void requestUserActivityNotification() {
9992 if (!mNotifyUserActivity.get()
9993 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9994 mNotifyUserActivity.set(true);
9995 }
9996 }
9997
9998 /**
9999 * Called when userActivity is signalled in the power manager.
10000 * This is safe to call from any thread, with any window manager locks held or not.
10001 */
10002 @Override
10003 public void userActivity() {
10004 // ***************************************
10005 // * Inherited from PhoneWindowManager *
10006 // ***************************************
10007 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10008 // WITH ITS LOCKS HELD.
10009 //
10010 // This code must be VERY careful about the locks
10011 // it acquires.
10012 // In fact, the current code acquires way too many,
10013 // and probably has lurking deadlocks.
10014
10015 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10016 throw new SecurityException("Only the OS may call notifyUserActivity()");
10017 }
10018
10019 if (mNotifyUserActivity.getAndSet(false)) {
10020 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10021 USER_ACTIVITY_NOTIFICATION_DELAY);
10022 }
10023 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010024
10025 @Override
10026 public boolean canConnectTo5GInDsdsMode() {
10027 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10028 }
Jack Yud10cdd42020-09-28 20:28:01 -070010029
10030 @Override
10031 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10032 String callingFeatureId) {
10033 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10034 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10035 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10036 }
10037
10038 Phone phone = getPhone(subId);
10039 if (phone == null) {
10040 throw new RuntimeException("phone is not available");
10041 }
10042 // Now that all security checks passes, perform the operation as ourselves.
10043 final long identity = Binder.clearCallingIdentity();
10044 try {
10045 return phone.getEquivalentHomePlmns();
10046 } finally {
10047 Binder.restoreCallingIdentity(identity);
10048 }
10049 }
Daniel Bright59e67312020-11-13 11:49:37 -080010050
10051 @Override
10052 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010053 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10054 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010055 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010056 if (radioInterfaceCapabilities == null) {
10057 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010058 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010059 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010060 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010061
Hui Wang641e81c2020-10-12 12:14:23 -070010062 @Override
10063 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10064 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010065 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10066 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10067 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10068 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10069 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010070 if (DBG) {
10071 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10072 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10073 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10074 }
10075
10076 if (!SubscriptionManager.isValidSubscriptionId(subId)
10077 || appType < TelephonyManager.APPTYPE_UNKNOWN
10078 || appType > TelephonyManager.APPTYPE_ISIM
10079 || nafUrl == null || securityProtocol == null || callback == null) {
10080 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10081 if (callback != null) {
10082 try {
10083 callback.onAuthenticationFailure(
10084 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10085 } catch (RemoteException exception) {
10086 log("Fail to notify onAuthenticationFailure due to " + exception);
10087 }
10088 return;
10089 }
10090 }
10091
10092 final long token = Binder.clearCallingIdentity();
10093 try {
10094 getGbaManager(subId).bootstrapAuthenticationRequest(
10095 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10096 forceBootStrapping, callback));
10097 } finally {
10098 Binder.restoreCallingIdentity(token);
10099 }
10100 }
10101
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010102 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010103 * Attempts to set the radio power state for all phones for thermal reason.
10104 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010105 * requested radio power state will actually be set. See {@link
10106 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10107 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010108 * @param enable {@code true} if trying to turn radio on.
10109 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10110 * false}.
10111 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010112 private boolean setRadioPowerForThermal(boolean enable) {
10113 boolean isPhoneAvailable = false;
10114 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10115 Phone phone = PhoneFactory.getPhone(i);
10116 if (phone != null) {
10117 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10118 isPhoneAvailable = true;
10119 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010120 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010121
10122 // return true if successfully informed the phone object about the thermal radio power
10123 // request.
10124 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010125 }
10126
10127 private int handleDataThrottlingRequest(int subId,
10128 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010129 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10130 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10131 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10132 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10133 throw new IllegalArgumentException("modem does not support data throttling");
10134 }
10135
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010136 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10137 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010138 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010139 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10140 }
10141
10142 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10143
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010144 if (isDataThrottlingSupported) {
10145 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010146 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010147 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10148 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10149 } else if (thermalMitigationResult
10150 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010151 log("Modem likely does not support data throttling on secondary carrier. Data " +
10152 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10153 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010154 }
10155 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010156 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010157
10158 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010159 }
10160
Jack Nudelman644b91a2021-03-12 14:09:48 -080010161 private static List<String> getThermalMitigationAllowlist(Context context) {
10162 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10163 for (String pckg : context.getResources()
10164 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10165 sThermalMitigationAllowlistedPackages.add(pckg);
10166 }
10167 }
10168
10169 return sThermalMitigationAllowlistedPackages;
10170 }
10171
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010172 private boolean isAnyPhoneInEmergencyState() {
10173 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10174 if (tm.isInEmergencyCall()) {
10175 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10176 return true;
10177 }
10178 for (Phone phone : PhoneFactory.getPhones()) {
10179 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10180 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10181 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10182 + phone.isInEcm());
10183 return true;
10184 }
10185 }
10186
10187 return false;
10188 }
10189
Jack Nudelman644b91a2021-03-12 14:09:48 -080010190 /**
10191 * Used by shell commands to add an authorized package name for thermal mitigation.
10192 * @param packageName name of package to be allowlisted
10193 * @param context
10194 */
10195 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10196 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10197 sThermalMitigationAllowlistedPackages.add(packageName);
10198 }
10199
10200 /**
10201 * Used by shell commands to remove an authorized package name for thermal mitigation.
10202 * @param packageName name of package to remove from allowlist
10203 * @param context
10204 */
10205 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10206 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10207 sThermalMitigationAllowlistedPackages.remove(packageName);
10208 }
10209
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010210 /**
10211 * Thermal mitigation request to control functionalities at modem.
10212 *
10213 * @param subId the id of the subscription.
10214 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010215 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010216 *
10217 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10218 */
10219 @Override
10220 @ThermalMitigationResult
10221 public int sendThermalMitigationRequest(
10222 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010223 ThermalMitigationRequest thermalMitigationRequest,
10224 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010225 enforceModifyPermission();
10226
Jack Nudelman644b91a2021-03-12 14:09:48 -080010227 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10228 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10229 .contains(callingPackage)) {
10230 throw new SecurityException("Calling package must be configured in the device config. "
10231 + "calling package: " + callingPackage);
10232 }
10233
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10235 final long identity = Binder.clearCallingIdentity();
10236
10237 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10238 try {
10239 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10240 switch (thermalMitigationAction) {
10241 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10242 thermalMitigationResult =
10243 handleDataThrottlingRequest(subId,
10244 thermalMitigationRequest.getDataThrottlingRequest());
10245 break;
10246 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10247 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10248 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10249 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10250 }
10251
10252 // Ensure that radio is on. If not able to power on due to phone being
10253 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010254 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010255 thermalMitigationResult =
10256 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10257 break;
10258 }
10259
10260 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10261 false);
10262 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10263 break;
10264 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10265 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10266 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10267 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10268 }
10269
10270 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10271 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010272 Phone phone = getPhone(subId);
10273 if (phone == null) {
10274 thermalMitigationResult =
10275 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10276 break;
10277 }
10278
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010279 TelephonyConnectionService service =
10280 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010281 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010282 Log.e(LOG_TAG, "An emergency call is pending");
10283 thermalMitigationResult =
10284 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10285 break;
10286 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010287 thermalMitigationResult =
10288 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10289 break;
10290 }
10291 } else {
10292 thermalMitigationResult =
10293 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10294 break;
10295 }
10296
10297 // Turn radio off. If not able to power off due to phone being unavailable,
10298 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010299 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010300 thermalMitigationResult =
10301 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10302 break;
10303 }
10304 thermalMitigationResult =
10305 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10306 break;
10307 default:
10308 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10309 + "not exist. Requested action: " + thermalMitigationAction);
10310 }
10311 } catch (IllegalArgumentException e) {
10312 throw e;
10313 } catch (Exception e) {
10314 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10315 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319
10320 if (DBG) {
10321 log("thermalMitigationRequest returning with thermalMitigationResult: "
10322 + thermalMitigationResult);
10323 }
10324
10325 return thermalMitigationResult;
10326 }
Hui Wang641e81c2020-10-12 12:14:23 -070010327
10328 /**
10329 * Set the GbaService Package Name that Telephony will bind to.
10330 *
10331 * @param subId The sim that the GbaService is associated with.
10332 * @param packageName The name of the package to be replaced with.
10333 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10334 */
10335 @Override
10336 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10337 enforceModifyPermission();
10338
10339 final long identity = Binder.clearCallingIdentity();
10340 try {
10341 return getGbaManager(subId).overrideServicePackage(packageName);
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
10346
10347 /**
10348 * Return the package name of the currently bound GbaService.
10349 *
10350 * @param subId The sim that the GbaService is associated with.
10351 * @return the package name of the GbaService configuration, null if GBA is not supported.
10352 */
10353 @Override
10354 public String getBoundGbaService(int subId) {
10355 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10356
10357 final long identity = Binder.clearCallingIdentity();
10358 try {
10359 return getGbaManager(subId).getServicePackage();
10360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
10364
10365 /**
10366 * Set the release time for telephony to unbind GbaService.
10367 *
10368 * @param subId The sim that the GbaService is associated with.
10369 * @param interval The release time to unbind GbaService by millisecond.
10370 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10371 */
10372 @Override
10373 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10374 enforceModifyPermission();
10375
10376 final long identity = Binder.clearCallingIdentity();
10377 try {
10378 return getGbaManager(subId).overrideReleaseTime(interval);
10379 } finally {
10380 Binder.restoreCallingIdentity(identity);
10381 }
10382 }
10383
10384 /**
10385 * Return the release time for telephony to unbind GbaService.
10386 *
10387 * @param subId The sim that the GbaService is associated with.
10388 * @return The release time to unbind GbaService by millisecond.
10389 */
10390 @Override
10391 public int getGbaReleaseTime(int subId) {
10392 enforceReadPrivilegedPermission("getGbaReleaseTime");
10393
10394 final long identity = Binder.clearCallingIdentity();
10395 try {
10396 return getGbaManager(subId).getReleaseTime();
10397 } finally {
10398 Binder.restoreCallingIdentity(identity);
10399 }
10400 }
10401
10402 private GbaManager getGbaManager(int subId) {
10403 GbaManager instance = GbaManager.getInstance(subId);
10404 if (instance == null) {
10405 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10406 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10407 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10408 }
10409 return instance;
10410 }
Hui Wang761a6682020-10-31 05:12:53 +000010411
10412 /**
10413 * indicate whether the device and the carrier can support
10414 * RCS VoLTE single registration.
10415 */
10416 @Override
10417 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010418 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10419 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10420 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10421 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010422
10423 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10424 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10425 }
10426
10427 final long identity = Binder.clearCallingIdentity();
10428 try {
10429 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10430 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010431 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10432 if (isCapable != null) {
10433 return isCapable;
10434 }
Hui Wang761a6682020-10-31 05:12:53 +000010435 }
Hui Wang67af90e2021-06-04 16:57:15 -070010436 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10437 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010438 } finally {
10439 Binder.restoreCallingIdentity(identity);
10440 }
10441 }
10442
10443 /**
10444 * Register RCS provisioning callback.
10445 */
10446 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010447 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010448 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010449 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010450 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010451 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10452 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010453
10454 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10455 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10456 }
10457 if (!isImsAvailableOnDevice()) {
10458 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10459 "IMS not available on device.");
10460 }
10461
10462 final long identity = Binder.clearCallingIdentity();
10463 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010464 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010465 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010466 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10467 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010468 }
Hui Wang761a6682020-10-31 05:12:53 +000010469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
10473
10474 /**
10475 * Unregister RCS provisioning callback.
10476 */
10477 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010478 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010479 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010480 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010481 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010482 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10483 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010484
10485 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10486 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10487 }
10488 if (!isImsAvailableOnDevice()) {
10489 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10490 "IMS not available on device.");
10491 }
10492
10493 final long identity = Binder.clearCallingIdentity();
10494 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010495 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010496 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010497 } finally {
10498 Binder.restoreCallingIdentity(identity);
10499 }
10500 }
10501
10502 /**
10503 * trigger RCS reconfiguration.
10504 */
10505 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010506 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10507 "triggerRcsReconfiguration",
10508 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010509
10510 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10511 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10512 }
10513 if (!isImsAvailableOnDevice()) {
10514 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10515 "IMS not available on device.");
10516 }
10517
10518 final long identity = Binder.clearCallingIdentity();
10519 try {
10520 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10521 } finally {
10522 Binder.restoreCallingIdentity(identity);
10523 }
10524 }
10525
10526 /**
10527 * Provide the client configuration parameters of the RCS application.
10528 */
10529 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010530 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10531 "setRcsClientConfiguration",
10532 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010533
10534 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10535 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10536 }
10537 if (!isImsAvailableOnDevice()) {
10538 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10539 "IMS not available on device.");
10540 }
10541
10542 final long identity = Binder.clearCallingIdentity();
10543
10544 try {
10545 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10546 if (configBinder == null) {
10547 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010548 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10549 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010550 } else {
10551 configBinder.setRcsClientConfiguration(rcc);
10552 }
joonhunshinfa314642021-09-17 06:33:39 +000010553
10554 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10555 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010556 } catch (RemoteException e) {
10557 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010558 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10559 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010560 } finally {
10561 Binder.restoreCallingIdentity(identity);
10562 }
10563 }
10564
10565 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010566 * Enables or disables the test mode for RCS VoLTE single registration.
10567 */
10568 @Override
10569 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10570 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10571 "setRcsSingleRegistrationTestModeEnabled");
10572
10573 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10574 }
10575
10576 /**
10577 * Gets the test mode for RCS VoLTE single registration.
10578 */
10579 @Override
10580 public boolean getRcsSingleRegistrationTestModeEnabled() {
10581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10582 "getRcsSingleRegistrationTestModeEnabled");
10583
10584 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10585 }
10586
10587 /**
Hui Wang761a6682020-10-31 05:12:53 +000010588 * Overrides the config of RCS VoLTE single registration enabled for the device.
10589 */
10590 @Override
10591 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10592 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10593 "setDeviceSingleRegistrationEnabledOverride");
10594 enforceModifyPermission();
10595
10596 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10597 : Boolean.parseBoolean(enabledStr);
10598 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010599 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010600 }
10601
10602 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010603 * Sends a device to device communication message. Only usable via shell.
10604 * @param message message to send.
10605 * @param value message value.
10606 */
10607 @Override
10608 public void sendDeviceToDeviceMessage(int message, int value) {
10609 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010610 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010611 enforceModifyPermission();
10612
10613 final long identity = Binder.clearCallingIdentity();
10614 try {
10615 TelephonyConnectionService service =
10616 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10617 if (service == null) {
10618 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10619 return;
10620 }
10621 service.sendTestDeviceToDeviceMessage(message, value);
10622 } finally {
10623 Binder.restoreCallingIdentity(identity);
10624 }
10625 }
10626
Tyler Gunnbabbda02021-02-10 11:05:02 -080010627 /**
10628 * Sets the specified device to device transport active.
10629 * @param transport The transport to set active.
10630 */
10631 @Override
10632 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10633 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10634 "setActiveDeviceToDeviceTransport");
10635 enforceModifyPermission();
10636
10637 final long identity = Binder.clearCallingIdentity();
10638 try {
10639 TelephonyConnectionService service =
10640 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10641 if (service == null) {
10642 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10643 return;
10644 }
10645 service.setActiveDeviceToDeviceTransport(transport);
10646 } finally {
10647 Binder.restoreCallingIdentity(identity);
10648 }
10649 }
Tyler Gunn92479152021-01-20 16:30:10 -080010650
Tyler Gunnd4575212021-05-03 14:46:49 -070010651 @Override
10652 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10653 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10654 "setDeviceToDeviceForceEnabled");
10655
10656 final long identity = Binder.clearCallingIdentity();
10657 try {
10658 Arrays.stream(PhoneFactory.getPhones()).forEach(
10659 p -> {
10660 Phone thePhone = p.getImsPhone();
10661 if (thePhone != null && thePhone instanceof ImsPhone) {
10662 ImsPhone imsPhone = (ImsPhone) thePhone;
10663 CallTracker tracker = imsPhone.getCallTracker();
10664 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10665 ImsPhoneCallTracker imsPhoneCallTracker =
10666 (ImsPhoneCallTracker) tracker;
10667 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10668 }
10669 }
10670 }
10671 );
10672 } finally {
10673 Binder.restoreCallingIdentity(identity);
10674 }
10675 }
10676
Tyler Gunn92479152021-01-20 16:30:10 -080010677 /**
Hui Wang761a6682020-10-31 05:12:53 +000010678 * Gets the config of RCS VoLTE single registration enabled for the device.
10679 */
10680 @Override
10681 public boolean getDeviceSingleRegistrationEnabled() {
10682 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10683 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10684 }
10685
10686 /**
10687 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10688 */
10689 @Override
10690 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10691 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10692 "setCarrierSingleRegistrationEnabledOverride");
10693 enforceModifyPermission();
10694
10695 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10696 : Boolean.parseBoolean(enabledStr);
10697 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10698 subId, enabled);
10699 }
10700
10701 /**
10702 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10703 */
10704 @Override
10705 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10706 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10707 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10708 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010709
10710 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010711 * Overrides the ims feature validation result
10712 */
10713 @Override
10714 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10716 "setImsFeatureValidationOverride");
10717
10718 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10719 : Boolean.parseBoolean(enabledStr);
10720 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10721 subId, enabled);
10722 }
10723
10724 /**
10725 * Gets the ims feature validation override value
10726 */
10727 @Override
10728 public boolean getImsFeatureValidationOverride(int subId) {
10729 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10730 "getImsFeatureValidationOverride");
10731 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10732 }
10733
10734 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010735 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10736 * their mobile plan.
10737 */
10738 @Override
10739 public String getMobileProvisioningUrl() {
10740 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10741 final long identity = Binder.clearCallingIdentity();
10742 try {
10743 return getDefaultPhone().getMobileProvisioningUrl();
10744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010748
James.cf Linbcdf8b32021-01-14 16:44:13 +080010749 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010750 * Get the EAB contact from the EAB database.
10751 */
10752 @Override
10753 public String getContactFromEab(String contact) {
10754 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10755 enforceModifyPermission();
10756 final long identity = Binder.clearCallingIdentity();
10757 try {
10758 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10759 } finally {
10760 Binder.restoreCallingIdentity(identity);
10761 }
10762 }
10763
10764 /**
Calvin Pana1434322021-07-01 19:27:01 +080010765 * Get the EAB capability from the EAB database.
10766 */
10767 @Override
10768 public String getCapabilityFromEab(String contact) {
10769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10770 enforceModifyPermission();
10771 final long identity = Binder.clearCallingIdentity();
10772 try {
10773 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10774 } finally {
10775 Binder.restoreCallingIdentity(identity);
10776 }
10777 }
10778
10779 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010780 * Remove the EAB contacts from the EAB database.
10781 */
10782 @Override
10783 public int removeContactFromEab(int subId, String contacts) {
10784 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10785 enforceModifyPermission();
10786 final long identity = Binder.clearCallingIdentity();
10787 try {
10788 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10789 } finally {
10790 Binder.restoreCallingIdentity(identity);
10791 }
10792 }
10793
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010794 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010795 public boolean getDeviceUceEnabled() {
10796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 return mApp.getDeviceUceEnabled();
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
10804
10805 @Override
10806 public void setDeviceUceEnabled(boolean isEnabled) {
10807 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10808 final long identity = Binder.clearCallingIdentity();
10809 try {
10810 mApp.setDeviceUceEnabled(isEnabled);
10811 } finally {
10812 Binder.restoreCallingIdentity(identity);
10813 }
10814 }
10815
Brad Ebinger14d467f2021-02-12 06:18:28 +000010816 /**
10817 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10818 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10819 */
10820 // Used for SHELL command only right now.
10821 @Override
10822 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10823 List<String> featureTags) {
10824 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10825 "addUceRegistrationOverrideShell");
10826 final long identity = Binder.clearCallingIdentity();
10827 try {
10828 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10829 new ArraySet<>(featureTags));
10830 } catch (ImsException e) {
10831 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10832 } finally {
10833 Binder.restoreCallingIdentity(identity);
10834 }
10835 }
10836
10837 /**
10838 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10839 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10840 */
10841 // Used for SHELL command only right now.
10842 @Override
10843 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10844 List<String> featureTags) {
10845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10846 "removeUceRegistrationOverrideShell");
10847 final long identity = Binder.clearCallingIdentity();
10848 try {
10849 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10850 new ArraySet<>(featureTags));
10851 } catch (ImsException e) {
10852 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10853 } finally {
10854 Binder.restoreCallingIdentity(identity);
10855 }
10856 }
10857
10858 /**
10859 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10860 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10861 */
10862 // Used for SHELL command only right now.
10863 @Override
10864 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10866 "clearUceRegistrationOverrideShell");
10867 final long identity = Binder.clearCallingIdentity();
10868 try {
10869 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10870 } catch (ImsException e) {
10871 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10872 } finally {
10873 Binder.restoreCallingIdentity(identity);
10874 }
10875 }
10876
10877 /**
10878 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10879 */
10880 // Used for SHELL command only right now.
10881 @Override
10882 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10884 "getLatestRcsContactUceCapabilityShell");
10885 final long identity = Binder.clearCallingIdentity();
10886 try {
10887 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10888 } catch (ImsException e) {
10889 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10890 } finally {
10891 Binder.restoreCallingIdentity(identity);
10892 }
10893 }
10894
10895 /**
10896 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10897 * device does not have an active PUBLISH.
10898 */
10899 // Used for SHELL command only right now.
10900 @Override
10901 public String getLastUcePidfXmlShell(int subId) {
10902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10903 final long identity = Binder.clearCallingIdentity();
10904 try {
10905 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10906 } catch (ImsException e) {
10907 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
10912
James.cf Line8713a42021-04-29 16:04:26 +080010913 /**
10914 * Remove UCE requests cannot be sent to the network status.
10915 */
10916 // Used for SHELL command only right now.
10917 @Override
10918 public boolean removeUceRequestDisallowedStatus(int subId) {
10919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10920 final long identity = Binder.clearCallingIdentity();
10921 try {
10922 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10923 } catch (ImsException e) {
10924 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10925 } finally {
10926 Binder.restoreCallingIdentity(identity);
10927 }
10928 }
10929
James.cf Lin0fc71b02021-05-25 01:37:38 +080010930 /**
10931 * Remove UCE requests cannot be sent to the network status.
10932 */
10933 // Used for SHELL command only.
10934 @Override
10935 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10936 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10937 final long identity = Binder.clearCallingIdentity();
10938 try {
10939 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10940 } catch (ImsException e) {
10941 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10942 } finally {
10943 Binder.restoreCallingIdentity(identity);
10944 }
10945 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010946
James.cf Lin4b784aa2021-01-31 03:25:15 +080010947 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010948 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10949 String callingPackage) {
10950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10951 mApp, subId, "setSignalStrengthUpdateRequest");
10952
10953 final int callingUid = Binder.getCallingUid();
10954 // Verify that tha callingPackage belongs to the calling UID
10955 mApp.getSystemService(AppOpsManager.class)
10956 .checkPackage(callingUid, callingPackage);
10957
Rambo Wang3607f502021-02-01 21:51:40 -080010958 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010959
10960 final long identity = Binder.clearCallingIdentity();
10961 try {
10962 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10963 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10964
10965 if (result instanceof IllegalStateException) {
10966 throw (IllegalStateException) result;
10967 }
10968 } finally {
10969 Binder.restoreCallingIdentity(identity);
10970 }
10971 }
10972
10973 @Override
10974 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10975 String callingPackage) {
10976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10977 mApp, subId, "clearSignalStrengthUpdateRequest");
10978
10979 final int callingUid = Binder.getCallingUid();
10980 // Verify that tha callingPackage belongs to the calling UID
10981 mApp.getSystemService(AppOpsManager.class)
10982 .checkPackage(callingUid, callingPackage);
10983
10984 final long identity = Binder.clearCallingIdentity();
10985 try {
10986 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10987 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10988
10989 if (result instanceof IllegalStateException) {
10990 throw (IllegalStateException) result;
10991 }
10992 } finally {
10993 Binder.restoreCallingIdentity(identity);
10994 }
10995 }
10996
Rambo Wang3607f502021-02-01 21:51:40 -080010997 private static void validateSignalStrengthUpdateRequest(Context context,
10998 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010999 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11000 // phone/system process do not have further restriction on request
11001 return;
11002 }
11003
11004 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011005 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011006 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011007 context.enforceCallingOrSelfPermission(
11008 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11009 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011010 }
11011
11012 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11013 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11014 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11015 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11016 || info.isEnabled()) {
11017 throw new IllegalArgumentException(
11018 "Only system can set hide fields in SignalThresholdInfo");
11019 }
11020
11021 // Thresholds length for each RAN need in range. This has been validated in
11022 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11023 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11024 final int[] thresholds = info.getThresholds();
11025 Objects.requireNonNull(thresholds);
11026 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11027 || thresholds.length
11028 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11029 throw new IllegalArgumentException(
11030 "thresholds length is out of range: " + thresholds.length);
11031 }
11032 }
11033 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011034
11035 /**
11036 * Gets the current phone capability.
11037 *
11038 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11039 * @return the PhoneCapability which describes the data connection capability of modem.
11040 * It's used to evaluate possible phone config change, for example from single
11041 * SIM device to multi-SIM device.
11042 */
11043 @Override
11044 public PhoneCapability getPhoneCapability() {
11045 enforceReadPrivilegedPermission("getPhoneCapability");
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
11048 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11049 } finally {
11050 Binder.restoreCallingIdentity(identity);
11051 }
11052 }
Michele Berionne5e411512020-11-13 02:36:59 +000011053
11054 /**
11055 * Prepare TelephonyManager for an unattended reboot. The reboot is
11056 * required to be done shortly after the API is invoked.
11057 */
11058 @Override
11059 @TelephonyManager.PrepareUnattendedRebootResult
11060 public int prepareForUnattendedReboot() {
11061 enforceRebootPermission();
11062
11063 final long identity = Binder.clearCallingIdentity();
11064 try {
11065 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11066 } finally {
11067 Binder.restoreCallingIdentity(identity);
11068 }
11069 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011070
11071 /**
11072 * Request to get the current slicing configuration including URSP rules and
11073 * NSSAIs (configured, allowed and rejected).
11074 *
11075 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11076 */
11077 @Override
11078 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011079 TelephonyPermissions
11080 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11081 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011082
11083 final long identity = Binder.clearCallingIdentity();
11084 try {
11085 Phone phone = getDefaultPhone();
11086 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11087 } finally {
11088 Binder.restoreCallingIdentity(identity);
11089 }
11090 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011091
11092 /**
11093 * Register an IMS connection state callback
11094 */
11095 @Override
11096 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11097 String callingPackage) {
11098 if (feature == ImsFeature.FEATURE_MMTEL) {
11099 // ImsMmTelManager
11100 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11101 TelephonyPermissions
11102 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11103 mApp, subId, "registerImsStateCallback");
11104 } else if (feature == ImsFeature.FEATURE_RCS) {
11105 // ImsRcsManager or SipDelegateManager
11106 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11107 Binder.getCallingUid(), "registerImsStateCallback",
11108 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11109 Manifest.permission.READ_PRECISE_PHONE_STATE,
11110 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11111 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11112 }
11113
11114 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11115 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11116 "IMS not available on device.");
11117 }
11118
11119 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11120 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11121 }
11122
11123 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11124 if (controller == null) {
11125 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11126 "IMS not available on device.");
11127 }
11128
11129 if (callingPackage == null) {
11130 callingPackage = getCurrentPackageName();
11131 }
11132
11133 final long token = Binder.clearCallingIdentity();
11134 try {
11135 int slotId = getSlotIndexOrException(subId);
11136 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11137 } catch (ImsException e) {
11138 throw new ServiceSpecificException(e.getCode());
11139 } finally {
11140 Binder.restoreCallingIdentity(token);
11141 }
11142 }
11143
11144 /**
11145 * Unregister an IMS connection state callback
11146 */
11147 @Override
11148 public void unregisterImsStateCallback(IImsStateCallback cb) {
11149 final long token = Binder.clearCallingIdentity();
11150 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11151 if (controller == null) {
11152 return;
11153 }
11154 try {
11155 controller.unregisterImsStateCallback(cb);
11156 } finally {
11157 Binder.restoreCallingIdentity(token);
11158 }
11159 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011160
11161 /**
11162 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11163 *
11164 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11165 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11166 * SecurityException.
11167 * If there is current registered network this value will be same as the registered cell
11168 * identity. If the device goes out of service the previous cell identity is cached and
11169 * will be returned. If the cache age of the Cell identity is more than 24 hours
11170 * it will be cleared and null will be returned.
11171 *
11172 */
11173 @Override
11174 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11175 String callingFeatureId) {
11176 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11177 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11178 LocationAccessPolicy.checkLocationPermission(mApp,
11179 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11180 .setCallingPackage(callingPackage)
11181 .setCallingFeatureId(callingFeatureId)
11182 .setCallingPid(Binder.getCallingPid())
11183 .setCallingUid(Binder.getCallingUid())
11184 .setMethod("getLastKnownCellIdentity")
11185 .setLogAsInfo(true)
11186 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11187 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11188 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11189 .build());
11190
11191 boolean hasFinePermission =
11192 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11193 if (!hasFinePermission
11194 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11195 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11196 + "and BIND_CONNECTION_SERVICE permission.");
11197 }
11198
11199 final long identity = Binder.clearCallingIdentity();
11200 try {
11201 Phone phone = getPhone(subId);
11202 if (phone == null) return null;
11203 ServiceStateTracker sst = phone.getServiceStateTracker();
11204 if (sst == null) return null;
11205 return sst.getLastKnownCellIdentity();
11206 } finally {
11207 Binder.restoreCallingIdentity(identity);
11208 }
11209 }
jimsun38340bf2021-10-26 15:01:23 +080011210
11211 /**
11212 * Sets the modem service class Name that Telephony will bind to.
11213 *
11214 * @param serviceName The class name of the modem service.
11215 * @return true if the operation is succeed, otherwise false.
11216 */
11217 public boolean setModemService(String serviceName) {
11218 Log.d(LOG_TAG, "setModemService - " + serviceName);
11219 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11221 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11222 "setModemService");
11223 return mPhoneConfigurationManager.setModemService(serviceName);
11224 }
11225
11226 /**
11227 * Return the class name of the currently bounded modem service.
11228 *
11229 * @return the class name of the modem service.
11230 */
11231 public String getModemService() {
11232 String result;
11233 Log.d(LOG_TAG, "getModemService");
11234 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11235 TelephonyPermissions
11236 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11237 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11238 "getModemService");
11239 result = mPhoneConfigurationManager.getModemService();
11240 Log.d(LOG_TAG, "result = " + result);
11241 return result;
11242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011243}