blob: 99f1a5480f135c73259de8e87ace39a5953063b1 [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;
Rambo Wanga7436882022-01-13 21:51:44 -0800152import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wange162e302021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700187import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshinfa314642021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800197import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800215import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700217import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800218import com.android.services.telephony.TelecomAccountRegistry;
219import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800220import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800221
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.IOException;
225import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228import java.util.Arrays;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +0000229import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800230import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800231import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800232import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100233import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700235import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800237import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800239import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800240import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
242/**
243 * Implementation of the ITelephony interface.
244 */
Santos Cordon117fee72014-05-16 17:56:12 -0700245public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 private static final String LOG_TAG = "PhoneInterfaceManager";
247 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
248 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
251 // Message codes used with mMainThreadHandler
252 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700253 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
254 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700255 private static final int CMD_OPEN_CHANNEL = 9;
256 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
257 private static final int CMD_CLOSE_CHANNEL = 11;
258 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800259 private static final int CMD_NV_READ_ITEM = 13;
260 private static final int EVENT_NV_READ_ITEM_DONE = 14;
261 private static final int CMD_NV_WRITE_ITEM = 15;
262 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
263 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
264 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_RESET_MODEM_CONFIG = 19;
266 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800267 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
268 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800269 private static final int CMD_SEND_ENVELOPE = 25;
270 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000271 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
272 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700273 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
274 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
275 private static final int CMD_EXCHANGE_SIM_IO = 31;
276 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
278 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700279 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
280 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700281 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
282 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700283 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
284 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
285 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
286 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700287 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
288 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
289 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
290 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700291 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800292 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
293 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000294 private static final int CMD_SWITCH_SLOTS = 50;
295 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700296 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
297 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
298 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
299 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
300 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
301 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
302 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
303 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700304 private static final int CMD_GET_ALL_CELL_INFO = 60;
305 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
306 private static final int CMD_GET_CELL_LOCATION = 62;
307 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700308 private static final int CMD_MODEM_REBOOT = 64;
309 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700310 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
311 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800312 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
313 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700314 private static final int CMD_GET_MODEM_STATUS = 70;
315 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700316 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
317 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700318 private static final int CMD_ERASE_MODEM_CONFIG = 74;
319 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800320 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
321 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
322 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
323 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800324 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
325 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800326 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800327 private static final int CMD_GET_CALL_FORWARDING = 83;
328 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
329 private static final int CMD_SET_CALL_FORWARDING = 85;
330 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
331 private static final int CMD_GET_CALL_WAITING = 87;
332 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
333 private static final int CMD_SET_CALL_WAITING = 89;
334 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700335 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
336 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
337 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
338 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700339 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
340 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800341 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
342 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800343 private static final int CMD_SET_DATA_THROTTLING = 99;
344 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800345 private static final int CMD_SET_SIM_POWER = 101;
346 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800347 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
348 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
349 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
350 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800351 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
352 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000353 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800354 private static final int CMD_GET_SLICING_CONFIG = 110;
355 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800356 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700357 private static final int CMD_ENABLE_VONR = 113;
358 private static final int EVENT_ENABLE_VONR_DONE = 114;
359 private static final int CMD_IS_VONR_ENABLED = 115;
360 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800362 // Parameters of select command.
363 private static final int SELECT_COMMAND = 0xA4;
364 private static final int SELECT_P1 = 0x04;
365 private static final int SELECT_P2 = 0;
366 private static final int SELECT_P3 = 0x10;
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 /** The singleton instance. */
369 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800370 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800374 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700375 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700377 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800379 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700381 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800382 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 /** User Activity */
385 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
387
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700388 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
389
Derek Tan97ebb422014-09-05 16:55:38 -0700390 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
391 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800392 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800393 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700394
Michelecea4cf22018-12-21 15:00:11 -0800395 // String to store multi SIM allowed
396 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
397
Derek Tan740e1672017-06-27 14:56:27 -0700398 // The AID of ISD-R.
399 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
400
yinxub1bed742017-04-17 11:45:04 -0700401 private NetworkScanRequestTracker mNetworkScanRequestTracker;
402
David Kelly5e06a7f2018-03-12 14:10:59 +0000403 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
404 private static final int MANUFACTURER_CODE_LENGTH = 8;
405
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800407 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408
Derek Tan89e89d42014-07-08 17:00:10 -0700409 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700410 * Experiment flag to enable erase modem config on reset network, default value is false
411 */
412 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
413 "reset_network_erase_modem_config_enabled";
414
Rambo Wang0f050d82021-02-12 11:43:36 -0800415 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjs0a502c42021-09-27 15:34:44 +0000416 /**
417 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
418 * one ICCID active at the same time.
419 * Apps should use below API signatures if targeting SDK is T and beyond.
420 *
421 * @hide
422 */
423 @ChangeId
424 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
425 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800426
Naina Nallurid63128d2019-09-17 14:10:30 -0700427 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 * A request object to use for transmitting data to an ICC.
429 */
430 private static final class IccAPDUArgument {
431 public int channel, cla, command, p1, p2, p3;
432 public String data;
433
434 public IccAPDUArgument(int channel, int cla, int command,
435 int p1, int p2, int p3, String data) {
436 this.channel = channel;
437 this.cla = cla;
438 this.command = command;
439 this.p1 = p1;
440 this.p2 = p2;
441 this.p3 = p3;
442 this.data = data;
443 }
444 }
445
446 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700447 * A request object to use for transmitting data to an ICC.
448 */
449 private static final class ManualNetworkSelectionArgument {
450 public OperatorInfo operatorInfo;
451 public boolean persistSelection;
452
453 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
454 this.operatorInfo = operatorInfo;
455 this.persistSelection = persistSelection;
456 }
457 }
458
459 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
461 * request after sending. The main thread will notify the request when it is complete.
462 */
463 private static final class MainThreadRequest {
464 /** The argument to use for the request */
465 public Object argument;
466 /** The result of the request that is run on the main thread */
467 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800468 // The subscriber id that this request applies to. Defaults to
469 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
470 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471
Nathan Harold92bed182018-10-12 18:16:49 -0700472 // In cases where subId is unavailable, the caller needs to specify the phone.
473 public Phone phone;
474
vagdeviaf9a5b92018-08-15 16:01:53 -0700475 public WorkSource workSource;
476
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 public MainThreadRequest(Object argument) {
478 this.argument = argument;
479 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800480
Nathan Harold92bed182018-10-12 18:16:49 -0700481 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
482 this.argument = argument;
483 if (phone != null) {
484 this.phone = phone;
485 }
486 this.workSource = workSource;
487 }
488
vagdeviaf9a5b92018-08-15 16:01:53 -0700489 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800491 if (subId != null) {
492 this.subId = subId;
493 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700494 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496 }
497
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800498 private static final class IncomingThirdPartyCallArgs {
499 public final ComponentName component;
500 public final String callId;
501 public final String callerDisplayName;
502
503 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
504 String callerDisplayName) {
505 this.component = component;
506 this.callId = callId;
507 this.callerDisplayName = callerDisplayName;
508 }
509 }
510
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 /**
512 * A handler that processes messages on the main thread in the phone process. Since many
513 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
514 * inbound binder threads to the main thread in the phone process. The Binder thread
515 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
516 * on, which will be notified when the operation completes and will contain the result of the
517 * request.
518 *
519 * <p>If a MainThreadRequest object is provided in the msg.obj field,
520 * note that request.result must be set to something non-null for the calling thread to
521 * unblock.
522 */
523 private final class MainThreadHandler extends Handler {
524 @Override
525 public void handleMessage(Message msg) {
526 MainThreadRequest request;
527 Message onCompleted;
528 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000529 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800531 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532
533 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 case CMD_HANDLE_USSD_REQUEST: {
535 request = (MainThreadRequest) msg.obj;
536 final Phone phone = getPhoneFromRequest(request);
537 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
538 String ussdRequest = ussdObject.first;
539 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700540
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 if (!isUssdApiAllowed(request.subId)) {
542 // Carrier does not support use of this API, return failure.
543 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
544 UssdResponse response = new UssdResponse(ussdRequest, null);
545 Bundle returnData = new Bundle();
546 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
547 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700548
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 request.result = true;
550 notifyRequester(request);
551 return;
552 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700553
Pengquan Menga1bb6272018-09-06 09:59:22 -0700554 try {
555 request.result = phone != null
556 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
557 } catch (CallStateException cse) {
558 request.result = false;
559 }
560 // Wake up the requesting thread
561 notifyRequester(request);
562 break;
pkanwar32d516d2016-10-14 19:37:38 -0700563 }
564
Yorke Lee716f67e2015-06-17 15:39:16 -0700565 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700567 final Phone phone = getPhoneFromRequest(request);
568 request.result = phone != null ?
569 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
570 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000579 uiccPort = getUiccPortFromRequest(request);
580 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 loge("iccTransmitApduLogicalChannel: No UICC");
582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
586 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000587 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 iccArgument.channel, iccArgument.cla, iccArgument.command,
589 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
597 if (ar.exception == null && ar.result != null) {
598 request.result = ar.result;
599 } else {
600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
601 if (ar.result == null) {
602 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800603 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800605 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 } else {
607 loge("iccTransmitApduLogicalChannel: Unknown exception");
608 }
609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 break;
612
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
614 request = (MainThreadRequest) msg.obj;
615 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000616 uiccPort = getUiccPortFromRequest(request);
617 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 loge("iccTransmitApduBasicChannel: No UICC");
619 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 } else {
622 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
623 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000624 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
626 iccArgument.p3, iccArgument.data, onCompleted);
627 }
628 break;
629
630 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result;
635 } else {
636 request.result = new IccIoResult(0x6F, 0, (byte[])null);
637 if (ar.result == null) {
638 loge("iccTransmitApduBasicChannel: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("iccTransmitApduBasicChannel: CommandException: " +
641 ar.exception);
642 } else {
643 loge("iccTransmitApduBasicChannel: Unknown exception");
644 }
645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 break;
648
649 case CMD_EXCHANGE_SIM_IO:
650 request = (MainThreadRequest) msg.obj;
651 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000652 uiccPort = getUiccPortFromRequest(request);
653 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 loge("iccExchangeSimIO: No UICC");
655 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
659 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000660 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
662 iccArgument.data, onCompleted);
663 }
664 break;
665
666 case EVENT_EXCHANGE_SIM_IO_DONE:
667 ar = (AsyncResult) msg.obj;
668 request = (MainThreadRequest) ar.userObj;
669 if (ar.exception == null && ar.result != null) {
670 request.result = ar.result;
671 } else {
672 request.result = new IccIoResult(0x6f, 0, (byte[])null);
673 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 break;
676
Derek Tan4d5e5c12014-02-04 11:54:58 -0800677 case CMD_SEND_ENVELOPE:
678 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000679 uiccPort = getUiccPortFromRequest(request);
680 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 loge("sendEnvelopeWithStatus: No UICC");
682 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000686 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800688 break;
689
690 case EVENT_SEND_ENVELOPE_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800695 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700696 request.result = new IccIoResult(0x6F, 0, (byte[])null);
697 if (ar.result == null) {
698 loge("sendEnvelopeWithStatus: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("sendEnvelopeWithStatus: CommandException: " +
701 ar.exception);
702 } else {
703 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
704 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800707 break;
708
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 case CMD_OPEN_CHANNEL:
710 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000711 uiccPort = getUiccPortFromRequest(request);
Rambo Wange162e302021-11-10 20:15:19 -0800712 IccLogicalChannelRequest openChannelRequest =
713 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000714 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800716 request.result = new IccOpenLogicalChannelResponse(-1,
717 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wange162e302021-11-10 20:15:19 -0800721 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
722 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 break;
725
726 case EVENT_OPEN_CHANNEL_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700731 int[] result = (int[]) ar.result;
732 int channelId = result[0];
733 byte[] selectResponse = null;
734 if (result.length > 1) {
735 selectResponse = new byte[result.length - 1];
736 for (int i = 1; i < result.length; ++i) {
737 selectResponse[i - 1] = (byte) result[i];
738 }
739 }
740 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700741 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 if (ar.result == null) {
744 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700746 if (ar.exception != null) {
747 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
748 }
749
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700750 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700751 if (ar.exception instanceof CommandException) {
752 CommandException.Error error =
753 ((CommandException) (ar.exception)).getCommandError();
754 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700755 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700756 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700757 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700758 }
759 }
760 openChannelResp = new IccOpenLogicalChannelResponse(
761 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700763 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 break;
766
767 case CMD_CLOSE_CHANNEL:
768 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000769 uiccPort = getUiccPortFromRequest(request);
770 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900772 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 } else {
775 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000776 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700777 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 break;
779
780 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800781 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
782 break;
783
784 case CMD_NV_READ_ITEM:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
788 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
791 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 ar = (AsyncResult) msg.obj;
793 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800794 if (ar.exception == null && ar.result != null) {
795 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800797 request.result = "";
798 if (ar.result == null) {
799 loge("nvReadItem: Empty response");
800 } else if (ar.exception instanceof CommandException) {
801 loge("nvReadItem: CommandException: " +
802 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800804 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 }
806 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700807 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700808 break;
809
Jake Hambye994d462014-02-03 13:10:13 -0800810 case CMD_NV_WRITE_ITEM:
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
813 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800814 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700815 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
818 case EVENT_NV_WRITE_ITEM_DONE:
819 handleNullReturnEvent(msg, "nvWriteItem");
820 break;
821
822 case CMD_NV_WRITE_CDMA_PRL:
823 request = (MainThreadRequest) msg.obj;
824 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800825 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800826 break;
827
828 case EVENT_NV_WRITE_CDMA_PRL_DONE:
829 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
830 break;
831
chen xu6dac5ab2018-10-26 17:39:23 -0700832 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800833 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700834 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800835 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800836 break;
837
chen xu6dac5ab2018-10-26 17:39:23 -0700838 case EVENT_RESET_MODEM_CONFIG_DONE:
839 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800840 break;
841
Sooraj Sasindran37444802020-08-11 10:40:43 -0700842 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
845 request);
846 Phone phone = getPhoneFromRequest(request);
847 if (phone != null) {
848 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
849 } else {
850 loge("isNRDualConnectivityEnabled: No phone object");
851 request.result = false;
852 notifyRequester(request);
853 }
854 break;
855 }
856
857 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
858 ar = (AsyncResult) msg.obj;
859 request = (MainThreadRequest) ar.userObj;
860 if (ar.exception == null && ar.result != null) {
861 request.result = ar.result;
862 } else {
863 // request.result must be set to something non-null
864 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700865 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700866 request.result = ar.result;
867 } else {
868 request.result = false;
869 }
870 if (ar.result == null) {
871 loge("isNRDualConnectivityEnabled: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("isNRDualConnectivityEnabled: CommandException: "
874 + ar.exception);
875 } else {
876 loge("isNRDualConnectivityEnabled: Unknown exception");
877 }
878 }
879 notifyRequester(request);
880 break;
881
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700882 case CMD_IS_VONR_ENABLED: {
883 request = (MainThreadRequest) msg.obj;
884 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
885 request);
886 Phone phone = getPhoneFromRequest(request);
887 if (phone != null) {
888 phone.isVoNrEnabled(onCompleted, request.workSource);
889 } else {
890 loge("isVoNrEnabled: No phone object");
891 request.result = false;
892 notifyRequester(request);
893 }
894 break;
895 }
896
897 case EVENT_IS_VONR_ENABLED_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
903 // request.result must be set to something non-null
904 // for the calling thread to unblock
905 if (ar.result != null) {
906 request.result = ar.result;
907 } else {
908 request.result = false;
909 }
910 if (ar.result == null) {
911 loge("isVoNrEnabled: Empty response");
912 } else if (ar.exception instanceof CommandException) {
913 loge("isVoNrEnabled: CommandException: "
914 + ar.exception);
915 } else {
916 loge("isVoNrEnabled: Unknown exception");
917 }
918 }
919 notifyRequester(request);
920 break;
921
Sooraj Sasindran37444802020-08-11 10:40:43 -0700922 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
925 Phone phone = getPhoneFromRequest(request);
926 if (phone != null) {
927 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
928 request.workSource);
929 } else {
930 loge("enableNrDualConnectivity: No phone object");
931 request.result =
932 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
933 notifyRequester(request);
934 }
935 break;
936 }
937
938 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
939 ar = (AsyncResult) msg.obj;
940 request = (MainThreadRequest) ar.userObj;
941 if (ar.exception == null) {
942 request.result =
943 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
944 } else {
945 request.result =
946 TelephonyManager
947 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
948 if (ar.exception instanceof CommandException) {
949 CommandException.Error error =
950 ((CommandException) (ar.exception)).getCommandError();
951 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
952 request.result =
953 TelephonyManager
954 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000955 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
956 request.result =
957 TelephonyManager
958 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700959 }
960 loge("enableNrDualConnectivity" + ": CommandException: "
961 + ar.exception);
962 } else {
963 loge("enableNrDualConnectivity" + ": Unknown exception");
964 }
965 }
966 notifyRequester(request);
967 break;
968 }
969
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700970 case CMD_ENABLE_VONR: {
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
973 Phone phone = getPhoneFromRequest(request);
974 if (phone != null) {
975 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
976 request.workSource);
977 } else {
978 loge("setVoNrEnabled: No phone object");
979 request.result =
980 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
981 notifyRequester(request);
982 }
983 break;
984 }
985
986 case EVENT_ENABLE_VONR_DONE: {
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 if (ar.exception == null) {
990 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
991 } else {
992 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
993 if (ar.exception instanceof CommandException) {
994 CommandException.Error error =
995 ((CommandException) (ar.exception)).getCommandError();
996 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
997 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
998 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
999 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1000 } else {
1001 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1002 }
1003 loge("setVoNrEnabled" + ": CommandException: "
1004 + ar.exception);
1005 } else {
1006 loge("setVoNrEnabled" + ": Unknown exception");
1007 }
1008 }
1009 notifyRequester(request);
1010 break;
1011 }
1012
SongFerngWang3ef3e072020-12-21 16:41:52 +08001013 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001015 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1016 request);
1017 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 break;
1019
SongFerngWang3ef3e072020-12-21 16:41:52 +08001020 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception == null && ar.result != null) {
1024 request.result = ar.result; // Integer
1025 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301026 // request.result must be set to something non-null
1027 // for the calling thread to unblock
1028 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001032 loge("getAllowedNetworkTypesBitmask: CommandException: "
1033 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001035 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001036 }
1037 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001038 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001039 break;
1040
SongFerngWang3ef3e072020-12-21 16:41:52 +08001041 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001042 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001043 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1044 request);
1045 Pair<Integer, Long> reasonWithNetworkTypes =
1046 (Pair<Integer, Long>) request.argument;
1047 getPhoneFromRequest(request).setAllowedNetworkTypes(
1048 reasonWithNetworkTypes.first,
1049 reasonWithNetworkTypes.second,
1050 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001051 break;
1052
SongFerngWang3ef3e072020-12-21 16:41:52 +08001053 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1054 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001055 break;
1056
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001057 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1058 request = (MainThreadRequest)msg.obj;
1059 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001060 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001061 break;
1062
1063 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1064 ar = (AsyncResult)msg.obj;
1065 request = (MainThreadRequest)ar.userObj;
1066 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001067 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001068 break;
1069
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001070 case CMD_SET_VOICEMAIL_NUMBER:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1073 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001074 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1075 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001076 break;
1077
1078 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1079 handleNullReturnEvent(msg, "setVoicemailNumber");
1080 break;
1081
Stuart Scott54788802015-03-30 13:18:01 -07001082 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1083 request = (MainThreadRequest) msg.obj;
1084 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1085 request);
1086 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1087 break;
1088
1089 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1090 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1091 break;
1092
Shishir Agrawal302c8692015-06-19 13:49:39 -07001093 case CMD_PERFORM_NETWORK_SCAN:
1094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1096 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1097 break;
1098
Hall Liu27d24262020-09-18 19:04:59 -07001099 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001100 request = (MainThreadRequest) msg.obj;
1101 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001102 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1103 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1104 request.argument;
1105 int callForwardingReason = args.first;
1106 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001107 break;
Hall Liu27d24262020-09-18 19:04:59 -07001108 }
1109 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001112 TelephonyManager.CallForwardingInfoCallback callback =
1113 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1114 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001115 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001116 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001117 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1118 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1119 // Service Class is a bit mask per 3gpp 27.007. Search for
1120 // any service for voice call.
1121 if ((callForwardInfo.serviceClass
1122 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001123 callForwardingInfo = new CallForwardingInfo(
1124 callForwardInfo.status
1125 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001126 callForwardInfo.reason,
1127 callForwardInfo.number,
1128 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001129 break;
1130 }
1131 }
1132 // Didn't find a call forward info for voice call.
1133 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001134 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1135 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 }
Hall Liu27d24262020-09-18 19:04:59 -07001137 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001138 } else {
1139 if (ar.result == null) {
1140 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1141 }
1142 if (ar.exception != null) {
1143 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1144 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001145 int errorCode = TelephonyManager
1146 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001147 if (ar.exception instanceof CommandException) {
1148 CommandException.Error error =
1149 ((CommandException) (ar.exception)).getCommandError();
1150 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001151 errorCode = TelephonyManager
1152 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001153 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001154 errorCode = TelephonyManager
1155 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001156 }
1157 }
Hall Liu27d24262020-09-18 19:04:59 -07001158 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001159 }
Shuo Qian4a594052020-01-23 11:59:30 -08001160 break;
Hall Liu27d24262020-09-18 19:04:59 -07001161 }
Shuo Qian4a594052020-01-23 11:59:30 -08001162
Hall Liu27d24262020-09-18 19:04:59 -07001163 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001164 request = (MainThreadRequest) msg.obj;
1165 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001166 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001167 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001168 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1169 request.argument).first;
1170 request.phone.setCallForwardingOption(
1171 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001172 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001173 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001174 callForwardingInfoToSet.getReason(),
1175 callForwardingInfoToSet.getNumber(),
1176 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1177 break;
Hall Liu27d24262020-09-18 19:04:59 -07001178 }
Shuo Qian4a594052020-01-23 11:59:30 -08001179
Hall Liu27d24262020-09-18 19:04:59 -07001180 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001183 Consumer<Integer> callback =
1184 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1185 request.argument).second;
1186 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001187 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 int errorCode = TelephonyManager.CallForwardingInfoCallback
1189 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001190 if (ar.exception instanceof CommandException) {
1191 CommandException.Error error =
1192 ((CommandException) (ar.exception)).getCommandError();
1193 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager.CallForwardingInfoCallback
1195 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001196 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 errorCode = TelephonyManager.CallForwardingInfoCallback
1198 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001199 }
1200 }
1201 callback.accept(errorCode);
1202 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001203 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205 break;
Hall Liu27d24262020-09-18 19:04:59 -07001206 }
Shuo Qian4a594052020-01-23 11:59:30 -08001207
Hall Liu27d24262020-09-18 19:04:59 -07001208 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1211 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1212 break;
Hall Liu27d24262020-09-18 19:04:59 -07001213 }
Shuo Qian4a594052020-01-23 11:59:30 -08001214
Hall Liu27d24262020-09-18 19:04:59 -07001215 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001216 ar = (AsyncResult) msg.obj;
1217 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001218 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1220 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001221 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001222 // Service Class is a bit mask per 3gpp 27.007.
1223 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001224 if (callForwardResults.length > 1
1225 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001226 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001227 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001228 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1229 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001230 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001231 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 }
1233 } else {
1234 if (ar.result == null) {
1235 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1236 }
1237 if (ar.exception != null) {
1238 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1239 }
1240 if (ar.exception instanceof CommandException) {
1241 CommandException.Error error =
1242 ((CommandException) (ar.exception)).getCommandError();
1243 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1244 callForwardingStatus =
1245 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1246 }
1247 }
1248 }
Hall Liu27d24262020-09-18 19:04:59 -07001249 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 break;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252
Hall Liu27d24262020-09-18 19:04:59 -07001253 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001254 request = (MainThreadRequest) msg.obj;
1255 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001256 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1257 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260
Hall Liu27d24262020-09-18 19:04:59 -07001261 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001264 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1265 Consumer<Integer> callback =
1266 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1267 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001269 if (ar.exception instanceof CommandException) {
1270 CommandException.Error error =
1271 ((CommandException) (ar.exception)).getCommandError();
1272 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1274 } else {
1275 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1276 }
1277 } else {
1278 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1279 }
1280 } else {
1281 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1282 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001283 }
Shuo Qian4a594052020-01-23 11:59:30 -08001284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001286 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1287 ar = (AsyncResult) msg.obj;
1288 request = (MainThreadRequest) ar.userObj;
1289 CellNetworkScanResult cellScanResult;
1290 if (ar.exception == null && ar.result != null) {
1291 cellScanResult = new CellNetworkScanResult(
1292 CellNetworkScanResult.STATUS_SUCCESS,
1293 (List<OperatorInfo>) ar.result);
1294 } else {
1295 if (ar.result == null) {
1296 loge("getCellNetworkScanResults: Empty response");
1297 }
1298 if (ar.exception != null) {
1299 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1300 }
1301 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1302 if (ar.exception instanceof CommandException) {
1303 CommandException.Error error =
1304 ((CommandException) (ar.exception)).getCommandError();
1305 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1306 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1307 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1308 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1309 }
1310 }
1311 cellScanResult = new CellNetworkScanResult(errorCode, null);
1312 }
1313 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001314 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001315 break;
1316
1317 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1318 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001319 ManualNetworkSelectionArgument selArg =
1320 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001321 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1322 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001323 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1324 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001325 break;
1326
1327 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001328 ar = (AsyncResult) msg.obj;
1329 request = (MainThreadRequest) ar.userObj;
1330 if (ar.exception == null) {
1331 request.result = true;
1332 } else {
1333 request.result = false;
1334 loge("setNetworkSelectionModeManual " + ar.exception);
1335 }
1336 notifyRequester(request);
1337 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001338 break;
1339
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001340 case CMD_GET_MODEM_ACTIVITY_INFO:
1341 request = (MainThreadRequest) msg.obj;
1342 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001343 if (defaultPhone != null) {
1344 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001345 } else {
1346 ResultReceiver result = (ResultReceiver) request.argument;
1347 Bundle bundle = new Bundle();
1348 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001349 new ModemActivityInfo(0, 0, 0,
1350 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001351 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001352 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001353 break;
1354
Hall Liud0f208c2020-10-14 16:54:44 -07001355 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001356 ar = (AsyncResult) msg.obj;
1357 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 ResultReceiver result = (ResultReceiver) request.argument;
1359
Hall Liud0f208c2020-10-14 16:54:44 -07001360 ModemActivityInfo ret = null;
1361 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001362 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001363 // Update the last modem activity info and the result of the request.
1364 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1365 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001366 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001367 int[] txTimeMs = info.getTransmitTimeMillis();
1368 int[] lastModemTxTimeMs = mLastModemActivityInfo
1369 .getTransmitTimeMillis();
1370 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1371 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1372 }
Hall Liu49656c02020-10-09 19:00:11 -07001373 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001374 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1375 + mLastModemActivityInfo.getSleepTimeMillis());
1376 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1377 + mLastModemActivityInfo.getIdleTimeMillis());
1378 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1379 mLastModemActivityInfo.setReceiveTimeMillis(
1380 info.getReceiveTimeMillis()
1381 + mLastModemActivityInfo.getReceiveTimeMillis());
1382 }
Hall Liu49656c02020-10-09 19:00:11 -07001383 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001384 mLastModemActivityInfo.getSleepTimeMillis(),
1385 mLastModemActivityInfo.getIdleTimeMillis(),
1386 mLastModemActivityInfo.getTransmitTimeMillis(),
1387 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 } else {
1389 if (ar.result == null) {
1390 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001391 error = TelephonyManager.ModemActivityInfoException
1392 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001393 } else if (ar.exception instanceof CommandException) {
1394 loge("queryModemActivityInfo: CommandException: " +
1395 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001396 error = TelephonyManager.ModemActivityInfoException
1397 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 } else {
1399 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001400 error = TelephonyManager.ModemActivityInfoException
1401 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001402 }
1403 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001404 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001405 if (ret != null) {
1406 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1407 } else {
1408 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1409 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001411 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001412 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001413 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001414
Meng Wang1a7c35a2016-05-05 20:56:15 -07001415 case CMD_SET_ALLOWED_CARRIERS:
1416 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001417 CarrierRestrictionRules argument =
1418 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001419 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001420 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001421 break;
1422
1423 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 if (ar.exception == null && ar.result != null) {
1427 request.result = ar.result;
1428 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001429 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1430 if (ar.exception instanceof CommandException) {
1431 loge("setAllowedCarriers: CommandException: " + ar.exception);
1432 CommandException.Error error =
1433 ((CommandException) (ar.exception)).getCommandError();
1434 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1435 request.result =
1436 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1437 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001438 } else {
1439 loge("setAllowedCarriers: Unknown exception");
1440 }
1441 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001443 break;
1444
1445 case CMD_GET_ALLOWED_CARRIERS:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001448 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001449 break;
1450
1451 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
1454 if (ar.exception == null && ar.result != null) {
1455 request.result = ar.result;
1456 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001457 request.result = new IllegalStateException(
1458 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001459 if (ar.result == null) {
1460 loge("getAllowedCarriers: Empty response");
1461 } else if (ar.exception instanceof CommandException) {
1462 loge("getAllowedCarriers: CommandException: " +
1463 ar.exception);
1464 } else {
1465 loge("getAllowedCarriers: Unknown exception");
1466 }
1467 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001468 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001469 break;
1470
Nathan Haroldb3014052017-01-25 15:57:32 -08001471 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
1474 if (ar.exception == null && ar.result != null) {
1475 request.result = ar.result;
1476 } else {
1477 request.result = new IllegalArgumentException(
1478 "Failed to retrieve Forbidden Plmns");
1479 if (ar.result == null) {
1480 loge("getForbiddenPlmns: Empty response");
1481 } else {
1482 loge("getForbiddenPlmns: Unknown exception");
1483 }
1484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001485 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001486 break;
1487
1488 case CMD_GET_FORBIDDEN_PLMNS:
1489 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001490 uiccPort = getUiccPortFromRequest(request);
1491 if (uiccPort == null) {
1492 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001493 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001494 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001495 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001496 break;
1497 }
1498 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001499 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001500 if (uiccApp == null) {
1501 loge("getForbiddenPlmns() no app with specified type -- "
1502 + appType);
1503 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001504 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001505 break;
1506 } else {
1507 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1508 + " specified type -- " + appType);
1509 }
1510 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1511 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1512 onCompleted);
1513 break;
1514
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001515 case CMD_SWITCH_SLOTS:
1516 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001517 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001518 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001519 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001520 break;
1521
1522 case EVENT_SWITCH_SLOTS_DONE:
1523 ar = (AsyncResult) msg.obj;
1524 request = (MainThreadRequest) ar.userObj;
1525 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001526 notifyRequester(request);
1527 break;
1528 case CMD_GET_NETWORK_SELECTION_MODE:
1529 request = (MainThreadRequest) msg.obj;
1530 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1531 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1532 break;
1533
1534 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception != null) {
1538 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1539 } else {
1540 int mode = ((int[]) ar.result)[0];
1541 if (mode == 0) {
1542 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1543 } else {
1544 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1545 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001547 notifyRequester(request);
1548 break;
1549 case CMD_GET_CDMA_ROAMING_MODE:
1550 request = (MainThreadRequest) msg.obj;
1551 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1552 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1553 break;
1554 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1555 ar = (AsyncResult) msg.obj;
1556 request = (MainThreadRequest) ar.userObj;
1557 if (ar.exception != null) {
1558 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1559 } else {
1560 request.result = ((int[]) ar.result)[0];
1561 }
1562 notifyRequester(request);
1563 break;
1564 case CMD_SET_CDMA_ROAMING_MODE:
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1567 int mode = (int) request.argument;
1568 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1569 break;
1570 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 request.result = ar.exception == null;
1574 notifyRequester(request);
1575 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001576 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1577 request = (MainThreadRequest) msg.obj;
1578 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1579 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1580 break;
1581 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1582 ar = (AsyncResult) msg.obj;
1583 request = (MainThreadRequest) ar.userObj;
1584 if (ar.exception != null) {
1585 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1586 } else {
1587 request.result = ((int[]) ar.result)[0];
1588 }
1589 notifyRequester(request);
1590 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001591 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1592 request = (MainThreadRequest) msg.obj;
1593 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1594 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001595 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1596 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001597 break;
1598 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 request.result = ar.exception == null;
1602 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001603 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 case CMD_GET_ALL_CELL_INFO:
1605 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001606 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001607 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001608 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001609 case EVENT_GET_ALL_CELL_INFO_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001612 // If a timeout occurs, the response will be null
1613 request.result = (ar.exception == null && ar.result != null)
1614 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001615 synchronized (request) {
1616 request.notifyAll();
1617 }
1618 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001619 case CMD_REQUEST_CELL_INFO_UPDATE:
1620 request = (MainThreadRequest) msg.obj;
1621 request.phone.requestCellInfoUpdate(request.workSource,
1622 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1623 break;
1624 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1628 try {
1629 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001630 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001631 cb.onError(
1632 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1633 ar.exception.getClass().getName(),
1634 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001635 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001636 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001637 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001638 } else {
1639 // use the result as returned
1640 cb.onCellInfo((List<CellInfo>) ar.result);
1641 }
1642 } catch (RemoteException re) {
1643 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1644 }
1645 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001646 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001647 request = (MainThreadRequest) msg.obj;
1648 WorkSource ws = (WorkSource) request.argument;
1649 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001650 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001652 }
1653 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 if (ar.exception == null) {
1657 request.result = ar.result;
1658 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001659 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001661 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 }
1663
1664 synchronized (request) {
1665 request.notifyAll();
1666 }
1667 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001668 }
chen xu6dac5ab2018-10-26 17:39:23 -07001669 case CMD_MODEM_REBOOT:
1670 request = (MainThreadRequest) msg.obj;
1671 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001672 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001673 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001674 case EVENT_CMD_MODEM_REBOOT_DONE:
1675 handleNullReturnEvent(msg, "rebootModem");
1676 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001677 case CMD_REQUEST_ENABLE_MODEM:
1678 request = (MainThreadRequest) msg.obj;
1679 boolean enable = (boolean) request.argument;
1680 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001681 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001682 PhoneConfigurationManager.getInstance()
1683 .enablePhone(request.phone, enable, onCompleted);
1684 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001685 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001689 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001690 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001691 if ((boolean) request.result) {
1692 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1693 updateModemStateMetrics();
1694 } else {
1695 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1696 + ar.exception);
1697 }
1698 notifyRequester(request);
1699 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001700 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001701 case CMD_GET_MODEM_STATUS:
1702 request = (MainThreadRequest) msg.obj;
1703 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1704 PhoneConfigurationManager.getInstance()
1705 .getPhoneStatusFromModem(request.phone, onCompleted);
1706 break;
1707 case EVENT_GET_MODEM_STATUS_DONE:
1708 ar = (AsyncResult) msg.obj;
1709 request = (MainThreadRequest) ar.userObj;
1710 int id = request.phone.getPhoneId();
1711 if (ar.exception == null && ar.result != null) {
1712 request.result = ar.result;
1713 //update the cache as modem status has changed
1714 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1715 (boolean) request.result);
1716 } else {
1717 // Return true if modem status cannot be retrieved. For most cases,
1718 // modem status is on. And for older version modems, GET_MODEM_STATUS
1719 // and disable modem are not supported. Modem is always on.
1720 // TODO: this should be fixed in R to support a third
1721 // status UNKNOWN b/131631629
1722 request.result = true;
1723 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1724 + ar.exception);
1725 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001726 notifyRequester(request);
1727 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001728 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1729 request = (MainThreadRequest) msg.obj;
1730 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1731 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1732 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1733 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1734 break;
1735 }
1736 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
1739 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1740 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1741 args.second.accept(ar.exception == null);
1742 notifyRequester(request);
1743 break;
1744 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001745 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1748 Phone phone = getPhoneFromRequest(request);
1749 if (phone != null) {
1750 phone.getSystemSelectionChannels(onCompleted);
1751 } else {
1752 loge("getSystemSelectionChannels: No phone object");
1753 request.result = new ArrayList<RadioAccessSpecifier>();
1754 notifyRequester(request);
1755 }
1756 break;
1757 }
1758 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1759 ar = (AsyncResult) msg.obj;
1760 request = (MainThreadRequest) ar.userObj;
1761 if (ar.exception == null && ar.result != null) {
1762 request.result = ar.result;
1763 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001764 request.result = new IllegalStateException(
1765 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001766 if (ar.result == null) {
1767 loge("getSystemSelectionChannels: Empty response");
1768 } else {
1769 loge("getSystemSelectionChannels: Unknown exception");
1770 }
1771 }
1772 notifyRequester(request);
1773 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001774 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1775 ar = (AsyncResult) msg.obj;
1776 request = (MainThreadRequest) ar.userObj;
1777 if (ar.exception == null && ar.result != null) {
1778 request.result = ar.result;
1779 } else {
1780 request.result = -1;
1781 loge("Failed to set Forbidden Plmns");
1782 if (ar.result == null) {
1783 loge("setForbidenPlmns: Empty response");
1784 } else if (ar.exception != null) {
1785 loge("setForbiddenPlmns: Exception: " + ar.exception);
1786 request.result = -1;
1787 } else {
1788 loge("setForbiddenPlmns: Unknown exception");
1789 }
1790 }
1791 notifyRequester(request);
1792 break;
1793 case CMD_SET_FORBIDDEN_PLMNS:
1794 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001795 uiccPort = getUiccPortFromRequest(request);
1796 if (uiccPort == null) {
1797 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001798 request.result = -1;
1799 notifyRequester(request);
1800 break;
1801 }
1802 Pair<Integer, List<String>> setFplmnsArgs =
1803 (Pair<Integer, List<String>>) request.argument;
1804 appType = setFplmnsArgs.first;
1805 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001806 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001807 if (uiccApp == null) {
1808 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1809 request.result = -1;
1810 loge("Failed to get UICC App");
1811 notifyRequester(request);
1812 } else {
1813 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1814 ((SIMRecords) uiccApp.getIccRecords())
1815 .setForbiddenPlmns(onCompleted, fplmns);
1816 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001817 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001818 case CMD_ERASE_MODEM_CONFIG:
1819 request = (MainThreadRequest) msg.obj;
1820 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1821 defaultPhone.eraseModemConfig(onCompleted);
1822 break;
1823 case EVENT_ERASE_MODEM_CONFIG_DONE:
1824 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001825 break;
zoey chene02881a2019-12-30 16:11:23 +08001826
Kai Shif70f46f2021-03-03 13:59:46 -08001827 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1828 request = (MainThreadRequest) msg.obj;
1829 request.result = defaultPhone.eraseDataInSharedPreferences();
1830 notifyRequester(request);
1831 break;
1832
zoey chene02881a2019-12-30 16:11:23 +08001833 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1834 request = (MainThreadRequest) msg.obj;
1835 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1836 Pair<String, String> changed = (Pair<String, String>) request.argument;
1837 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1838 changed.first, changed.second, onCompleted);
1839 break;
1840 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 if (ar.exception == null) {
1844 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001845 // If the operation is successful, update the PIN storage
1846 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1847 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001848 UiccController.getInstance().getPinStorage()
1849 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001850 } else {
1851 request.result = msg.arg1;
1852 }
1853 notifyRequester(request);
1854 break;
1855
Michele Berionne5e411512020-11-13 02:36:59 +00001856 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001857 request = (MainThreadRequest) msg.obj;
1858 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1859 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1860 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1861 enabled.first, enabled.second, onCompleted);
1862 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001863 }
zoey chene02881a2019-12-30 16:11:23 +08001864 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 if (ar.exception == null) {
1868 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001869 // If the operation is successful, update the PIN storage
1870 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1871 int phoneId = getPhoneFromRequest(request).getPhoneId();
1872 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001873 UiccController.getInstance().getPinStorage()
1874 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001875 } else {
1876 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1877 }
zoey chene02881a2019-12-30 16:11:23 +08001878 } else {
1879 request.result = msg.arg1;
1880 }
Michele Berionne5e411512020-11-13 02:36:59 +00001881
1882
zoey chene02881a2019-12-30 16:11:23 +08001883 notifyRequester(request);
1884 break;
1885
Peter Wangdafb9ac2020-01-15 14:13:38 -08001886 case MSG_NOTIFY_USER_ACTIVITY:
1887 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001888 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001889 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1890 getDefaultPhone().getContext().sendBroadcastAsUser(
1891 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1892 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001893
1894 case CMD_SET_DATA_THROTTLING: {
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1897 DataThrottlingRequest dataThrottlingRequest =
1898 (DataThrottlingRequest) request.argument;
1899 Phone phone = getPhoneFromRequest(request);
1900 if (phone != null) {
1901 phone.setDataThrottling(onCompleted,
1902 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1903 dataThrottlingRequest.getCompletionDurationMillis());
1904 } else {
1905 loge("setDataThrottling: No phone object");
1906 request.result =
1907 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1908 notifyRequester(request);
1909 }
1910
1911 break;
1912 }
1913 case EVENT_SET_DATA_THROTTLING_DONE:
1914 ar = (AsyncResult) msg.obj;
1915 request = (MainThreadRequest) ar.userObj;
1916
1917 if (ar.exception == null) {
1918 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1919 } else if (ar.exception instanceof CommandException) {
1920 loge("setDataThrottling: CommandException: " + ar.exception);
1921 CommandException.Error error =
1922 ((CommandException) (ar.exception)).getCommandError();
1923
1924 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1925 request.result = TelephonyManager
1926 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1927 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1928 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001929 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1930 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001931 } else {
1932 request.result =
1933 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1934 }
1935 } else {
1936 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1937 }
1938 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1939 notifyRequester(request);
1940 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001941
1942 case CMD_SET_SIM_POWER: {
1943 request = (MainThreadRequest) msg.obj;
1944 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1945 request = (MainThreadRequest) msg.obj;
1946 int stateToSet =
1947 ((Pair<Integer, IIntegerConsumer>)
1948 request.argument).first;
1949 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1950 break;
1951 }
1952 case EVENT_SET_SIM_POWER_DONE: {
1953 ar = (AsyncResult) msg.obj;
1954 request = (MainThreadRequest) ar.userObj;
1955 IIntegerConsumer callback =
1956 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1957 if (ar.exception != null) {
1958 loge("setSimPower exception: " + ar.exception);
1959 int errorCode = TelephonyManager.CallForwardingInfoCallback
1960 .RESULT_ERROR_UNKNOWN;
1961 if (ar.exception instanceof CommandException) {
1962 CommandException.Error error =
1963 ((CommandException) (ar.exception)).getCommandError();
1964 if (error == CommandException.Error.SIM_ERR) {
1965 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1966 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1967 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1968 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1969 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1970 } else {
1971 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1972 }
1973 }
1974 try {
1975 callback.accept(errorCode);
1976 } catch (RemoteException e) {
1977 // Ignore if the remote process is no longer available to call back.
1978 Log.w(LOG_TAG, "setSimPower: callback not available.");
1979 }
1980 } else {
1981 try {
1982 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1983 } catch (RemoteException e) {
1984 // Ignore if the remote process is no longer available to call back.
1985 Log.w(LOG_TAG, "setSimPower: callback not available.");
1986 }
1987 }
1988 break;
1989 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001990 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1991 request = (MainThreadRequest) msg.obj;
1992
1993 final Phone phone = getPhoneFromRequest(request);
1994 if (phone == null || phone.getServiceStateTracker() == null) {
1995 request.result = new IllegalStateException("Phone or SST is null");
1996 notifyRequester(request);
1997 break;
1998 }
1999
2000 Pair<Integer, SignalStrengthUpdateRequest> pair =
2001 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2002 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2003 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002004 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002005 request.subId, pair.first /*callingUid*/,
2006 pair.second /*request*/, onCompleted);
2007 break;
2008 }
2009 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2010 ar = (AsyncResult) msg.obj;
2011 request = (MainThreadRequest) ar.userObj;
2012 // request.result will be the exception of ar if present, true otherwise.
2013 // Be cautious not to leave result null which will wait() forever
2014 request.result = ar.exception != null ? ar.exception : true;
2015 notifyRequester(request);
2016 break;
2017 }
2018 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2019 request = (MainThreadRequest) msg.obj;
2020
2021 Phone phone = getPhoneFromRequest(request);
2022 if (phone == null || phone.getServiceStateTracker() == null) {
2023 request.result = new IllegalStateException("Phone or SST is null");
2024 notifyRequester(request);
2025 break;
2026 }
2027
2028 Pair<Integer, SignalStrengthUpdateRequest> pair =
2029 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2030 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2031 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002032 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002033 request.subId, pair.first /*callingUid*/,
2034 pair.second /*request*/, onCompleted);
2035 break;
2036 }
2037 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2038 ar = (AsyncResult) msg.obj;
2039 request = (MainThreadRequest) ar.userObj;
2040 request.result = ar.exception != null ? ar.exception : true;
2041 notifyRequester(request);
2042 break;
2043 }
Jordan Liu109698e2020-11-24 14:50:34 -08002044
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002045 case CMD_GET_SLICING_CONFIG: {
2046 request = (MainThreadRequest) msg.obj;
2047 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2048 request.phone.getSlicingConfig(onCompleted);
2049 break;
2050 }
2051 case EVENT_GET_SLICING_CONFIG_DONE: {
2052 ar = (AsyncResult) msg.obj;
2053 request = (MainThreadRequest) ar.userObj;
2054 ResultReceiver result = (ResultReceiver) request.argument;
2055
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002056 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002057 Bundle bundle = new Bundle();
2058 int resultCode = 0;
2059 if (ar.exception != null) {
2060 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2061 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002062 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002063 } else if (ar.result == null) {
2064 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002065 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002066 } else {
2067 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002068 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2069 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002070 }
2071
2072 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002073 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002074 }
2075 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2076 result.send(resultCode, bundle);
2077 notifyRequester(request);
2078 break;
2079 }
2080
Michele Berionne5e411512020-11-13 02:36:59 +00002081 case CMD_PREPARE_UNATTENDED_REBOOT:
2082 request = (MainThreadRequest) msg.obj;
2083 request.result =
2084 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2085 notifyRequester(request);
2086 break;
2087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 default:
2089 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2090 break;
2091 }
2092 }
Jake Hambye994d462014-02-03 13:10:13 -08002093
Pengquan Menga1bb6272018-09-06 09:59:22 -07002094 private void notifyRequester(MainThreadRequest request) {
2095 synchronized (request) {
2096 request.notifyAll();
2097 }
2098 }
2099
Jake Hambye994d462014-02-03 13:10:13 -08002100 private void handleNullReturnEvent(Message msg, String command) {
2101 AsyncResult ar = (AsyncResult) msg.obj;
2102 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2103 if (ar.exception == null) {
2104 request.result = true;
2105 } else {
2106 request.result = false;
2107 if (ar.exception instanceof CommandException) {
2108 loge(command + ": CommandException: " + ar.exception);
2109 } else {
2110 loge(command + ": Unknown exception");
2111 }
2112 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002113 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
2117 /**
2118 * Posts the specified command to be executed on the main thread,
2119 * waits for the request to complete, and returns the result.
2120 * @see #sendRequestAsync
2121 */
2122 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002123 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2124 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002125 }
2126
2127 /**
2128 * Posts the specified command to be executed on the main thread,
2129 * waits for the request to complete, and returns the result.
2130 * @see #sendRequestAsync
2131 */
2132 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2133 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002134 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002135 }
2136
2137 /**
2138 * Posts the specified command to be executed on the main thread,
2139 * waits for the request to complete, and returns the result.
2140 * @see #sendRequestAsync
2141 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002142 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002143 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2144 }
2145
2146 /**
2147 * Posts the specified command to be executed on the main thread,
2148 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2149 * if not timeout or null otherwise.
2150 * @see #sendRequestAsync
2151 */
2152 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2153 long timeoutInMs) {
2154 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002155 }
2156
2157 /**
2158 * Posts the specified command to be executed on the main thread,
2159 * waits for the request to complete, and returns the result.
2160 * @see #sendRequestAsync
2161 */
Nathan Harold92bed182018-10-12 18:16:49 -07002162 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002163 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002164 }
2165
2166 /**
2167 * Posts the specified command to be executed on the main thread,
2168 * waits for the request to complete, and returns the result.
2169 * @see #sendRequestAsync
2170 */
2171 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002172 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2173 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002174 }
2175
2176 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002177 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2178 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2179 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002180 * @see #sendRequestAsync
2181 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002182 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2183 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2185 throw new RuntimeException("This method will deadlock if called from the main thread.");
2186 }
2187
Nathan Harold92bed182018-10-12 18:16:49 -07002188 MainThreadRequest request = null;
2189 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2190 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2191 } else if (phone != null) {
2192 request = new MainThreadRequest(argument, phone, workSource);
2193 } else {
2194 request = new MainThreadRequest(argument, subId, workSource);
2195 }
2196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 Message msg = mMainThreadHandler.obtainMessage(command, request);
2198 msg.sendToTarget();
2199
Rambo Wang0f050d82021-02-12 11:43:36 -08002200
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 if (timeoutInMs >= 0) {
2203 // Wait for at least timeoutInMs before returning null request result
2204 long now = SystemClock.elapsedRealtime();
2205 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002206 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002207 try {
2208 request.wait(deadline - now);
2209 } catch (InterruptedException e) {
2210 // Do nothing, go back and check if request is completed or timeout
2211 } finally {
2212 now = SystemClock.elapsedRealtime();
2213 }
2214 }
2215 } else {
2216 // Wait for the request to complete
2217 while (request.result == null) {
2218 try {
2219 request.wait();
2220 } catch (InterruptedException e) {
2221 // Do nothing, go back and wait until the request is complete
2222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224 }
2225 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002226 if (request.result == null) {
2227 Log.wtf(LOG_TAG,
2228 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 return request.result;
2231 }
2232
2233 /**
2234 * Asynchronous ("fire and forget") version of sendRequest():
2235 * Posts the specified command to be executed on the main thread, and
2236 * returns immediately.
2237 * @see #sendRequest
2238 */
2239 private void sendRequestAsync(int command) {
2240 mMainThreadHandler.sendEmptyMessage(command);
2241 }
2242
2243 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002244 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002246 */
2247 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002248 sendRequestAsync(command, argument, null, null);
2249 }
2250
2251 /**
2252 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2253 * @see {@link #sendRequest(int,Object)}
2254 */
2255 private void sendRequestAsync(
2256 int command, Object argument, Phone phone, WorkSource workSource) {
2257 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002258 Message msg = mMainThreadHandler.obtainMessage(command, request);
2259 msg.sendToTarget();
2260 }
2261
2262 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 * Initialize the singleton PhoneInterfaceManager instance.
2264 * This is only done once, at startup, from PhoneApp.onCreate().
2265 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002266 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 synchronized (PhoneInterfaceManager.class) {
2268 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002269 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 } else {
2271 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2272 }
2273 return sInstance;
2274 }
2275 }
2276
2277 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002278 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002281 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002282 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002284 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002286 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002287 mTelephonySharedPreferences =
2288 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002289 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002290 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002291 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002292 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002293
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 publish();
2295 }
2296
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002297 private Phone getDefaultPhone() {
2298 Phone thePhone = getPhone(getDefaultSubscription());
2299 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2300 }
2301
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 private void publish() {
2303 if (DBG) log("publish: " + this);
2304
Peter Wangc035ce42020-01-08 21:00:22 -08002305 TelephonyFrameworkInitializer
2306 .getTelephonyServiceManager()
2307 .getTelephonyServiceRegisterer()
2308 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
Stuart Scott584921c2015-01-15 17:10:34 -08002311 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002312 if (request.phone != null) {
2313 return request.phone;
2314 } else {
2315 return getPhoneFromSubId(request.subId);
2316 }
2317 }
2318
2319 private Phone getPhoneFromSubId(int subId) {
2320 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2321 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002322 }
2323
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002324 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002325 Phone phone = getPhoneFromRequest(request);
2326 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002327 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002328 }
2329
Wink Saville36469e72014-06-11 15:17:00 -07002330 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002331 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002332 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334
Kai Shif70f46f2021-03-03 13:59:46 -08002335 private void sendEraseModemConfig(@NonNull Phone phone) {
2336 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2337 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2338 }
2339
2340 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2341 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2342 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002343 }
2344
Peter Wang44b186e2020-01-13 23:33:09 -08002345 private boolean isImsAvailableOnDevice() {
2346 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2347 if (pm == null) {
2348 // For some reason package manger is not available.. This will fail internally anyway,
2349 // so do not throw error and allow.
2350 return true;
2351 }
2352 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2353 }
2354
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002356 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002357 }
2358
Wink Savilleb564aae2014-10-23 10:18:09 -07002359 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 if (DBG) log("dial: " + number);
2361 // No permission check needed here: This is just a wrapper around the
2362 // ACTION_DIAL intent, which is available to any app since it puts up
2363 // the UI before it does anything.
2364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 String url = createTelUrl(number);
2368 if (url == null) {
2369 return;
2370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372 // PENDING: should we just silently fail if phone is offhook or ringing?
2373 PhoneConstants.State state = mCM.getState(subId);
2374 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2375 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2376 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2377 mApp.startActivity(intent);
2378 }
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 }
2382 }
2383
2384 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002385 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002386 }
2387
Wink Savilleb564aae2014-10-23 10:18:09 -07002388 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 if (DBG) log("call: " + number);
2390
2391 // This is just a wrapper around the ACTION_CALL intent, but we still
2392 // need to do a permission check since we're calling startActivity()
2393 // from the context of the phone app.
2394 enforceCallPermission();
2395
Jordan Liu1617b712019-07-10 15:06:26 -07002396 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 != AppOpsManager.MODE_ALLOWED) {
2398 return;
2399 }
2400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 String url = createTelUrl(number);
2404 if (url == null) {
2405 return;
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408 boolean isValid = false;
2409 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2410 if (slist != null) {
2411 for (SubscriptionInfo subInfoRecord : slist) {
2412 if (subInfoRecord.getSubscriptionId() == subId) {
2413 isValid = true;
2414 break;
2415 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002416 }
Wink Saville08874612014-08-31 19:19:58 -07002417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418 if (!isValid) {
2419 return;
2420 }
Wink Saville08874612014-08-31 19:19:58 -07002421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2423 intent.putExtra(SUBSCRIPTION_KEY, subId);
2424 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2425 mApp.startActivity(intent);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002432 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002433 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2434 }
2435
Wink Savilleb564aae2014-10-23 10:18:09 -07002436 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002437 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002438 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2439 }
2440
Wink Savilleb564aae2014-10-23 10:18:09 -07002441 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002446 Phone phone = getPhone(subId);
2447 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 checkSimPin.start();
2449 return checkSimPin.unlockSim(null, pin);
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
2452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
Wink Savilleb564aae2014-10-23 10:18:09 -07002455 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457
2458 final long identity = Binder.clearCallingIdentity();
2459 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002460 Phone phone = getPhone(subId);
2461 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462 checkSimPuk.start();
2463 return checkSimPuk.unlockSim(puk, pin);
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
2466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
2469 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002470 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 * a synchronous one.
2472 */
2473 private static class UnlockSim extends Thread {
2474
2475 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002476 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477
2478 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002479 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2480 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481
2482 // For replies from SimCard interface
2483 private Handler mHandler;
2484
2485 // For async handler to identify request type
2486 private static final int SUPPLY_PIN_COMPLETE = 100;
2487
Michele Berionne5e411512020-11-13 02:36:59 +00002488 UnlockSim(int phoneId, IccCard simCard) {
2489 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 mSimCard = simCard;
2491 }
2492
2493 @Override
2494 public void run() {
2495 Looper.prepare();
2496 synchronized (UnlockSim.this) {
2497 mHandler = new Handler() {
2498 @Override
2499 public void handleMessage(Message msg) {
2500 AsyncResult ar = (AsyncResult) msg.obj;
2501 switch (msg.what) {
2502 case SUPPLY_PIN_COMPLETE:
2503 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2504 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002505 mRetryCount = msg.arg1;
2506 if (ar.exception != null) {
2507 if (ar.exception instanceof CommandException &&
2508 ((CommandException)(ar.exception)).getCommandError()
2509 == CommandException.Error.PASSWORD_INCORRECT) {
2510 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002511 } //When UiccCardApp dispose,handle message and return exception
2512 else if (ar.exception instanceof CommandException &&
2513 ((CommandException) (ar.exception)).getCommandError()
2514 == CommandException.Error.ABORTED) {
2515 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002516 } else {
2517 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2518 }
2519 } else {
2520 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 mDone = true;
2523 UnlockSim.this.notifyAll();
2524 }
2525 break;
2526 }
2527 }
2528 };
2529 UnlockSim.this.notifyAll();
2530 }
2531 Looper.loop();
2532 }
2533
2534 /*
2535 * Use PIN or PUK to unlock SIM card
2536 *
2537 * If PUK is null, unlock SIM card with PIN
2538 *
2539 * If PUK is not null, unlock SIM card with PUK and set PIN code
2540 */
Wink Saville9de0f752013-10-22 19:04:03 -07002541 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542
2543 while (mHandler == null) {
2544 try {
2545 wait();
2546 } catch (InterruptedException e) {
2547 Thread.currentThread().interrupt();
2548 }
2549 }
2550 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2551
2552 if (puk == null) {
2553 mSimCard.supplyPin(pin, callback);
2554 } else {
2555 mSimCard.supplyPuk(puk, pin, callback);
2556 }
2557
2558 while (!mDone) {
2559 try {
2560 Log.d(LOG_TAG, "wait for done");
2561 wait();
2562 } catch (InterruptedException e) {
2563 // Restore the interrupted status
2564 Thread.currentThread().interrupt();
2565 }
2566 }
2567 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002568 int[] resultArray = new int[2];
2569 resultArray[0] = mResult;
2570 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002571
2572 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002573 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002574 }
2575
Wink Saville9de0f752013-10-22 19:04:03 -07002576 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 }
2578 }
2579
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002580 /**
2581 * This method has been removed due to privacy and stability concerns.
2582 */
2583 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002585 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2586 return;
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Nathan Harold1f889d82020-06-04 17:05:26 -07002589 @Override
2590 public void updateServiceLocationWithPackageName(String callingPackage) {
2591 mApp.getSystemService(AppOpsManager.class)
2592 .checkPackage(Binder.getCallingUid(), callingPackage);
2593
Nathan Haroldf096d982020-11-18 17:18:06 -08002594 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002595 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2596 // Callers targeting S have no business invoking this method.
2597 return;
2598 }
2599
2600 LocationAccessPolicy.LocationPermissionResult locationResult =
2601 LocationAccessPolicy.checkLocationPermission(mApp,
2602 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2603 .setCallingPackage(callingPackage)
2604 .setCallingFeatureId(null)
2605 .setCallingPid(Binder.getCallingPid())
2606 .setCallingUid(Binder.getCallingUid())
2607 .setMethod("updateServiceLocation")
2608 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2609 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2610 .build());
2611 // Apps that lack location permission have no business calling this method;
2612 // however, because no permission was declared in the public API, denials must
2613 // all be "soft".
2614 switch (locationResult) {
2615 case DENIED_HARD: /* fall through */
2616 case DENIED_SOFT:
2617 return;
2618 }
2619
2620 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002623 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002625 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 @Override
2634 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002635 return isRadioOnWithFeature(callingPackage, null);
2636 }
2637
2638
2639 @Override
2640 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2641 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2642 callingFeatureId);
2643 }
2644
2645 @Deprecated
2646 @Override
2647 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2648 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002649 }
2650
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002651 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002652 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2653 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002655 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002656 return false;
2657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658
2659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 return isRadioOnForSubscriber(subId);
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002665 }
2666
2667 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone != null) {
2672 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2673 } else {
2674 return false;
2675 }
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 }
2680
2681 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002682 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 }
Wink Saville36469e72014-06-11 15:17:00 -07002684
Wink Savilleb564aae2014-10-23 10:18:09 -07002685 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 final Phone phone = getPhone(subId);
2691 if (phone != null) {
2692 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2693 }
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002696 }
Wink Saville36469e72014-06-11 15:17:00 -07002697 }
2698
2699 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002700 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002701 }
2702
Wink Savilleb564aae2014-10-23 10:18:09 -07002703 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 final Phone phone = getPhone(subId);
2709 if (phone == null) {
2710 return false;
2711 }
2712 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2713 toggleRadioOnOffForSubscriber(subId);
2714 }
2715 return true;
2716 } finally {
2717 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 }
Wink Saville36469e72014-06-11 15:17:00 -07002720
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002721 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002722 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002723 /*
2724 * If any of the Radios are available, it will need to be
2725 * shutdown. So return true if any Radio is available.
2726 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2730 Phone phone = PhoneFactory.getPhone(i);
2731 if (phone != null && phone.isRadioAvailable()) return true;
2732 }
2733 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2734 return false;
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002737 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002738 }
2739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002741 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 enforceModifyPermission();
2743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2747 logv("Shutting down Phone " + i);
2748 shutdownRadioUsingPhoneId(i);
2749 }
2750 } finally {
2751 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002752 }
2753 }
2754
2755 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002756 Phone phone = PhoneFactory.getPhone(phoneId);
2757 if (phone != null && phone.isRadioAvailable()) {
2758 phone.shutdownRadio();
2759 }
2760 }
2761
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2768 if (defaultPhone != null) {
2769 defaultPhone.setRadioPower(turnOn);
2770 return true;
2771 } else {
2772 loge("There's no default phone.");
2773 return false;
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002777 }
Wink Saville36469e72014-06-11 15:17:00 -07002778 }
2779
Wink Savilleb564aae2014-10-23 10:18:09 -07002780 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
2787 phone.setRadioPower(turnOn);
2788 return true;
2789 } else {
2790 return false;
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
Wink Saville36469e72014-06-11 15:17:00 -07002797 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002798 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 public boolean enableDataConnectivity() {
2800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 int subId = mSubscriptionController.getDefaultDataSubId();
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002807 if (phone.isUsingNewDataStack()) {
2808 phone.getDataSettingsManager().setDataEnabled(
2809 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2810 } else {
2811 phone.getDataEnabledSettings().setDataEnabled(
2812 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 return true;
2815 } else {
2816 return false;
2817 }
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
2822
Wink Saville36469e72014-06-11 15:17:00 -07002823 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002824 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 public boolean disableDataConnectivity() {
2826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827
2828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 int subId = mSubscriptionController.getDefaultDataSubId();
2831 final Phone phone = getPhone(subId);
2832 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002833 if (phone.isUsingNewDataStack()) {
2834 phone.getDataSettingsManager().setDataEnabled(
2835 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2836 } else {
2837 phone.getDataEnabledSettings().setDataEnabled(
2838 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840 return true;
2841 } else {
2842 return false;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002850 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 final Phone phone = getPhone(subId);
2854 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002855 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 } else {
2857 return false;
2858 }
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
2864 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002865 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002866 }
2867
pkanwarae03a6b2016-11-06 20:37:09 -08002868 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 enforceCallPermission();
2870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 return;
2875 }
2876 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2877 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
pkanwar32d516d2016-10-14 19:37:38 -07002881 };
2882
Wink Savilleb564aae2014-10-23 10:18:09 -07002883 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2889 return false;
2890 }
2891 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002897 /**
2898 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2899 * tag on getCallState Binder call.
2900 */
2901 @Deprecated
2902 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002903 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002904 if (CompatChanges.isChangeEnabled(
2905 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2906 Binder.getCallingUid())) {
2907 // Do not allow this API to be called on API version 31+, it should only be
2908 // called on old apps using this Binder call directly.
2909 throw new SecurityException("This method can only be used for applications "
2910 + "targeting API version 30 or less.");
2911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912 final long identity = Binder.clearCallingIdentity();
2913 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002914 Phone phone = getPhone(getDefaultSubscription());
2915 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2916 PhoneConstantConversions.convertCallState(phone.getState());
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
2920 }
2921
2922 @Override
2923 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2924 if (CompatChanges.isChangeEnabled(
2925 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2926 Binder.getCallingUid())) {
2927 // Check READ_PHONE_STATE for API version 31+
2928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2929 featureId, "getCallStateForSubscription")) {
2930 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2931 + "targeting API level 31+.");
2932 }
2933 }
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2938 PhoneConstantConversions.convertCallState(phone.getState());
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 }
2943
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002945 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002946 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2947 }
2948
2949 @Override
2950 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002953 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08002955 if (phone.isUsingNewDataStack()) {
2956 return phone.getDataNetworkController().getInternetDataNetworkState();
2957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2959 } else {
2960 return PhoneConstantConversions.convertDataState(
2961 PhoneConstants.DataState.DISCONNECTED);
2962 }
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966 }
2967
Sanket Padawe356d7632015-06-22 14:03:32 -07002968 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002969 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002970 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2971 }
2972
2973 @Override
2974 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 final long identity = Binder.clearCallingIdentity();
2976 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002977 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 if (phone != null) {
2979 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2980 } else {
2981 return TelephonyManager.DATA_ACTIVITY_NONE;
2982 }
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 }
2987
2988 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002989 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002991 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002992
2993 LocationAccessPolicy.LocationPermissionResult locationResult =
2994 LocationAccessPolicy.checkLocationPermission(mApp,
2995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2996 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002997 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002998 .setCallingPid(Binder.getCallingPid())
2999 .setCallingUid(Binder.getCallingUid())
3000 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003001 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003002 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3003 .build());
3004 switch (locationResult) {
3005 case DENIED_HARD:
3006 throw new SecurityException("Not allowed to access cell location");
3007 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003008 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3009 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 }
3011
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003012 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003016 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003017 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
Svetoslav64fad262015-04-14 14:35:21 -07003021 }
3022
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003024 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003025 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3026 // registered cell info, so return a NULL country instead.
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003029 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3030 // Get default phone in this case.
3031 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3032 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003033 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003035 if (phone == null) return "";
3036 ServiceStateTracker sst = phone.getServiceStateTracker();
3037 if (sst == null) return "";
3038 LocaleTracker lt = sst.getLocaleTracker();
3039 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003040 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003044 }
3045
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003046 /**
3047 * This method was removed due to potential issues caused by performing partial
3048 * updates of service state, and lack of a credible use case.
3049 *
3050 * This has the ability to break the telephony implementation by disabling notification of
3051 * changes in device connectivity. DO NOT USE THIS!
3052 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003053 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 public void enableLocationUpdates() {
3055 mApp.enforceCallingOrSelfPermission(
3056 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003059 /**
3060 * This method was removed due to potential issues caused by performing partial
3061 * updates of service state, and lack of a credible use case.
3062 *
3063 * This has the ability to break the telephony implementation by disabling notification of
3064 * changes in device connectivity. DO NOT USE THIS!
3065 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 @Override
3067 public void disableLocationUpdates() {
3068 mApp.enforceCallingOrSelfPermission(
3069 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003070 }
3071
3072 @Override
3073 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003074 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3075 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003076 try {
3077 mApp.getSystemService(AppOpsManager.class)
3078 .checkPackage(Binder.getCallingUid(), callingPackage);
3079 } catch (SecurityException e) {
3080 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3081 throw e;
3082 }
3083
Nathan Haroldf096d982020-11-18 17:18:06 -08003084 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003085 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3086 throw new SecurityException(
3087 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3088 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003089
Jordan Liu1617b712019-07-10 15:06:26 -07003090 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3092 return null;
3093 }
Svetoslav64fad262015-04-14 14:35:21 -07003094
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003095 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003097 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003098 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099
Nathan Haroldf180aac2018-06-01 18:43:55 -07003100 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3101 for (CellInfo ci : info) {
3102 if (ci instanceof CellInfoGsm) {
3103 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3104 } else if (ci instanceof CellInfoWcdma) {
3105 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003108 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 }
3110
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003111 private List<CellInfo> getCachedCellInfo() {
3112 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3113 for (Phone phone : PhoneFactory.getPhones()) {
3114 List<CellInfo> info = phone.getAllCellInfo();
3115 if (info != null) cellInfos.addAll(info);
3116 }
3117 return cellInfos;
3118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119
3120 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003121 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003122 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003123 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003124
3125 LocationAccessPolicy.LocationPermissionResult locationResult =
3126 LocationAccessPolicy.checkLocationPermission(mApp,
3127 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3128 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003129 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003130 .setCallingPid(Binder.getCallingPid())
3131 .setCallingUid(Binder.getCallingUid())
3132 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003133 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003134 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3135 .build());
3136 switch (locationResult) {
3137 case DENIED_HARD:
3138 throw new SecurityException("Not allowed to access cell info");
3139 case DENIED_SOFT:
3140 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 }
3142
Nathan Haroldf096d982020-11-18 17:18:06 -08003143 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3145 return getCachedCellInfo();
3146 }
3147
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003148 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003149 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3153 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003154 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003155 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 if (info != null) cellInfos.addAll(info);
3157 }
3158 return cellInfos;
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161 }
3162 }
3163
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003164 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003165 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3166 String callingFeatureId) {
3167 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3168 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 }
3170
3171 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3173 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003174 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003175 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003176 }
3177
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003178 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3179 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003181 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003182
3183 LocationAccessPolicy.LocationPermissionResult locationResult =
3184 LocationAccessPolicy.checkLocationPermission(mApp,
3185 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3186 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003187 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003188 .setCallingPid(Binder.getCallingPid())
3189 .setCallingUid(Binder.getCallingUid())
3190 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003191 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3192 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003193 .build());
3194 switch (locationResult) {
3195 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003196 if (TelephonyPermissions
3197 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003198 // Safetynet logging for b/154934934
3199 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3200 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003201 throw new SecurityException("Not allowed to access cell info");
3202 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003203 if (TelephonyPermissions
3204 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003205 // Safetynet logging for b/154934934
3206 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3207 }
Nathan Harold5320c422019-05-09 10:26:08 -07003208 try {
3209 cb.onCellInfo(new ArrayList<CellInfo>());
3210 } catch (RemoteException re) {
3211 // Drop without consequences
3212 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003213 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003214 }
3215
Nathan Harolda939a962019-05-09 10:13:47 -07003216
3217 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003218 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3219
3220 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3221 }
3222
3223 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003225 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003230 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231 } finally {
3232 Binder.restoreCallingIdentity(identity);
3233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003234 }
3235
Shishir Agrawala9f32182016-04-12 12:00:16 -07003236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003237 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003238 Phone phone = PhoneFactory.getPhone(slotIndex);
3239 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003240 return null;
3241 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003242 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003243 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003244 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003245 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003246 return null;
3247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248
3249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 return phone.getImei();
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
3254 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003255 }
3256
3257 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003258 public String getTypeAllocationCodeForSlot(int slotIndex) {
3259 Phone phone = PhoneFactory.getPhone(slotIndex);
3260 String tac = null;
3261 if (phone != null) {
3262 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003263 try {
3264 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3265 } catch (IndexOutOfBoundsException e) {
3266 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3267 return null;
3268 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003269 }
3270 return tac;
3271 }
3272
3273 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003274 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003275 try {
3276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3277 } catch (SecurityException se) {
3278 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3279 throw new SecurityException("Package " + callingPackage + " does not belong to "
3280 + Binder.getCallingUid());
3281 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 Phone phone = PhoneFactory.getPhone(slotIndex);
3283 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003284 return null;
3285 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003288 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003289 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003290 return null;
3291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 return phone.getMeid();
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
Jack Yu2af8d712017-03-15 17:14:14 -07003299 }
3300
3301 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003302 public String getManufacturerCodeForSlot(int slotIndex) {
3303 Phone phone = PhoneFactory.getPhone(slotIndex);
3304 String manufacturerCode = null;
3305 if (phone != null) {
3306 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003307 try {
3308 manufacturerCode =
3309 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3310 } catch (IndexOutOfBoundsException e) {
3311 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3312 return null;
3313 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003314 }
3315 return manufacturerCode;
3316 }
3317
3318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003319 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3320 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003321 Phone phone = PhoneFactory.getPhone(slotIndex);
3322 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003323 return null;
3324 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003325 int subId = phone.getSubId();
3326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003327 mApp, subId, callingPackage, callingFeatureId,
3328 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003329 return null;
3330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 return phone.getDeviceSvn();
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003338 }
3339
fionaxu43304da2017-11-27 22:51:16 -08003340 @Override
3341 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = getPhone(subId);
3345 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
fionaxu43304da2017-11-27 22:51:16 -08003349 }
3350
3351 @Override
3352 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 final Phone phone = getPhone(subId);
3356 return phone == null ? null : phone.getCarrierName();
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
fionaxu43304da2017-11-27 22:51:16 -08003360 }
3361
calvinpanffe225e2018-11-01 19:43:06 +08003362 @Override
chen xu0026ca62019-03-06 15:28:50 -08003363 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 final Phone phone = getPhone(subId);
3367 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003368 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
chen xu0026ca62019-03-06 15:28:50 -08003375 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003379 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
3383 }
3384
chen xu651eec72018-11-11 19:03:44 -08003385 @Override
chen xu864e11c2018-12-06 22:10:03 -08003386 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3387 if (!isSubscriptionMccMnc) {
3388 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3389 }
chen xu651eec72018-11-11 19:03:44 -08003390 final Phone phone = PhoneFactory.getPhone(slotIndex);
3391 if (phone == null) {
3392 return TelephonyManager.UNKNOWN_CARRIER_ID;
3393 }
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
3400 }
3401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 //
3403 // Internal helper methods.
3404 //
3405
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003406 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003407 * Make sure the caller is the calling package itself
3408 *
3409 * @throws SecurityException if the caller is not the calling package
3410 */
3411 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3412 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003413 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3414 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003415 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003416 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003417 } catch (PackageManager.NameNotFoundException e) {
3418 // packageUid is -1
3419 }
3420 if (packageUid != callingUid) {
3421 throw new SecurityException(message + ": Package " + callingPackage
3422 + " does not belong to " + callingUid);
3423 }
3424 }
3425
3426 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3428 *
3429 * @throws SecurityException if the caller does not have the required permission
3430 */
3431 private void enforceModifyPermission() {
3432 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3433 }
3434
Shuo Qian3b6ee772019-11-13 17:43:31 -08003435 private void enforceActiveEmergencySessionPermission() {
3436 mApp.enforceCallingOrSelfPermission(
3437 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3438 }
3439
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 /**
3441 * Make sure the caller has the CALL_PHONE permission.
3442 *
3443 * @throws SecurityException if the caller does not have the required permission
3444 */
3445 private void enforceCallPermission() {
3446 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3447 }
3448
paulhu5a773602019-08-23 19:17:33 +08003449 private void enforceSettingsPermission() {
3450 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003451 }
3452
Michele Berionne5e411512020-11-13 02:36:59 +00003453 private void enforceRebootPermission() {
3454 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3455 }
3456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003457 private String createTelUrl(String number) {
3458 if (TextUtils.isEmpty(number)) {
3459 return null;
3460 }
3461
Jake Hambye994d462014-02-03 13:10:13 -08003462 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 }
3464
Ihab Awadf9e92732013-12-05 18:02:52 -08003465 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3467 }
3468
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003469 private static void logv(String msg) {
3470 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3471 }
3472
Ihab Awadf9e92732013-12-05 18:02:52 -08003473 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3475 }
3476
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003477 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003479 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003480 }
3481
Sanket Padawe356d7632015-06-22 14:03:32 -07003482 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003483 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484 final long identity = Binder.clearCallingIdentity();
3485 try {
3486 final Phone phone = PhoneFactory.getPhone(slotIndex);
3487 if (phone == null) {
3488 return PhoneConstants.PHONE_TYPE_NONE;
3489 } else {
3490 return phone.getPhoneType();
3491 }
3492 } finally {
3493 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003495 }
3496
3497 /**
3498 * Returns the CDMA ERI icon index to display
3499 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003500 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003501 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3502 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3503 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003504 }
3505
Sanket Padawe356d7632015-06-22 14:03:32 -07003506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003507 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3508 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003510 mApp, subId, callingPackage, callingFeatureId,
3511 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003512 return -1;
3513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
3515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 final Phone phone = getPhone(subId);
3518 if (phone != null) {
3519 return phone.getCdmaEriIconIndex();
3520 } else {
3521 return -1;
3522 }
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
3528 /**
3529 * Returns the CDMA ERI icon mode,
3530 * 0 - ON
3531 * 1 - FLASHING
3532 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003534 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3535 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3536 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003537 }
3538
Sanket Padawe356d7632015-06-22 14:03:32 -07003539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003540 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3541 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003543 mApp, subId, callingPackage, callingFeatureId,
3544 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003545 return -1;
3546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 final Phone phone = getPhone(subId);
3551 if (phone != null) {
3552 return phone.getCdmaEriIconMode();
3553 } else {
3554 return -1;
3555 }
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003559 }
3560
3561 /**
3562 * Returns the CDMA ERI text,
3563 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003565 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3566 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3567 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003568 }
3569
Sanket Padawe356d7632015-06-22 14:03:32 -07003570 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003571 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3572 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003574 mApp, subId, callingPackage, callingFeatureId,
3575 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003576 return null;
3577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578
3579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 if (phone != null) {
3583 return phone.getCdmaEriText();
3584 } else {
3585 return null;
3586 }
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003590 }
3591
3592 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003593 * Returns the CDMA MDN.
3594 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003595 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003596 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3598 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599
3600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003603 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 return phone.getLine1Number();
3605 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607 return null;
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003611 }
3612 }
3613
3614 /**
3615 * Returns the CDMA MIN.
3616 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003617 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003618 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3620 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3626 return phone.getCdmaMin();
3627 } else {
3628 return null;
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003632 }
3633 }
3634
Hall Liud892bec2018-11-30 14:51:45 -08003635 @Override
3636 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3637 INumberVerificationCallback callback, String callingPackage) {
3638 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3639 != PERMISSION_GRANTED) {
3640 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3641 }
3642 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3643
3644 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3645 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003646 throw new SecurityException("Calling package must be configured in the device config: "
3647 + "calling package: " + callingPackage
3648 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003649 }
3650
3651 if (range == null) {
3652 throw new NullPointerException("Range must be non-null");
3653 }
3654
3655 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003656 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003657
3658 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3659 }
3660
Junda Liuca05d5d2014-08-14 22:36:34 -07003661 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003662 * Returns true if CDMA provisioning needs to run.
3663 */
3664 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003671 }
3672
3673 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003674 * Sets the voice mail number of a given subId.
3675 */
3676 @Override
3677 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003678 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3679 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3684 new Pair<String, String>(alphaTag, number), new Integer(subId));
3685 return success;
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003689 }
3690
Ta-wei Yen87c49842016-05-13 21:19:52 -07003691 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003692 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003694 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3695 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003696 if (!TextUtils.equals(callingPackage, systemDialer)) {
3697 throw new SecurityException("caller must be system dialer");
3698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3703 if (phoneAccountHandle == null) {
3704 return null;
3705 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003709 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003710 }
3711
3712 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003713 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3714 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003717 mApp, subId, callingPackage, callingFeatureId,
3718 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003719 return null;
3720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003722 final long identity = Binder.clearCallingIdentity();
3723 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003728 }
3729
3730 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003731 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3732 VisualVoicemailSmsFilterSettings settings) {
3733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 }
3743
3744 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003745 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
3748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003751 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003755 }
3756
3757 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003758 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3759 String callingPackage, int subId) {
3760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003765 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003769 }
3770
3771 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003772 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003778 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779 } finally {
3780 Binder.restoreCallingIdentity(identity);
3781 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003782 }
3783
3784 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003785 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3786 String callingAttributionTag, int subId, String number, int port, String text,
3787 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003788 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003789 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003790 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003791 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003792 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3793 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003794 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003795
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003796 /**
fionaxu0152e512016-11-14 13:36:14 -08003797 * Sets the voice activation state of a given subId.
3798 */
3799 @Override
3800 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3802 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803
3804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 final Phone phone = getPhone(subId);
3807 if (phone != null) {
3808 phone.setVoiceActivationState(activationState);
3809 } else {
3810 loge("setVoiceActivationState fails with invalid subId: " + subId);
3811 }
3812 } finally {
3813 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003814 }
3815 }
3816
3817 /**
3818 * Sets the data activation state of a given subId.
3819 */
3820 @Override
3821 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3823 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824
3825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 final Phone phone = getPhone(subId);
3828 if (phone != null) {
3829 phone.setDataActivationState(activationState);
3830 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003831 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 }
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003835 }
3836 }
3837
3838 /**
3839 * Returns the voice activation state of a given subId.
3840 */
3841 @Override
3842 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844
fionaxu0152e512016-11-14 13:36:14 -08003845 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846 final long identity = Binder.clearCallingIdentity();
3847 try {
3848 if (phone != null) {
3849 return phone.getVoiceActivationState();
3850 } else {
3851 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3852 }
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003855 }
3856 }
3857
3858 /**
3859 * Returns the data activation state of a given subId.
3860 */
3861 @Override
3862 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864
fionaxu0152e512016-11-14 13:36:14 -08003865 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 if (phone != null) {
3869 return phone.getDataActivationState();
3870 } else {
3871 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3872 }
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003875 }
3876 }
3877
3878 /**
Wink Saville36469e72014-06-11 15:17:00 -07003879 * Returns the unread count of voicemails for a subId
3880 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003882 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3883 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003885 mApp, subId, callingPackage, callingFeatureId,
3886 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003887 return 0;
3888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 final Phone phone = getPhone(subId);
3892 if (phone != null) {
3893 return phone.getVoiceMessageCount();
3894 } else {
3895 return 0;
3896 }
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003900 }
3901
3902 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003903 * returns true, if the device is in a state where both voice and data
3904 * are supported simultaneously. This can change based on location or network condition.
3905 */
3906 @Override
3907 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 final Phone phone = getPhone(subId);
3911 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003915 }
3916
3917 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003918 * Send the dialer code if called from the current default dialer or the caller has
3919 * carrier privilege.
3920 * @param inputCode The dialer code to send
3921 */
3922 @Override
3923 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003924 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003926 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3927 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003928 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003930 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003935 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936 } finally {
3937 Binder.restoreCallingIdentity(identity);
3938 }
fionaxu235cc5e2017-03-06 22:25:57 -08003939 }
3940
Pengquan Menga1bb6272018-09-06 09:59:22 -07003941 @Override
3942 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003943 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003944 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003945 mApp, subId, "getNetworkSelectionMode");
3946 final long identity = Binder.clearCallingIdentity();
3947 try {
3948 if (!isActiveSubscription(subId)) {
3949 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3950 }
3951 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003955 }
3956
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003958 public boolean isInEmergencySmsMode() {
3959 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 for (Phone phone : PhoneFactory.getPhones()) {
3963 if (phone.isInEmergencySmsMode()) {
3964 return true;
3965 }
3966 }
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
3970 return false;
3971 }
3972
shilu366312e2019-12-17 09:28:10 -08003973 /**
3974 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3975 * @param subId The subscription to use to check the configuration.
3976 * @param c The callback that will be used to send the result.
3977 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003978 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003979 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3980 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003981 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003982 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003983
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003984 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3985 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3986 "IMS not available on device.");
3987 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 final long token = Binder.clearCallingIdentity();
3989 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003990 int slotId = getSlotIndexOrException(subId);
3991 verifyImsMmTelConfiguredOrThrow(slotId);
3992 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(token);
3997 }
3998 }
3999
shilu366312e2019-12-17 09:28:10 -08004000 /**
4001 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4002 * @param subId The subscription to use to check the configuration.
4003 * @param c The callback that will be used to send the result.
4004 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004006 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004008 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004009 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4010 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4011 }
Meng Wangafbc5852019-09-19 17:37:13 -07004012 final long token = Binder.clearCallingIdentity();
4013 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4015 .removeRegistrationCallbackForSubscription(c, subId);
4016 } catch (ImsException e) {
4017 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4018 + "is inactive, ignoring unregister.");
4019 // If the subscription is no longer active, just return, since the callback
4020 // will already have been removed internally.
4021 } finally {
4022 Binder.restoreCallingIdentity(token);
4023 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 }
4025
Brad Ebingera34a6c22019-10-22 17:36:18 -07004026 /**
4027 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4028 */
4029 @Override
4030 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4031 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4034 "IMS not available on device.");
4035 }
4036 final long token = Binder.clearCallingIdentity();
4037 try {
4038 Phone phone = getPhone(subId);
4039 if (phone == null) {
4040 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4041 + subId + "'");
4042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4043 }
4044 phone.getImsRegistrationState(regState -> {
4045 try {
4046 consumer.accept((regState == null)
4047 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4048 } catch (RemoteException e) {
4049 // Ignore if the remote process is no longer available to call back.
4050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4051 }
4052 });
4053 } finally {
4054 Binder.restoreCallingIdentity(token);
4055 }
4056 }
4057
4058 /**
4059 * Get the transport type for the IMS service registration state.
4060 */
4061 @Override
4062 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004063 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004064 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004065 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4066 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4067 "IMS not available on device.");
4068 }
4069 final long token = Binder.clearCallingIdentity();
4070 try {
4071 Phone phone = getPhone(subId);
4072 if (phone == null) {
4073 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4074 + subId + "'");
4075 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4076 }
4077 phone.getImsRegistrationTech(regTech -> {
4078 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4079 int regTechConverted = (regTech == null)
4080 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4081 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4082 regTechConverted);
4083 try {
4084 consumer.accept(regTechConverted);
4085 } catch (RemoteException e) {
4086 // Ignore if the remote process is no longer available to call back.
4087 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4088 }
4089 });
4090 } finally {
4091 Binder.restoreCallingIdentity(token);
4092 }
4093 }
4094
shilu366312e2019-12-17 09:28:10 -08004095 /**
4096 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4097 * @param subId The subscription to use to check the configuration.
4098 * @param c The callback that will be used to send the result.
4099 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004101 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4102 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004103 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004104 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004105 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4106 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4107 "IMS not available on device.");
4108 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 final long token = Binder.clearCallingIdentity();
4110 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004111 int slotId = getSlotIndexOrException(subId);
4112 verifyImsMmTelConfiguredOrThrow(slotId);
4113 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004114 } catch (ImsException e) {
4115 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 } finally {
4117 Binder.restoreCallingIdentity(token);
4118 }
4119 }
4120
shilu366312e2019-12-17 09:28:10 -08004121 /**
4122 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4123 * @param subId The subscription to use to check the configuration.
4124 * @param c The callback that will be used to send the result.
4125 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004127 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004129 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004130 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4131 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4132 }
Meng Wangafbc5852019-09-19 17:37:13 -07004133
4134 final long token = Binder.clearCallingIdentity();
4135 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004136 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004137 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004138 } catch (ImsException e) {
4139 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4140 + "is inactive, ignoring unregister.");
4141 // If the subscription is no longer active, just return, since the callback
4142 // will already have been removed internally.
4143 } finally {
4144 Binder.restoreCallingIdentity(token);
4145 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 }
4147
4148 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004149 public boolean isCapable(int subId, int capability, int regTech) {
4150 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 final long token = Binder.clearCallingIdentity();
4152 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004153 int slotId = getSlotIndexOrException(subId);
4154 verifyImsMmTelConfiguredOrThrow(slotId);
4155 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4158 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004160 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4161 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 } finally {
4163 Binder.restoreCallingIdentity(token);
4164 }
4165 }
4166
4167 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004168 public boolean isAvailable(int subId, int capability, int regTech) {
4169 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 final long token = Binder.clearCallingIdentity();
4171 try {
4172 Phone phone = getPhone(subId);
4173 if (phone == null) return false;
4174 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004175 } catch (com.android.ims.ImsException e) {
4176 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4177 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 } finally {
4179 Binder.restoreCallingIdentity(token);
4180 }
4181 }
4182
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004183 /**
4184 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4185 * subscription.
4186 * @param subId The subscription to use to check the configuration.
4187 * @param callback The callback that will be used to send the result.
4188 * @param capability The MmTelFeature capability that will be used to send the result.
4189 * @param transportType The transport type of the MmTelFeature capability.
4190 */
4191 @Override
4192 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4193 int transportType) {
4194 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4195 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4196 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4197 "IMS not available on device.");
4198 }
4199 final long token = Binder.clearCallingIdentity();
4200 try {
4201 int slotId = getSlotIndex(subId);
4202 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4203 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4204 + subId + "'");
4205 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4206 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004207 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004208 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4209 transportType, aBoolean -> {
4210 try {
4211 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4212 } catch (RemoteException e) {
4213 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4214 + "running. Ignore");
4215 }
4216 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004217 } catch (ImsException e) {
4218 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004219 } finally {
4220 Binder.restoreCallingIdentity(token);
4221 }
4222 }
4223
shilu366312e2019-12-17 09:28:10 -08004224 /**
4225 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4226 * @param subId The subscription to use to check the configuration.
4227 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 @Override
4229 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004230 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004231 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004232
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 final long token = Binder.clearCallingIdentity();
4234 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004235 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004236 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004237 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004238 } catch (ImsException e) {
4239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 } finally {
4241 Binder.restoreCallingIdentity(token);
4242 }
4243 }
4244
4245 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004246 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004248 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004249 final long identity = Binder.clearCallingIdentity();
4250 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004251 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004252 // This setting doesn't require an active ImsService connection, so do not verify. The
4253 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004254 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004255 } catch (ImsException e) {
4256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 } finally {
4258 Binder.restoreCallingIdentity(identity);
4259 }
4260 }
4261
shilu366312e2019-12-17 09:28:10 -08004262 /**
4263 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4264 * @param subId The subscription to use to check the configuration.
4265 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004267 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004268 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004269 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 final long identity = Binder.clearCallingIdentity();
4271 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004272 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004273 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004274 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004275 } catch (ImsException e) {
4276 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 } finally {
4278 Binder.restoreCallingIdentity(identity);
4279 }
4280 }
4281
4282 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004283 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004285 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 final long identity = Binder.clearCallingIdentity();
4287 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004289 // This setting doesn't require an active ImsService connection, so do not verify. The
4290 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004291 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004292 } catch (ImsException e) {
4293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
4297 }
4298
shilu366312e2019-12-17 09:28:10 -08004299 /**
4300 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4301 * @param subId The subscription to use to check the configuration.
4302 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 @Override
4304 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004305 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004306 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 final long identity = Binder.clearCallingIdentity();
4308 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004309 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004310 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004311 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004312 } catch (ImsException e) {
4313 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
4317 }
4318
4319 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004320 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004322 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004323 final long identity = Binder.clearCallingIdentity();
4324 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004326 // This setting doesn't require an active ImsService connection, so do not verify. The
4327 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004328 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004329 } catch (ImsException e) {
4330 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004331 } finally {
4332 Binder.restoreCallingIdentity(identity);
4333 }
4334 }
4335
shilu366312e2019-12-17 09:28:10 -08004336 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004337 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4338 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4339 * @param subId The subscription to use to check the configuration.
4340 */
4341 @Override
4342 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004343 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004344 mApp, subId, "isCrossSimCallingEnabledByUser");
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004347 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004348 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004349 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004350 } catch (ImsException e) {
4351 throw new ServiceSpecificException(e.getCode());
4352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
4355 }
4356
4357 /**
4358 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4359 * Requires MODIFY_PHONE_STATE permission.
4360 * @param subId The subscription to use to check the configuration.
4361 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4362 * false otherwise
4363 */
4364 @Override
4365 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4367 "setCrossSimCallingEnabled");
4368 final long identity = Binder.clearCallingIdentity();
4369 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004371 // This setting doesn't require an active ImsService connection, so do not verify. The
4372 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004374 } catch (ImsException e) {
4375 throw new ServiceSpecificException(e.getCode());
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
4379 }
4380
4381 /**
shilu366312e2019-12-17 09:28:10 -08004382 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4383 * @param subId The subscription to use to check the configuration.
4384 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004386
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004388 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004389 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 final long identity = Binder.clearCallingIdentity();
4391 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004392 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004393 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004394 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004395 } catch (ImsException e) {
4396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
4402 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004403 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004405 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004406 final long identity = Binder.clearCallingIdentity();
4407 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004408 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004409 // This setting doesn't require an active ImsService connection, so do not verify. The
4410 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004412 } catch (ImsException e) {
4413 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
4417 }
4418
4419 @Override
4420 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4422 "setVoWiFiNonPersistent");
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004426 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004427 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004428 } catch (ImsException e) {
4429 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
4433 }
4434
shilu366312e2019-12-17 09:28:10 -08004435 /**
4436 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4437 * @param subId The subscription to use to check the configuration.
4438 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 @Override
4440 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004441 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004442 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004443 final long identity = Binder.clearCallingIdentity();
4444 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004446 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004447 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004448 } catch (ImsException e) {
4449 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
4453 }
4454
4455 @Override
4456 public void setVoWiFiModeSetting(int subId, int mode) {
4457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4458 "setVoWiFiModeSetting");
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004462 // This setting doesn't require an active ImsService connection, so do not verify. The
4463 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004465 } catch (ImsException e) {
4466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
4470 }
4471
4472 @Override
4473 public int getVoWiFiRoamingModeSetting(int subId) {
4474 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004478 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004479 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004480 } catch (ImsException e) {
4481 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485 }
4486
4487 @Override
4488 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4490 "setVoWiFiRoamingModeSetting");
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004494 // This setting doesn't require an active ImsService connection, so do not verify. The
4495 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004497 } catch (ImsException e) {
4498 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
4502 }
4503
4504 @Override
4505 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4507 "setRttCapabilityEnabled");
4508 final long identity = Binder.clearCallingIdentity();
4509 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004511 // This setting doesn't require an active ImsService connection, so do not verify. The
4512 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004513 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004514 } catch (ImsException e) {
4515 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
4519 }
4520
shilu366312e2019-12-17 09:28:10 -08004521 /**
4522 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4523 * @param subId The subscription to use to check the configuration.
4524 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004525 @Override
4526 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004527 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004528 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004531 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004532 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004533 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004534 } catch (ImsException e) {
4535 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
4539 }
4540
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004541 @Override
4542 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4543 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004544
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004545 final long identity = Binder.clearCallingIdentity();
4546 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004547 if (!isImsAvailableOnDevice()) {
4548 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4549 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004550 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004551 int slotId = getSlotIndexOrException(subId);
4552 verifyImsMmTelConfiguredOrThrow(slotId);
4553 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004554 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004555 } catch (ImsException e) {
4556 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 }
4561
4562 @Override
4563 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4564 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004565
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004566 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4568 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4569 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004570 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004571 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004572 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004573 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004574 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4575 + "is inactive, ignoring unregister.");
4576 // If the subscription is no longer active, just return, since the callback will already
4577 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
4581 }
4582
joonhunshin2c3e4232021-11-28 07:32:01 +00004583 @Override
4584 public void registerFeatureProvisioningChangedCallback(int subId,
4585 IFeatureProvisioningCallback callback) {
4586 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4587 mApp, subId, "registerFeatureProvisioningChangedCallback");
4588
4589 final long identity = Binder.clearCallingIdentity();
4590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4591 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4592 }
4593
4594 ImsProvisioningController.getInstance()
4595 .addFeatureProvisioningChangedCallback(subId, callback);
4596
4597 Binder.restoreCallingIdentity(identity);
4598 }
4599
4600 @Override
4601 public void unregisterFeatureProvisioningChangedCallback(int subId,
4602 IFeatureProvisioningCallback callback) {
4603 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4604 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4605
4606 final long identity = Binder.clearCallingIdentity();
4607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4608 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4609 }
4610
4611 ImsProvisioningController.getInstance()
4612 .removeFeatureProvisioningChangedCallback(subId, callback);
4613
4614 Binder.restoreCallingIdentity(identity);
4615 }
allenwtsu99c623b2020-01-03 18:24:23 +08004616
4617 private void checkModifyPhoneStatePermission(int subId, String message) {
4618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4619 message);
4620 }
4621
4622 private boolean isImsProvisioningRequired(int subId, int capability,
4623 boolean isMmtelCapability) {
4624 Phone phone = getPhone(subId);
4625 if (phone == null) {
4626 loge("phone instance null for subid " + subId);
4627 return false;
4628 }
4629 if (isMmtelCapability) {
4630 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4631 return false;
4632 }
4633 } else {
4634 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4635 return false;
4636 }
4637 }
4638 return true;
4639 }
4640
4641 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004642 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004643 boolean isProvisioned) {
4644 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4645
4646 final long identity = Binder.clearCallingIdentity();
4647 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004648 ImsProvisioningController.getInstance()
4649 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4650 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
allenwtsu99c623b2020-01-03 18:24:23 +08004654 }
4655
4656
4657 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004658 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4659 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4660 mApp, subId, "getRcsProvisioningStatusForCapability");
4661
allenwtsu99c623b2020-01-03 18:24:23 +08004662 final long identity = Binder.clearCallingIdentity();
4663 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004664 return ImsProvisioningController.getInstance()
4665 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
4669 }
4670
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004671 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004672 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4673 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004674 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004675
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676 final long identity = Binder.clearCallingIdentity();
4677 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004678 ImsProvisioningController.getInstance()
4679 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
4685 @Override
4686 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004687 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4688 mApp, subId, "getProvisioningStatusForCapability");
4689
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 final long identity = Binder.clearCallingIdentity();
4691 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004692 return ImsProvisioningController.getInstance()
4693 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004694
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
4700 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004701 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4702 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4703 mApp, subId, "isProvisioningRequiredForCapability");
4704
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 return ImsProvisioningController.getInstance()
4708 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4709 } finally {
4710 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004712 }
4713
4714 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004715 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4716 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4717 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718
joonhunshin2c3e4232021-11-28 07:32:01 +00004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 return ImsProvisioningController.getInstance()
4722 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4723 } finally {
4724 Binder.restoreCallingIdentity(identity);
4725 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 }
4727
4728 private static String getMmTelProvisioningKey(int subId, int tech) {
4729 // resulting key is provision_ims_mmtel_{subId}_{tech}
4730 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4731 }
4732
4733 /**
4734 * Query CarrierConfig to see if the specified capability requires provisioning for the
4735 * carrier associated with the subscription id.
4736 */
4737 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4738 int capability) {
4739 CarrierConfigManager configManager = new CarrierConfigManager(context);
4740 PersistableBundle c = configManager.getConfigForSubId(subId);
4741 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004742 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004743 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4744 false);
4745 boolean requireVoiceVtProvisioning = c.getBoolean(
4746 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4747
4748 // First check to make sure that the capability requires provisioning.
4749 switch (capability) {
4750 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4751 // intentional fallthrough
4752 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4753 if (requireVoiceVtProvisioning) {
4754 // Voice and Video requires provisioning
4755 return true;
4756 }
4757 break;
4758 }
4759 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4760 if (requireUtProvisioning) {
4761 // UT requires provisioning
4762 return true;
4763 }
4764 break;
4765 }
4766 }
4767 return false;
4768 }
4769
allenwtsu99c623b2020-01-03 18:24:23 +08004770 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4771 int capability) {
4772 CarrierConfigManager configManager = new CarrierConfigManager(context);
4773 PersistableBundle c = configManager.getConfigForSubId(subId);
4774
4775 boolean requireRcsProvisioning = c.getBoolean(
4776 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4777
4778 // First check to make sure that the capability requires provisioning.
4779 switch (capability) {
4780 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4781 // intentional fallthrough
4782 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4783 if (requireRcsProvisioning) {
4784 // OPTION or PRESENCE requires provisioning
4785 return true;
4786 }
4787 break;
4788 }
4789 }
4790 return false;
4791 }
4792
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004793 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004794 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004795 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4796 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4797 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004798 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4799 mApp, subId, "getImsProvisioningInt");
4800
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 int slotId = getSlotIndex(subId);
4805 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4806 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4807 + subId + "' for key:" + key);
4808 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4809 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004810
4811 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4812 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4813 return retVal;
4814 }
4815
calvinpanb5a34062021-02-08 19:59:36 +08004816 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004817 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004818 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4819 + subId + "' for key:" + key);
4820 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
4824 }
4825
4826 @Override
4827 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004828 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4829 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4830 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004831 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4832 mApp, subId, "getImsProvisioningString");
4833
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004834 final long identity = Binder.clearCallingIdentity();
4835 try {
4836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004837 int slotId = getSlotIndex(subId);
4838 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4839 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4840 + subId + "' for key:" + key);
4841 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4842 }
calvinpanb5a34062021-02-08 19:59:36 +08004843 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004844 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004845 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4846 + subId + "' for key:" + key);
4847 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
4851 }
4852
4853 @Override
4854 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4856 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4857 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4859 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004860
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004864 int slotId = getSlotIndex(subId);
4865 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4866 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4867 + subId + "' for key:" + key);
4868 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4869 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004870
4871 int retVal = ImsProvisioningController.getInstance()
4872 .setProvisioningValue(subId, key, value);
4873 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4874 return retVal;
4875 }
4876
calvinpanb5a34062021-02-08 19:59:36 +08004877 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4878 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004880 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
4887 @Override
4888 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4890 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4891 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4893 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 int slotId = getSlotIndex(subId);
4898 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4899 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4900 + subId + "' for key:" + key);
4901 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4902 }
calvinpanb5a34062021-02-08 19:59:36 +08004903 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4904 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004906 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
4911 }
4912
Brad Ebinger919631e2021-06-02 17:46:35 -07004913 /**
4914 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4915 * for the given slot ID or no ImsResolver instance has been created.
4916 * @param slotId The slot ID that the IMS service is created for.
4917 * @throws ImsException If there is no ImsService configured for this slot.
4918 */
4919 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4920 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4921 ImsFeature.FEATURE_MMTEL)) {
4922 throw new ImsException("This subscription does not support MMTEL over IMS",
4923 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4924 }
4925 }
4926
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004927 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004928 int slotId = SubscriptionManager.getSlotIndex(subId);
4929 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004930 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4931 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004932 }
4933 return slotId;
4934 }
4935
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004936 private int getSlotIndex(int subId) {
4937 int slotId = SubscriptionManager.getSlotIndex(subId);
4938 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4939 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4940 }
4941 return slotId;
4942 }
4943
Wink Saville36469e72014-06-11 15:17:00 -07004944 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004945 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004946 */
4947 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004948 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4949 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004950 try {
4951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4952 } catch (SecurityException se) {
4953 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4954 throw new SecurityException("Package " + callingPackage + " does not belong to "
4955 + Binder.getCallingUid());
4956 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004957 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004958 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004959 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004960 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004961 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004962 mApp, subId, callingPackage, callingFeatureId,
4963 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004964 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4965 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
4968 try {
4969 final Phone phone = getPhone(subId);
4970 if (phone != null) {
4971 return phone.getServiceState().getDataNetworkType();
4972 } else {
4973 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4974 }
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004978 }
4979
4980 /**
4981 * Returns the data network type
4982 */
4983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004984 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004985 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4986 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004987 }
4988
4989 /**
4990 * Returns the data network type for a subId
4991 */
4992 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004993 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4994 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004995 String functionName = "getDataNetworkTypeForSubscriber";
4996 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4997 mApp, functionName)) {
4998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4999 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5000 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5001 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005002 }
5003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 final long identity = Binder.clearCallingIdentity();
5005 try {
5006 final Phone phone = getPhone(subId);
5007 if (phone != null) {
5008 return phone.getServiceState().getDataNetworkType();
5009 } else {
5010 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5011 }
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005015 }
5016
5017 /**
Wink Saville36469e72014-06-11 15:17:00 -07005018 * Returns the Voice network type for a subId
5019 */
5020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005021 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5022 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005023 String functionName = "getVoiceNetworkTypeForSubscriber";
5024 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5025 mApp, functionName)) {
5026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5027 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5028 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5029 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005030 }
5031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 final long identity = Binder.clearCallingIdentity();
5033 try {
5034 final Phone phone = getPhone(subId);
5035 if (phone != null) {
5036 return phone.getServiceState().getVoiceNetworkType();
5037 } else {
5038 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5039 }
5040 } finally {
5041 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005042 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005043 }
5044
5045 /**
5046 * @return true if a ICC card is present
5047 */
5048 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005049 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005050 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5051 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005052 }
5053
5054 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005055 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005056 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005057 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005058 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 final Phone phone = PhoneFactory.getPhone(slotIndex);
5062 if (phone != null) {
5063 return phone.getIccCard().hasIccCard();
5064 } else {
5065 return false;
5066 }
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005070 }
5071
5072 /**
5073 * Return if the current radio is LTE on CDMA. This
5074 * is a tri-state return value as for a period of time
5075 * the mode may be unknown.
5076 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005077 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005078 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005079 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005080 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005082 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5083 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5084 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005085 }
5086
Sanket Padawe356d7632015-06-22 14:03:32 -07005087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005088 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5089 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005090 try {
5091 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5092 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005093 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5094 }
5095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 final Phone phone = getPhone(subId);
5099 if (phone == null) {
5100 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5101 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005102 return TelephonyProperties.lte_on_cdma_device()
5103 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 }
5105 } finally {
5106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005107 }
Wink Saville36469e72014-06-11 15:17:00 -07005108 }
5109
Wink Saville36469e72014-06-11 15:17:00 -07005110 /**
5111 * {@hide}
5112 * Returns Default subId, 0 in the case of single standby.
5113 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005114 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005115 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005116 }
5117
Shishir Agrawala9f32182016-04-12 12:00:16 -07005118 private int getSlotForDefaultSubscription() {
5119 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5120 }
5121
Wink Savilleb564aae2014-10-23 10:18:09 -07005122 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005123 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005124 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005125
Pengquan Menge92a50d2018-09-21 15:54:48 -07005126 private boolean isActiveSubscription(int subId) {
5127 return mSubscriptionController.isActiveSubId(subId);
5128 }
5129
Ihab Awadf2177b72013-11-25 13:33:23 -08005130 /**
5131 * @see android.telephony.TelephonyManager.WifiCallingChoices
5132 */
5133 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005136 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5138 getWhenToMakeWifiCallsDefaultPreference());
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005142 }
5143
5144 /**
5145 * @see android.telephony.TelephonyManager.WifiCallingChoices
5146 */
5147 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 final long identity = Binder.clearCallingIdentity();
5149 try {
5150 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005151 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005156 }
5157
Sailesh Nepald1e68152013-12-12 19:08:02 -08005158 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005159 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005160 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005161 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005162
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005163 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5164 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5165 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005166 if (phoneId == -1) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005167 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5168 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005169 }
5170 return PhoneFactory.getPhone(phoneId);
5171 }
5172
Shishir Agrawal566b7612013-10-28 14:41:00 -07005173 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005174 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wange162e302021-11-10 20:15:19 -08005175 @NonNull IccLogicalChannelRequest request) {
5176 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5177 /*message=*/ "iccOpenLogicalChannel");
5178
5179 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5180 // Verify that the callingPackage in the request belongs to the calling UID
5181 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5182
5183 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005184 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005185
Rambo Wange162e302021-11-10 20:15:19 -08005186 private Phone getPhoneFromValidIccLogicalChannelRequest(
5187 @NonNull IccLogicalChannelRequest request, String message) {
5188 Phone phone;
5189 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5191 mApp, request.subId, message);
5192 phone = getPhoneFromSubId(request.subId);
5193 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5194 enforceModifyPermission();
5195 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5196 } else {
5197 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005198 }
Rambo Wange162e302021-11-10 20:15:19 -08005199 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005200 }
5201
5202 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wange162e302021-11-10 20:15:19 -08005203 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 final long identity = Binder.clearCallingIdentity();
5205 try {
Rambo Wange162e302021-11-10 20:15:19 -08005206 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005208 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5209 .getContext().getPackageManager());
Rambo Wange162e302021-11-10 20:15:19 -08005210 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5211 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 loge("The calling package is not allowed to access ISD-R.");
5213 throw new SecurityException(
5214 "The calling package is not allowed to access ISD-R.");
5215 }
Derek Tan740e1672017-06-27 14:56:27 -07005216 }
Derek Tan740e1672017-06-27 14:56:27 -07005217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wange162e302021-11-10 20:15:19 -08005219 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5220 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 return response;
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005225 }
5226
5227 @Override
Rambo Wange162e302021-11-10 20:15:19 -08005228 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5229 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5230 /*message=*/"iccCloseLogicalChannel");
5231
5232 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5233
5234 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005235 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005236
Rambo Wange162e302021-11-10 20:15:19 -08005237 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5238 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
Rambo Wange162e302021-11-10 20:15:19 -08005241 if (request.channel < 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 return false;
5243 }
Rambo Wange162e302021-11-10 20:15:19 -08005244 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005245 null /* workSource */);
Rambo Wange162e302021-11-10 20:15:19 -08005246 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 return success;
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005250 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005251 }
5252
5253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005254 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005255 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5257 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005258 if (DBG) {
5259 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5260 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5261 + p3 + " data=" + data);
5262 }
5263 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5264 command, p1, p2, p3, data);
5265 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005266
Jordan Liu4c733742019-02-28 12:03:40 -08005267 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005268 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5269 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005270 enforceModifyPermission();
5271 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005272 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5273 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5274 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005275 }
5276 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005277 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5278 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005279 }
5280
5281 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5282 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005285 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 return "";
5287 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005290 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5291 null /* workSource */);
5292 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 // Append the returned status code to the end of the response payload.
5295 String s = Integer.toHexString(
5296 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5297 if (response.payload != null) {
5298 s = IccUtils.bytesToHexString(response.payload) + s;
5299 }
5300 return s;
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005303 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304 }
Jake Hambye994d462014-02-03 13:10:13 -08005305
Evan Charltonc66da362014-05-16 14:06:40 -07005306 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005307 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5308 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005312 if (DBG) {
5313 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5314 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5315 }
5316 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5317 cla, command, p1, p2, p3, data);
5318 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005319
Jordan Liu4c733742019-02-28 12:03:40 -08005320 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005321 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5322 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005323 enforceModifyPermission();
5324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5325 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005326 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5327 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5328 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005329 }
5330
5331 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005332 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5333 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005334 }
5335
5336 // open APDU basic channel assuming the caller has sufficient permissions
5337 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5338 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5342 && TextUtils.equals(ISDR_AID, data)) {
5343 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005344 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5345 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 if (bestComponent == null
5347 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5348 loge("The calling package is not allowed to select ISD-R.");
5349 throw new SecurityException(
5350 "The calling package is not allowed to select ISD-R.");
5351 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005352 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005355 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5356 null /* workSource */);
5357 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 // Append the returned status code to the end of the response payload.
5360 String s = Integer.toHexString(
5361 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5362 if (response.payload != null) {
5363 s = IccUtils.bytesToHexString(response.payload) + s;
5364 }
5365 return s;
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005368 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005369 }
5370
5371 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005372 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005373 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5375 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 final long identity = Binder.clearCallingIdentity();
5378 try {
5379 if (DBG) {
5380 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5381 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5382 }
5383
5384 IccIoResult response =
5385 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5386 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5387 subId);
5388
5389 if (DBG) {
5390 log("Exchange SIM_IO [R]" + response);
5391 }
5392
5393 byte[] result = null;
5394 int length = 2;
5395 if (response.payload != null) {
5396 length = 2 + response.payload.length;
5397 result = new byte[length];
5398 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5399 } else {
5400 result = new byte[length];
5401 }
5402
5403 result[length - 1] = (byte) response.sw2;
5404 result[length - 2] = (byte) response.sw1;
5405 return result;
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005408 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005409 }
5410
Nathan Haroldb3014052017-01-25 15:57:32 -08005411 /**
5412 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5413 * on a particular subscription
5414 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005415 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5416 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005418 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005419 return null;
5420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 if (appType != TelephonyManager.APPTYPE_USIM
5425 && appType != TelephonyManager.APPTYPE_SIM) {
5426 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5427 return null;
5428 }
5429 Object response = sendRequest(
5430 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5431 if (response instanceof String[]) {
5432 return (String[]) response;
5433 }
yincheng zhao2737e882019-09-06 17:06:54 -07005434 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005436 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005439 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005440 }
5441
yincheng zhao2737e882019-09-06 17:06:54 -07005442 /**
5443 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5444 * subscription.
5445 *
5446 * @param subId the id of the subscription.
5447 * @param appType the uicc app type, must be USIM or SIM.
5448 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5449 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005450 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005451 * @return number of fplmns that is successfully written to the SIM.
5452 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005453 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5454 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5456 mApp, subId, "setForbiddenPlmns");
5457
yincheng zhao2737e882019-09-06 17:06:54 -07005458 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5459 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5460 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5461 }
5462 if (fplmns == null) {
5463 throw new IllegalArgumentException("Fplmn List provided is null");
5464 }
5465 for (String fplmn : fplmns) {
5466 if (!CellIdentity.isValidPlmn(fplmn)) {
5467 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5468 }
5469 }
5470 final long identity = Binder.clearCallingIdentity();
5471 try {
5472 Object response = sendRequest(
5473 CMD_SET_FORBIDDEN_PLMNS,
5474 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5475 subId);
5476 return (int) response;
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
5480 }
5481
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005482 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005483 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5485 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5490 if (response.payload == null) {
5491 return "";
5492 }
Evan Charltonc66da362014-05-16 14:06:40 -07005493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 // Append the returned status code to the end of the response payload.
5495 String s = Integer.toHexString(
5496 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5497 s = IccUtils.bytesToHexString(response.payload) + s;
5498 return s;
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
Evan Charltonc66da362014-05-16 14:06:40 -07005502 }
5503
Jake Hambye994d462014-02-03 13:10:13 -08005504 /**
5505 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5506 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5507 *
5508 * @param itemID the ID of the item to read
5509 * @return the NV item as a String, or null on error.
5510 */
5511 @Override
5512 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5515 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005520 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5522 return value;
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Jake Hambye994d462014-02-03 13:10:13 -08005526 }
5527
5528 /**
5529 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5530 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5531 *
5532 * @param itemID the ID of the item to read
5533 * @param itemValue the value to write, as a String
5534 * @return true on success; false on any failure
5535 */
5536 @Override
5537 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005538 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5540 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541
5542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5545 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005546 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5548 return success;
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
Jake Hambye994d462014-02-03 13:10:13 -08005552 }
5553
5554 /**
5555 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5556 * Used for device configuration by some CDMA operators.
5557 *
5558 * @param preferredRoamingList byte array containing the new PRL
5559 * @return true on success; false on any failure
5560 */
5561 @Override
5562 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5569 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5570 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5571 return success;
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
Jake Hambye994d462014-02-03 13:10:13 -08005575 }
5576
5577 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005578 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005579 * Used for device configuration by some CDMA operators.
5580 *
chen xu6dac5ab2018-10-26 17:39:23 -07005581 * @param slotIndex - device slot.
5582 *
Jake Hambye994d462014-02-03 13:10:13 -08005583 * @return true on success; false on any failure
5584 */
5585 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005586 public boolean resetModemConfig(int slotIndex) {
5587 Phone phone = PhoneFactory.getPhone(slotIndex);
5588 if (phone != null) {
5589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5590 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591
chen xu6dac5ab2018-10-26 17:39:23 -07005592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5595 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5596 return success;
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 }
chen xu6dac5ab2018-10-26 17:39:23 -07005601 return false;
5602 }
5603
5604 /**
5605 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5606 *
5607 * @param slotIndex - device slot.
5608 *
5609 * @return true on success; false on any failure
5610 */
5611 @Override
5612 public boolean rebootModem(int slotIndex) {
5613 Phone phone = PhoneFactory.getPhone(slotIndex);
5614 if (phone != null) {
5615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5616 mApp, phone.getSubId(), "rebootModem");
5617
5618 final long identity = Binder.clearCallingIdentity();
5619 try {
5620 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5621 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5622 return success;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
5626 }
5627 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005628 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005629
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005630 public String[] getPcscfAddress(String apnType, String callingPackage,
5631 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005632 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5634 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005635 return new String[0];
5636 }
5637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 final long identity = Binder.clearCallingIdentity();
5639 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005640 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Wink Saville36469e72014-06-11 15:17:00 -07005644 }
5645
Brad Ebinger51f743a2017-01-23 13:50:20 -08005646 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005647 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5648 * {@link #disableIms(int)}.
5649 * @param slotIndex device slot.
5650 */
5651 public void resetIms(int slotIndex) {
5652 enforceModifyPermission();
5653
5654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 if (mImsResolver == null) {
5657 // may happen if the does not support IMS.
5658 return;
5659 }
5660 mImsResolver.disableIms(slotIndex);
5661 mImsResolver.enableIms(slotIndex);
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
5665 }
5666
5667 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005668 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5669 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005670 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005671 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005672 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005676 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005677 // may happen if the device does not support IMS.
5678 return;
5679 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005680 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005684 }
5685
5686 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005687 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5688 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005689 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005690 public void disableIms(int slotId) {
5691 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005695 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005696 // may happen if the device does not support IMS.
5697 return;
5698 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005699 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005703 }
5704
5705 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005706 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5707 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005708 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005709 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005710 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005715 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005716 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5717 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005718 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005719 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 } finally {
5721 Binder.restoreCallingIdentity(identity);
5722 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005723 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005724 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005725 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5726 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005727 @Override
5728 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005729 enforceModifyPermission();
5730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005734 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
5738 }
5739
5740 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005741 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005742 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005743 */
5744 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005749 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005750 // may happen if the device does not support IMS.
5751 return null;
5752 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005753 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005757 }
5758
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005759 /**
5760 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005761 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005762 */
5763 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005769 // may happen if the device does not support IMS.
5770 return null;
5771 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005772 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005776 }
5777
Brad Ebinger884c07b2018-02-15 16:17:40 -08005778 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005779 * Sets the ImsService Package Name that Telephony will bind to.
5780 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 * @param slotIndex the slot ID that the ImsService should bind for.
5782 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005783 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005784 * @param featureTypes An integer array of feature types associated with a packageName.
5785 * @param packageName The name of the package that the current configuration will be replaced
5786 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005787 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005788 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5790 int[] featureTypes, String packageName) {
5791 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5794 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005795 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 final long identity = Binder.clearCallingIdentity();
5798 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005799 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005800 // may happen if the device does not support IMS.
5801 return false;
5802 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005803 Map<Integer, String> featureConfig = new HashMap<>();
5804 for (int featureType : featureTypes) {
5805 featureConfig.put(featureType, packageName);
5806 }
5807 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5808 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005812 }
5813
5814 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005815 * Clears any carrier ImsService overrides for the slot index specified that were previously
5816 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5817 *
5818 * This should only be used for testing.
5819 *
5820 * @param slotIndex the slot ID that the ImsService should bind for.
5821 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5822 */
5823 @Override
5824 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5825 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5827 "clearCarrierImsServiceOverride");
5828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5829 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5830 "clearCarrierImsServiceOverride");
5831
5832 final long identity = Binder.clearCallingIdentity();
5833 try {
5834 if (mImsResolver == null) {
5835 // may happen if the device does not support IMS.
5836 return false;
5837 }
5838 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
5842 }
5843
5844 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005846 *
5847 * @param slotId The slot that the ImsService is associated with.
5848 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5849 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005850 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005851 * @return the package name of the ImsService configuration.
5852 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005853 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5854 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005855 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005857 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5859 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 final long identity = Binder.clearCallingIdentity();
5862 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005864 // may happen if the device does not support IMS.
5865 return "";
5866 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005867 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005868 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5869 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 }
5874
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005875 /**
5876 * Get the MmTelFeature state associated with the requested subscription id.
5877 * @param subId The subscription that the MmTelFeature is associated with.
5878 * @param callback A callback with an integer containing the
5879 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5880 */
5881 @Override
5882 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5883 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5884 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5886 "IMS not available on device.");
5887 }
5888 final long token = Binder.clearCallingIdentity();
5889 try {
5890 int slotId = getSlotIndex(subId);
5891 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5892 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5893 + subId + "'");
5894 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5895 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005896 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005897 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5898 try {
5899 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5900 } catch (RemoteException e) {
5901 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5902 + "Ignore");
5903 }
5904 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005905 } catch (ImsException e) {
5906 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005907 } finally {
5908 Binder.restoreCallingIdentity(token);
5909 }
5910 }
5911
Daniel Brightbb5840b2021-01-12 15:48:18 -08005912 /**
5913 * Sets the ims registration state on all valid {@link Phone}s.
5914 */
5915 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005920 // NOTE: Before S, this method only set the default phone.
5921 for (final Phone phone : PhoneFactory.getPhones()) {
5922 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5923 phone.setImsRegistrationState(registered);
5924 }
5925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 } finally {
5927 Binder.restoreCallingIdentity(identity);
5928 }
Wink Saville36469e72014-06-11 15:17:00 -07005929 }
5930
5931 /**
Stuart Scott54788802015-03-30 13:18:01 -07005932 * Set the network selection mode to automatic.
5933 *
5934 */
5935 @Override
5936 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5938 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939
5940 final long identity = Binder.clearCallingIdentity();
5941 try {
shilufc958392020-01-20 11:36:01 -08005942 if (!isActiveSubscription(subId)) {
5943 return;
5944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005946 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5947 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Stuart Scott54788802015-03-30 13:18:01 -07005951 }
5952
Jack Yud10cdd42020-09-28 20:28:01 -07005953 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005954 * Ask the radio to connect to the input network and change selection mode to manual.
5955 *
5956 * @param subId the id of the subscription.
5957 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5958 * the operator to attach to.
5959 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5960 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5961 * normal network selection next time.
5962 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005963 */
5964 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005965 public boolean setNetworkSelectionModeManual(
5966 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5968 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005969
5970 if (!isActiveSubscription(subId)) {
5971 return false;
5972 }
5973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 final long identity = Binder.clearCallingIdentity();
5975 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005976 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005978 if (DBG) {
5979 log("setNetworkSelectionModeManual: subId: " + subId
5980 + " operator: " + operatorInfo);
5981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005986 }
shilu84f6e8b2019-12-19 13:58:01 -08005987 /**
5988 * Get the manual network selection
5989 *
5990 * @param subId the id of the subscription.
5991 *
5992 * @return the previously saved user selected PLMN
5993 */
5994 @Override
5995 public String getManualNetworkSelectionPlmn(int subId) {
5996 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005997 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005998 mApp, subId, "getManualNetworkSelectionPlmn");
5999
6000 final long identity = Binder.clearCallingIdentity();
6001 try {
6002 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006003 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006004 }
6005
6006 final Phone phone = getPhone(subId);
6007 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006008 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006009 }
6010 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6011 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6012 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
6016 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006017
6018 /**
6019 * Scans for available networks.
6020 */
6021 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006022 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6023 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6025 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006026 LocationAccessPolicy.LocationPermissionResult locationResult =
6027 LocationAccessPolicy.checkLocationPermission(mApp,
6028 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6029 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006030 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006031 .setCallingPid(Binder.getCallingPid())
6032 .setCallingUid(Binder.getCallingUid())
6033 .setMethod("getCellNetworkScanResults")
6034 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006035 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6036 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006037 .build());
6038 switch (locationResult) {
6039 case DENIED_HARD:
6040 throw new SecurityException("Not allowed to access scan results -- location");
6041 case DENIED_SOFT:
6042 return null;
6043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
Pengquan Menga1bb6272018-09-06 09:59:22 -07006045 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 try {
6047 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006048 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006053 }
6054
6055 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006056 * Get the call forwarding info, given the call forwarding reason.
6057 */
6058 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006059 public void getCallForwarding(int subId, int callForwardingReason,
6060 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006061 enforceReadPrivilegedPermission("getCallForwarding");
6062 long identity = Binder.clearCallingIdentity();
6063 try {
6064 if (DBG) {
6065 log("getCallForwarding: subId " + subId
6066 + " callForwardingReason" + callForwardingReason);
6067 }
Hall Liu27d24262020-09-18 19:04:59 -07006068
6069 Phone phone = getPhone(subId);
6070 if (phone == null) {
6071 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006072 callback.onError(
6073 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006074 } catch (RemoteException e) {
6075 // ignore
6076 }
6077 return;
6078 }
6079
6080 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6081 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6082 @Override
6083 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6084 try {
6085 callback.onCallForwardingInfoAvailable(info);
6086 } catch (RemoteException e) {
6087 // ignore
6088 }
6089 }
6090
6091 @Override
6092 public void onError(int error) {
6093 try {
6094 callback.onError(error);
6095 } catch (RemoteException e) {
6096 // ignore
6097 }
6098 }
6099 });
6100 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
6105
6106 /**
6107 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6108 * reason, the number to forward, and the timeout before the forwarding is attempted.
6109 */
6110 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006111 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6112 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006113 enforceModifyPermission();
6114 long identity = Binder.clearCallingIdentity();
6115 try {
6116 if (DBG) {
6117 log("setCallForwarding: subId " + subId
6118 + " callForwardingInfo" + callForwardingInfo);
6119 }
Hall Liu27d24262020-09-18 19:04:59 -07006120
6121 Phone phone = getPhone(subId);
6122 if (phone == null) {
6123 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006124 callback.accept(
6125 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006126 } catch (RemoteException e) {
6127 // ignore
6128 }
6129 return;
6130 }
6131
6132 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6133 FunctionalUtils.ignoreRemoteException(callback::accept));
6134
6135 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
6139 }
6140
6141 /**
Hall Liu27d24262020-09-18 19:04:59 -07006142 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006143 */
6144 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006145 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006146 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006147 long identity = Binder.clearCallingIdentity();
6148 try {
Hall Liu27d24262020-09-18 19:04:59 -07006149 Phone phone = getPhone(subId);
6150 if (phone == null) {
6151 try {
6152 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6153 } catch (RemoteException e) {
6154 // ignore
6155 }
6156 return;
6157 }
SongFerngWang0e767992021-03-31 22:08:45 +08006158 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6159 PersistableBundle c = configManager.getConfigForSubId(subId);
6160 boolean requireUssd = c.getBoolean(
6161 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006162
Shuo Qian4a594052020-01-23 11:59:30 -08006163 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006164 if (requireUssd) {
6165 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6166 getSubscriptionCarrierId(subId));
6167 String newUssdCommand = "";
6168 try {
6169 newUssdCommand = carrierXmlParser.getFeature(
6170 CarrierXmlParser.FEATURE_CALL_WAITING)
6171 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6172 } catch (NullPointerException e) {
6173 loge("Failed to generate USSD number" + e);
6174 }
6175 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6176 mMainThreadHandler, callback, carrierXmlParser,
6177 CarrierXmlParser.SsEntry.SSAction.QUERY);
6178 final String ussdCommand = newUssdCommand;
6179 Executors.newSingleThreadExecutor().execute(() -> {
6180 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6181 });
6182 } else {
6183 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6184 callback::accept);
6185 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6186 }
Shuo Qian4a594052020-01-23 11:59:30 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
Hall Liu27d24262020-09-18 19:04:59 -07006193 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006194 */
6195 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006196 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006197 enforceModifyPermission();
6198 long identity = Binder.clearCallingIdentity();
6199 try {
Hall Liu27d24262020-09-18 19:04:59 -07006200 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6201
6202 Phone phone = getPhone(subId);
6203 if (phone == null) {
6204 try {
6205 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6206 } catch (RemoteException e) {
6207 // ignore
6208 }
6209 return;
6210 }
6211
SongFerngWang0e767992021-03-31 22:08:45 +08006212 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6213 PersistableBundle c = configManager.getConfigForSubId(subId);
6214 boolean requireUssd = c.getBoolean(
6215 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006216
SongFerngWang0e767992021-03-31 22:08:45 +08006217 if (DBG) log("getCallWaitingStatus: subId " + subId);
6218 if (requireUssd) {
6219 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6220 getSubscriptionCarrierId(subId));
6221 CarrierXmlParser.SsEntry.SSAction ssAction =
6222 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6223 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6224 String newUssdCommand = "";
6225 try {
6226 newUssdCommand = carrierXmlParser.getFeature(
6227 CarrierXmlParser.FEATURE_CALL_WAITING)
6228 .makeCommand(ssAction, null);
6229 } catch (NullPointerException e) {
6230 loge("Failed to generate USSD number" + e);
6231 }
6232 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6233 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6234 final String ussdCommand = newUssdCommand;
6235 Executors.newSingleThreadExecutor().execute(() -> {
6236 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6237 });
6238 } else {
6239 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6240 FunctionalUtils.ignoreRemoteException(callback::accept));
6241
6242 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6243 }
Shuo Qian4a594052020-01-23 11:59:30 -08006244 } finally {
6245 Binder.restoreCallingIdentity(identity);
6246 }
6247 }
6248
6249 /**
yinxub1bed742017-04-17 11:45:04 -07006250 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006251 *
yinxub1bed742017-04-17 11:45:04 -07006252 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006253 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6254 * location related information which will be sent if the caller already possess
6255 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006256 * @param request contains the radio access networks with bands/channels to scan
6257 * @param messenger callback messenger for scan results or errors
6258 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006259 * @return the id of the requested scan which can be used to stop the scan.
6260 */
6261 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006262 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6263 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006264 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6266 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006267 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006268 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6269 if (!renounceFineLocationAccess) {
6270 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6271 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6272 .setCallingPackage(callingPackage)
6273 .setCallingFeatureId(callingFeatureId)
6274 .setCallingPid(Binder.getCallingPid())
6275 .setCallingUid(Binder.getCallingUid())
6276 .setMethod("requestNetworkScan")
6277 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6278 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6279 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6280 .build());
6281 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006282 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006283 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6284 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006285 if (e != null) {
6286 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6287 throw e;
6288 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006289 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006290 return TelephonyScanManager.INVALID_SCAN_ID;
6291 }
6292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 }
Hall Liu912dfd32019-04-25 14:02:26 -07006294 int callingUid = Binder.getCallingUid();
6295 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006296 final long identity = Binder.clearCallingIdentity();
6297 try {
6298 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006299 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006300 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006301 } finally {
6302 Binder.restoreCallingIdentity(identity);
6303 }
yinxu504e1392017-04-12 16:03:22 -07006304 }
6305
Hall Liub2ac8ef2019-02-28 15:56:23 -08006306 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006307 NetworkScanRequest request, int subId, String callingPackage) {
6308 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006309 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6310 boolean hasNetworkScanPermission =
6311 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6312 == PERMISSION_GRANTED;
6313
6314 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6315 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6316 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006317 }
6318
6319 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6320 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006321 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6322 return new SecurityException("Specific channels must not be"
6323 + " scanned without location access.");
6324 }
6325 }
6326 }
6327
Hall Liub2ac8ef2019-02-28 15:56:23 -08006328 return null;
6329 }
6330
yinxu504e1392017-04-12 16:03:22 -07006331 /**
6332 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006333 *
6334 * @param subId id of the subscription
6335 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006336 */
6337 @Override
6338 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6340 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341
Hall Liu912dfd32019-04-25 14:02:26 -07006342 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 final long identity = Binder.clearCallingIdentity();
6344 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006345 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
yinxu504e1392017-04-12 16:03:22 -07006349 }
6350
6351 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006352 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006353 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006354 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006355 */
6356 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006357 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006358 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006359 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006360 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361
6362 final long identity = Binder.clearCallingIdentity();
6363 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006364 if (DBG) log("getAllowedNetworkTypesBitmask");
6365 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6366 int networkTypesBitmask = (result != null ? result[0] : -1);
6367 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6368 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006372 }
6373
6374 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006375 * Get the allowed network types for certain reason.
6376 *
6377 * @param subId the id of the subscription.
6378 * @param reason the reason the allowed network type change is taking place
6379 * @return the allowed network types.
6380 */
6381 @Override
6382 public long getAllowedNetworkTypesForReason(int subId,
6383 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006384 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006385 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006386 final long identity = Binder.clearCallingIdentity();
6387 try {
6388 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
6392 }
6393
6394 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006395 * Enable/Disable E-UTRA-NR Dual Connectivity
6396 * @param subId subscription id of the sim card
6397 * @param nrDualConnectivityState expected NR dual connectivity state
6398 * This can be passed following states
6399 * <ol>
6400 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6401 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6402 * <li>Disable NR dual connectivity and force secondary cell to be released
6403 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6404 * </ol>
6405 * @return operation result.
6406 */
6407 @Override
6408 public int setNrDualConnectivityState(int subId,
6409 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006412 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006413 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6414 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6415 }
6416
Sooraj Sasindran37444802020-08-11 10:40:43 -07006417 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6418 final long identity = Binder.clearCallingIdentity();
6419 try {
6420 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6421 nrDualConnectivityState, subId,
6422 workSource);
6423 if (DBG) log("enableNRDualConnectivity result: " + result);
6424 return result;
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
6428 }
6429
6430 /**
6431 * Is E-UTRA-NR Dual Connectivity enabled
6432 * @return true if dual connectivity is enabled else false
6433 */
6434 @Override
6435 public boolean isNrDualConnectivityEnabled(int subId) {
6436 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006437 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006438 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006439 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006440 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6441 return false;
6442 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6444 final long identity = Binder.clearCallingIdentity();
6445 try {
6446 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6447 null, subId, workSource);
6448 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6449 return isEnabled;
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 }
6454
6455 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006456 * Set the allowed network types of the device and
6457 * provide the reason triggering the allowed network change.
6458 *
6459 * @param subId the id of the subscription.
6460 * @param reason the reason the allowed network type change is taking place
6461 * @param allowedNetworkTypes the allowed network types.
6462 * @return true on success; false on any failure.
6463 */
6464 @Override
6465 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006466 @TelephonyManager.AllowedNetworkTypesReason int reason,
6467 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6469 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006470 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006471 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6472 return false;
6473 }
6474 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6475 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006476 return false;
6477 }
6478
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006479 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6480 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6481
6482
6483 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6484 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6485 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006486 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006487
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006488 final long identity = Binder.clearCallingIdentity();
6489 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006490 Boolean success = (Boolean) sendRequest(
6491 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6492 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6493
6494 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6495 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500
6501 /**
Miaoa84611c2019-03-15 09:21:10 +08006502 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006503 *
Miaoa84611c2019-03-15 09:21:10 +08006504 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006505 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006506 * @hide
6507 */
6508 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006509 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006512 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 try {
Miaoa84611c2019-03-15 09:21:10 +08006514 if (phone != null) {
6515 return phone.hasMatchedTetherApnSetting();
6516 } else {
6517 return false;
6518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519 } finally {
6520 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006521 }
Junda Liu475951f2014-11-07 16:45:03 -08006522 }
6523
6524 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006525 * Get the user enabled state of Mobile Data.
6526 *
6527 * TODO: remove and use isUserDataEnabled.
6528 * This can't be removed now because some vendor codes
6529 * calls through ITelephony directly while they should
6530 * use TelephonyManager.
6531 *
6532 * @return true on enabled
6533 */
6534 @Override
6535 public boolean getDataEnabled(int subId) {
6536 return isUserDataEnabled(subId);
6537 }
6538
6539 /**
6540 * Get whether mobile data is enabled per user setting.
6541 *
6542 * There are other factors deciding whether mobile data is actually enabled, but they are
6543 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006544 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006545 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6546 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006547 *
6548 * @return {@code true} if data is enabled else {@code false}
6549 */
6550 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006551 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006552 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006553 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006554 try {
6555 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6556 functionName);
6557 } catch (Exception e) {
6558 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6559 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006560 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006562 mApp, subId, functionName);
6563
Robert Greenwalt646120a2014-05-23 11:54:03 -07006564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565
6566 final long identity = Binder.clearCallingIdentity();
6567 try {
6568 int phoneId = mSubscriptionController.getPhoneId(subId);
6569 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6570 Phone phone = PhoneFactory.getPhone(phoneId);
6571 if (phone != null) {
6572 boolean retVal = phone.isUserDataEnabled();
6573 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6574 return retVal;
6575 } else {
6576 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6577 return false;
6578 }
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006581 }
6582 }
6583
6584 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006585 * Checks if the device is capable of mobile data by considering whether whether the
6586 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6587 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006588 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006589 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006590 */
6591 @Override
6592 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006593 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006594 try {
6595 try {
6596 mApp.enforceCallingOrSelfPermission(
6597 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006598 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006599 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006600 try {
6601 mApp.enforceCallingOrSelfPermission(
6602 android.Manifest.permission.READ_PHONE_STATE,
6603 functionName);
6604 } catch (Exception e2) {
6605 mApp.enforceCallingOrSelfPermission(
6606 permission.READ_BASIC_PHONE_STATE, functionName);
6607 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006608 }
6609 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006610 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612
6613 final long identity = Binder.clearCallingIdentity();
6614 try {
6615 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 Phone phone = PhoneFactory.getPhone(phoneId);
6617 if (phone != null) {
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006618 boolean retVal;
6619 if (phone.isUsingNewDataStack()) {
Sarah Chin8619e162022-03-09 13:57:52 -08006620 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006621 } else {
6622 retVal = phone.getDataEnabledSettings().isDataEnabled();
6623 }
6624 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 return retVal;
6626 } else {
6627 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6628 return false;
6629 }
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006632 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006633 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006634
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006635 /**
6636 * Check if data is enabled for a specific reason
6637 * @param subId Subscription index
6638 * @param reason the reason the data enable change is taking place
6639 * @return {@code true} if the overall data is enabled; {@code false} if not.
6640 */
6641 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006642 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006643 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006644 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006645 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006646 try {
6647 mApp.enforceCallingOrSelfPermission(
6648 android.Manifest.permission.ACCESS_NETWORK_STATE,
6649 functionName);
6650 } catch (Exception e) {
6651 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6652 functionName);
6653 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006654 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006655 try {
6656 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006657 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006658 } catch (Exception e2) {
6659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006660 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006661 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006662 }
6663
6664
6665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 int phoneId = mSubscriptionController.getPhoneId(subId);
6668 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006669 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006670 + " reason=" + reason);
6671 }
6672 Phone phone = PhoneFactory.getPhone(phoneId);
6673 if (phone != null) {
6674 boolean retVal;
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006675 if (phone.isUsingNewDataStack()) {
6676 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006677 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006678 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6679 retVal = phone.isUserDataEnabled();
6680 } else {
6681 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6682 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006684 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 return retVal;
6686 } else {
6687 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006688 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006689 + subId + " retVal=false");
6690 }
6691 return false;
6692 }
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
6695 }
6696 }
6697
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006698 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006699 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006700 if (uid == Process.PHONE_UID) {
6701 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6702 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006703 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6704 }
6705
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006706 //load access rules from carrier configs, and check those as well: b/139133814
6707 SubscriptionController subController = SubscriptionController.getInstance();
6708 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6709 || subController == null) return privilegeFromSim;
6710
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006711 PackageManager pkgMgr = phone.getContext().getPackageManager();
6712 String[] packages = pkgMgr.getPackagesForUid(uid);
6713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006716 int subId = phone.getSubId();
6717 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6718 // A test override is in place for the privileges for this subId, so don't try to
6719 // read the subscription privileges.
6720 return privilegeFromSim;
6721 }
6722 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006723 SubscriptionManager subManager = (SubscriptionManager)
6724 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6725 for (String pkg : packages) {
6726 if (subManager.canManageSubscription(subInfo, pkg)) {
6727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6728 }
6729 }
6730 return privilegeFromSim;
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
6734 }
6735
6736 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6737 String pkgName) {
6738 //load access rules from carrier configs, and check those as well: b/139133814
6739 SubscriptionController subController = SubscriptionController.getInstance();
6740 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6741 || subController == null) return privilegeFromSim;
6742
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006745 int subId = phone.getSubId();
6746 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6747 // A test override is in place for the privileges for this subId, so don't try to
6748 // read the subscription privileges.
6749 return privilegeFromSim;
6750 }
6751 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006752 SubscriptionManager subManager = (SubscriptionManager)
6753 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6754 return subManager.canManageSubscription(subInfo, pkgName)
6755 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
6759 }
6760
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006761 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006762 public int getCarrierPrivilegeStatus(int subId) {
6763 final Phone phone = getPhone(subId);
6764 if (phone == null) {
6765 loge("getCarrierPrivilegeStatus: Invalid subId");
6766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6767 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006768 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6769 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006770 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6772 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006773
6774 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006775 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006776 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006777 }
Junda Liu29340342014-07-10 15:23:27 -07006778
6779 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006780 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006781 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 final Phone phone = getPhone(subId);
6783 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006784 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006785 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6786 }
6787 UiccProfile profile =
6788 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6789 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006790 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6792 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006793 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006794 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006795 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006796 }
6797
6798 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006799 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006800 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006801 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006803 }
6804
6805 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006806 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6807 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006808 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006809 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6810 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006811 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006812 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006813 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006814 }
6815
6816 @Override
6817 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006818 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006819 if (TextUtils.isEmpty(pkgName))
6820 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006821 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6822 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006823 UiccPort port = UiccController.getInstance().getUiccPort(i);
6824 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006825 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006826 continue;
6827 }
6828
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006829 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006830 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006831 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006832 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6833 break;
6834 }
6835 }
6836
6837 return result;
Junda Liu29340342014-07-10 15:23:27 -07006838 }
Derek Tan89e89d42014-07-08 17:00:10 -07006839
6840 @Override
Junda Liue64de782015-04-16 17:19:16 -07006841 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006842 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006843 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6844 loge("phoneId " + phoneId + " is not valid.");
6845 return null;
6846 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006847 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6848 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006849 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006850 return null ;
6851 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006852 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006853 }
6854
Amith Yamasani6e118872016-02-19 12:53:51 -08006855 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006856 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006857 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006858 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006859 List<String> privilegedPackages = new ArrayList<>();
6860 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006861 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006862 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006863 if (port != null) {
6864 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006865 if (packages == null) {
6866 // Only check packages in user 0 for now
6867 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006868 PackageManager.MATCH_DISABLED_COMPONENTS
6869 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006870 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006871 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006872 }
6873 for (int p = packages.size() - 1; p >= 0; p--) {
6874 PackageInfo pkgInfo = packages.get(p);
6875 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006876 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006877 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006878 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006879 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006880 privilegedPackages.add(pkgInfo.packageName);
6881 }
6882 }
6883 }
6884 }
6885 return privilegedPackages;
6886 }
6887
chen xuf7e9fe82019-05-09 19:31:02 -07006888 @Override
6889 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006890 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6891
6892 final long identity = Binder.clearCallingIdentity();
6893
chen xuf7e9fe82019-05-09 19:31:02 -07006894 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006895 try {
6896 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6897 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6898 }
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006901 }
6902 return privilegedPackages;
6903 }
6904
Wink Savilleb564aae2014-10-23 10:18:09 -07006905 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006906 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006907 UiccPort port = phone == null ? null : phone.getUiccPort();
6908 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006909 return null;
6910 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006911 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006912 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006913 return null;
6914 }
6915 return iccId;
6916 }
6917
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006918 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006919 public void setCallComposerStatus(int subId, int status) {
6920 enforceModifyPermission();
6921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 Phone phone = getPhone(subId);
6925 if (phone != null) {
6926 Phone defaultPhone = phone.getImsPhone();
6927 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6928 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6929 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006930 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6931 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006932 }
6933 }
Shuo Qian284ae752020-12-22 19:10:14 -08006934 } catch (ImsException e) {
6935 throw new ServiceSpecificException(e.getCode());
6936 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006937 Binder.restoreCallingIdentity(identity);
6938 }
6939 }
6940
6941 @Override
6942 public int getCallComposerStatus(int subId) {
6943 enforceReadPrivilegedPermission("getCallComposerStatus");
6944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 Phone phone = getPhone(subId);
6948 if (phone != null) {
6949 Phone defaultPhone = phone.getImsPhone();
6950 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6951 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6952 return imsPhone.getCallComposerStatus();
6953 }
6954 }
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6959 }
6960
6961 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006962 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6963 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006964 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006965 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 final String iccId = getIccId(subId);
6970 final Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 return false;
6973 }
6974 final String subscriberId = phone.getSubscriberId();
6975
6976 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006977 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 + subscriberId + " to " + number);
6979 }
6980
6981 if (TextUtils.isEmpty(iccId)) {
6982 return false;
6983 }
6984
6985 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6986
6987 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6988 if (alphaTag == null) {
6989 editor.remove(alphaTagPrefKey);
6990 } else {
6991 editor.putString(alphaTagPrefKey, alphaTag);
6992 }
6993
6994 // Record both the line number and IMSI for this ICCID, since we need to
6995 // track all merged IMSIs based on line number
6996 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6997 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6998 if (number == null) {
6999 editor.remove(numberPrefKey);
7000 editor.remove(subscriberPrefKey);
7001 } else {
7002 editor.putString(numberPrefKey, number);
7003 editor.putString(subscriberPrefKey, subscriberId);
7004 }
7005
7006 editor.commit();
7007 return true;
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007010 }
Derek Tan7226c842014-07-02 17:42:23 -07007011 }
7012
7013 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007014 public String getLine1NumberForDisplay(int subId, String callingPackage,
7015 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007016 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007018 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007019 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007020 return null;
7021 }
Derek Tan97ebb422014-09-05 16:55:38 -07007022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 String iccId = getIccId(subId);
7026 if (iccId != null) {
7027 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7028 if (DBG_MERGE) {
7029 log("getLine1NumberForDisplay returning "
7030 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7031 }
7032 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7035 return null;
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007038 }
Derek Tan7226c842014-07-02 17:42:23 -07007039 }
7040
7041 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007042 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7043 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007045 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007046 return null;
7047 }
Derek Tan97ebb422014-09-05 16:55:38 -07007048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 final long identity = Binder.clearCallingIdentity();
7050 try {
7051 String iccId = getIccId(subId);
7052 if (iccId != null) {
7053 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7054 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7055 }
7056 return null;
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007059 }
Derek Tan7226c842014-07-02 17:42:23 -07007060 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007061
7062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007063 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7064 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007065 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7066 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007068 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007069 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007070 return null;
7071 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007072
Jordan Liub49b04b2019-05-06 14:45:15 -07007073 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7074 // the process, where TelephonyManager was instantiated.
7075 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007076 final long identity = Binder.clearCallingIdentity();
7077 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007078 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 final TelephonyManager tele = TelephonyManager.from(context);
7080 final SubscriptionManager sub = SubscriptionManager.from(context);
7081
7082 // Figure out what subscribers are currently active
7083 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084
Jordan Liub49b04b2019-05-06 14:45:15 -07007085 // Only consider subs which match the current subId
7086 // This logic can be simplified. See b/131189269 for progress.
7087 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007088 activeSubscriberIds.add(tele.getSubscriberId(subId));
7089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090
7091 // First pass, find a number override for an active subscriber
7092 String mergeNumber = null;
7093 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7094 for (String key : prefs.keySet()) {
7095 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7096 final String subscriberId = (String) prefs.get(key);
7097 if (activeSubscriberIds.contains(subscriberId)) {
7098 final String iccId = key.substring(
7099 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7100 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7101 mergeNumber = (String) prefs.get(numberKey);
7102 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007103 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 + " for active subscriber " + subscriberId);
7105 }
7106 if (!TextUtils.isEmpty(mergeNumber)) {
7107 break;
7108 }
7109 }
7110 }
7111 }
7112
7113 // Shortcut when no active merged subscribers
7114 if (TextUtils.isEmpty(mergeNumber)) {
7115 return null;
7116 }
7117
7118 // Second pass, find all subscribers under that line override
7119 final ArraySet<String> result = new ArraySet<>();
7120 for (String key : prefs.keySet()) {
7121 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7122 final String number = (String) prefs.get(key);
7123 if (mergeNumber.equals(number)) {
7124 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7125 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7126 final String subscriberId = (String) prefs.get(subscriberKey);
7127 if (!TextUtils.isEmpty(subscriberId)) {
7128 result.add(subscriberId);
7129 }
7130 }
7131 }
7132 }
7133
7134 final String[] resultArray = result.toArray(new String[result.size()]);
7135 Arrays.sort(resultArray);
7136 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007137 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7139 }
7140 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007143 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007144 }
7145
7146 @Override
zoey chen38003472019-12-13 17:16:31 +08007147 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7148 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007149
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 final TelephonyManager telephonyManager = mApp.getSystemService(
7153 TelephonyManager.class);
7154 String subscriberId = telephonyManager.getSubscriberId(subId);
7155 if (subscriberId == null) {
7156 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007157 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007158 + subId);
7159 }
7160 return null;
7161 }
7162
7163 final SubscriptionInfo info = SubscriptionController.getInstance()
7164 .getSubscriptionInfo(subId);
7165 final ParcelUuid groupUuid = info.getGroupUuid();
7166 // If it doesn't belong to any group, return just subscriberId of itself.
7167 if (groupUuid == null) {
7168 return new String[]{subscriberId};
7169 }
7170
7171 // Get all subscriberIds from the group.
7172 final List<String> mergedSubscriberIds = new ArrayList<>();
7173 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007174 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007175 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007176 for (SubscriptionInfo subInfo : groupInfos) {
7177 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7178 if (subscriberId != null) {
7179 mergedSubscriberIds.add(subscriberId);
7180 }
7181 }
7182
7183 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186
7187 }
7188 }
7189
7190 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007191 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007192 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007193 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194
7195 final long identity = Binder.clearCallingIdentity();
7196 try {
7197 final Phone phone = getPhone(subId);
7198 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007202 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007203
7204 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007205 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007206 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7207 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007208 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7209 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 final Phone phone = getPhone(subId);
7214 if (phone == null) {
7215 return false;
7216 }
7217 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7218 cdmaNonRoamingList);
7219 } finally {
7220 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007221 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007222 }
7223
7224 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007225 @Deprecated
7226 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7227 enforceModifyPermission();
7228
7229 int returnValue = 0;
7230 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007231 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007232 if(result.exception == null) {
7233 if (result.result != null) {
7234 byte[] responseData = (byte[])(result.result);
7235 if(responseData.length > oemResp.length) {
7236 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7237 responseData.length + "bytes. Buffer Size is " +
7238 oemResp.length + "bytes.");
7239 }
7240 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7241 returnValue = responseData.length;
7242 }
7243 } else {
7244 CommandException ex = (CommandException) result.exception;
7245 returnValue = ex.getCommandError().ordinal();
7246 if(returnValue > 0) returnValue *= -1;
7247 }
7248 } catch (RuntimeException e) {
7249 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7250 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7251 if(returnValue > 0) returnValue *= -1;
7252 }
7253
7254 return returnValue;
7255 }
7256
7257 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007258 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007259 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007260 try {
7261 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007262 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007263 mApp, phone.getSubId(), "getRadioAccessFamily");
7264 } catch (SecurityException e) {
7265 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7266 throw e;
7267 }
chen xub97461a2018-10-26 14:17:57 -07007268 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007269 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007270 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 final long identity = Binder.clearCallingIdentity();
7273 try {
chen xub97461a2018-10-26 14:17:57 -07007274 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007275 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007276 mApp, phone.getSubId(), "getRadioAccessFamily");
7277 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
chen xub97461a2018-10-26 14:17:57 -07007281 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007282 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007283
7284 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007285 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007286 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007287 try {
7288 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7289 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007290 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007291 }
7292 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007293 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007294 }
7295 RoleManager rm = mApp.getSystemService(RoleManager.class);
7296 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7297 if (!dialerRoleHolders.contains(callingPackage)) {
7298 throw new SecurityException("App must be the dialer role holder to"
7299 + " upload a call composer pic");
7300 }
7301
7302 Executors.newSingleThreadExecutor().execute(() -> {
7303 ByteArrayOutputStream output = new ByteArrayOutputStream(
7304 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7305 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7306 boolean readUntilEnd = false;
7307 int totalBytesRead = 0;
7308 byte[] buffer = new byte[16 * 1024];
7309 while (true) {
7310 int numRead;
7311 try {
7312 numRead = input.read(buffer);
7313 } catch (IOException e) {
7314 try {
7315 fd.checkError();
7316 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7317 null);
7318 } catch (IOException e1) {
7319 // This means that the other side closed explicitly with an error. If this
7320 // happens, log and ignore.
7321 loge("Remote end of call composer picture pipe closed: " + e1);
7322 }
7323 break;
7324 }
7325 if (numRead == -1) {
7326 readUntilEnd = true;
7327 break;
7328 }
7329 totalBytesRead += numRead;
7330 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7331 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7332 try {
7333 input.close();
7334 } catch (IOException e) {
7335 // ignore
7336 }
7337 break;
7338 }
7339 output.write(buffer, 0, numRead);
7340 }
7341 // Generally, the remote end will close the file descriptors. The only case where we
7342 // close is above, where the picture size is too big.
7343
7344 try {
7345 fd.checkError();
7346 } catch (IOException e) {
7347 loge("Remote end for call composer closed with an error: " + e);
7348 return;
7349 }
7350
Hall Liuaa4211e2021-01-20 15:43:39 -08007351 if (!readUntilEnd) {
7352 loge("Did not finish reading entire image; aborting");
7353 return;
7354 }
Hall Liu82694d52020-12-11 18:22:04 -08007355
Hall Liuaa4211e2021-01-20 15:43:39 -08007356 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7357 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7358 new CallComposerPictureTransfer.Factory() {},
7359 imageData,
7360 (result) -> {
7361 if (result.first != null) {
7362 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7363 Bundle outputResult = new Bundle();
7364 outputResult.putParcelable(
7365 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7366 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7367 outputResult);
7368 } else {
7369 callback.send(result.second, null);
7370 }
7371 }
7372 );
Hall Liu82694d52020-12-11 18:22:04 -08007373 });
7374 }
7375
7376 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007377 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007378 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007379 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380
7381 final long identity = Binder.clearCallingIdentity();
7382 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 ImsManager.getInstance(defaultPhone.getContext(),
7384 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 } finally {
7386 Binder.restoreCallingIdentity(identity);
7387 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007388 }
7389
7390 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007391 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7394 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007395 return false;
7396 }
Svet Ganovb320e182015-04-16 12:30:10 -07007397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 final long identity = Binder.clearCallingIdentity();
7399 try {
7400 // Check the user preference and the system-level IMS setting. Even if the user has
7401 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7402 // In the long run, we may instead need to check if there exists a connection service
7403 // which can support video calling.
7404 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 return imsManager.isVtEnabledByPlatform()
7407 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7408 && imsManager.isVtEnabledByUser();
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
7411 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007412 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007413
Andrew Leea1239f22015-03-02 17:44:07 -08007414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007415 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7416 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 mApp, subId, callingPackage, callingFeatureId,
7419 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 return false;
7421 }
7422
7423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 CarrierConfigManager configManager =
7426 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
Andrew Leea1239f22015-03-02 17:44:07 -08007432 }
7433
7434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007435 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 return false;
7439 }
7440
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
7443 CarrierConfigManager configManager =
7444 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
Andrew Leea1239f22015-03-02 17:44:07 -08007450 }
7451
Andrew Lee9431b832015-03-09 18:46:45 -07007452 @Override
7453 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007454 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007455 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007456 }
7457
7458 @Override
7459 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007462 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 } finally {
7464 Binder.restoreCallingIdentity(identity);
7465 }
Andrew Lee9431b832015-03-09 18:46:45 -07007466 }
7467
Hall Liuf6668912018-10-31 17:05:23 -07007468 /**
7469 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7470 * support for the feature and device firmware support.
7471 *
7472 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7473 */
7474 @Override
7475 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007477 final Phone phone = getPhone(subscriptionId);
7478 if (phone == null) {
7479 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7480 return false;
7481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7485 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 return isCarrierSupported && isDeviceSupported;
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Hall Liu98187582018-01-22 19:15:32 -08007491 }
7492
Hall Liuf6668912018-10-31 17:05:23 -07007493 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007494 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7495 * RTT setting, will return true if the device and carrier both support RTT.
7496 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007497 */
7498 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 final long identity = Binder.clearCallingIdentity();
7500 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007501 boolean isRttSupported = isRttSupported(subscriptionId);
7502 boolean isUserRttSettingOn = Settings.Secure.getInt(
7503 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7504 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7505 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7506 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007510 }
7511
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007512 @Deprecated
7513 @Override
7514 public String getDeviceId(String callingPackage) {
7515 return getDeviceIdWithFeature(callingPackage, null);
7516 }
7517
Sanket Padawe7310cc72015-01-14 09:53:20 -08007518 /**
7519 * Returns the unique device ID of phone, for example, the IMEI for
7520 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7521 *
7522 * <p>Requires Permission:
7523 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7524 */
7525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007527 try {
7528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7529 } catch (SecurityException se) {
7530 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7531 throw new SecurityException("Package " + callingPackage + " does not belong to "
7532 + Binder.getCallingUid());
7533 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007534 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007535 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007536 return null;
7537 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007538 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007539 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007541 return null;
7542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543
7544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 return phone.getDeviceId();
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007550 }
7551
Ping Sunc67b7c22016-03-02 19:16:45 +08007552 /**
7553 * {@hide}
7554 * Returns the IMS Registration Status on a particular subid
7555 *
7556 * @param subId
7557 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007558 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007559 Phone phone = getPhone(subId);
7560 if (phone != null) {
7561 return phone.isImsRegistered();
7562 } else {
7563 return false;
7564 }
7565 }
7566
Santos Cordon7a1885b2015-02-03 11:15:19 -08007567 @Override
7568 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007575 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007576
Tyler Gunnf70ed162019-04-03 15:28:53 -07007577 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007578 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007579 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007581 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007582 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7583 }
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
7590 }
7591
7592 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007593 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007594 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007595 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007596 mApp,
7597 subscriptionId,
7598 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 Phone phone = getPhone(subscriptionId);
7602 if (phone == null) {
7603 return null;
7604 }
7605 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7606 } finally {
7607 Binder.restoreCallingIdentity(identity);
7608 }
7609 }
7610
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007611 /**
7612 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007613 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007614 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 final long identity = Binder.clearCallingIdentity();
7616 try {
7617 Phone phone = getPhone(subId);
7618 if (phone != null) {
7619 return phone.isWifiCallingEnabled();
7620 } else {
7621 return false;
7622 }
7623 } finally {
7624 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007625 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007626 }
7627
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007628 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007629 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007630 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007631 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632 final long identity = Binder.clearCallingIdentity();
7633 try {
7634 Phone phone = getPhone(subId);
7635 if (phone != null) {
7636 return phone.isVideoEnabled();
7637 } else {
7638 return false;
7639 }
7640 } finally {
7641 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007642 }
7643 }
7644
7645 /**
7646 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7647 * defined in {@link ImsRegistrationImplBase}.
7648 */
7649 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 Phone phone = getPhone(subId);
7653 if (phone != null) {
7654 return phone.getImsRegistrationTech();
7655 } else {
7656 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7657 }
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007661 }
7662
Stuart Scott8eef64f2015-04-08 15:13:54 -07007663 @Override
7664 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007665 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007666 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7667 return;
7668 }
Kai Shif70f46f2021-03-03 13:59:46 -08007669 Phone defaultPhone = getDefaultPhone();
7670 if (defaultPhone != null) {
7671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7672 mApp, getDefaultPhone().getSubId(), "factoryReset");
7673 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007674 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007675
Svet Ganovcc087f82015-05-12 20:35:54 -07007676 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007677 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7678 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007679 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007680 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007681 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007682 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007683 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007684 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007685 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007686 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007687 // There has been issues when Sms raw table somehow stores orphan
7688 // fragments. They lead to garbled message when new fragments come
7689 // in and combined with those stale ones. In case this happens again,
7690 // user can reset all network settings which will clean up this table.
7691 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007692 // Clean up IMS settings as well here.
7693 int slotId = getSlotIndex(subId);
7694 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7695 ImsManager.getInstance(mApp, slotId).factoryReset();
7696 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007697
Kai Shif70f46f2021-03-03 13:59:46 -08007698 if (defaultPhone == null) {
7699 return;
7700 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007701 // Erase modem config if erase modem on network setting is enabled.
7702 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7703 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7704 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007705 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007706 }
Kai Shif70f46f2021-03-03 13:59:46 -08007707
7708 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007709 } finally {
7710 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007711 }
7712 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007713
SongFerngWangfd89b102021-05-27 22:44:54 +08007714 @VisibleForTesting
7715 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7716 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7717 return;
7718 }
7719 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7720 RILConstants.PREFERRED_NETWORK_MODE);
7721 SubscriptionManager.setSubscriptionProperty(subId,
7722 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7723 "user=" + defaultNetworkType);
7724 phone.loadAllowedNetworksFromSubscriptionDatabase();
7725 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7726 defaultNetworkType, null);
7727 }
7728
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007729 private void cleanUpSmsRawTable(Context context) {
7730 ContentResolver resolver = context.getContentResolver();
7731 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7732 resolver.delete(uri, null, null);
7733 }
7734
Narayan Kamath1c496c22015-04-16 14:40:19 +01007735 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007736 public String getSimLocaleForSubscriber(int subId) {
7737 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7738 final Phone phone = getPhone(subId);
7739 if (phone == null) {
7740 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007741 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007742 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743 final long identity = Binder.clearCallingIdentity();
7744 try {
chen xu5d3637b2019-01-21 23:31:38 -08007745 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007746 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007747 if (info == null) {
7748 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7749 return null;
7750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 // Try and fetch the locale from the carrier properties or from the SIM language
7752 // preferences (EF-PL and EF-LI)...
7753 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007755 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7756 if (localeFromDefaultSim != null) {
7757 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7758 if (DBG) log("Using locale from subId: " + subId + " locale: "
7759 + localeFromDefaultSim);
7760 return localeFromDefaultSim.toLanguageTag();
7761 } else {
7762 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 }
7764 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 // The SIM language preferences only store a language (e.g. fr = French), not an
7767 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7768 // the SIM and carrier preferences does not include a country we add the country
7769 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007770 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007772 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773 return mccLocale.toLanguageTag();
7774 }
7775
7776 if (DBG) log("No locale found - returning null");
7777 return null;
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
7780 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007781 }
7782
7783 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007784 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007785 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007786 }
7787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 /**
7789 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7790 */
7791 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007792 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007793 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007794 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007795
Chenjie Yu1ba97252018-01-11 18:16:20 -08007796 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007797 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007798
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007799 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007800 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7801 * representing the state of the modem.
7802 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007803 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7804 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007805 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007806 */
7807 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007808 public void requestModemActivityInfo(ResultReceiver result) {
7809 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007810 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811
7812 final long identity = Binder.clearCallingIdentity();
7813 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007814 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 } finally {
7816 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007817 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007818 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007819
Siddharth Rayb8114062018-06-17 15:02:38 -07007820 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7821 // less than total activity duration.
7822 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7823 if (info == null) {
7824 return false;
7825 }
7826 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007827 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7828 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7829
Siddharth Rayb8114062018-06-17 15:02:38 -07007830 return (info.isValid()
7831 && (info.getSleepTimeMillis() <= activityDurationMs)
7832 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007833 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007834 && (totalTxTimeMs <= activityDurationMs));
7835 }
7836
Jack Yu85bd38a2015-11-09 11:34:32 -08007837 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007838 * Returns the service state information on specified subscription.
7839 */
7840 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007841 public ServiceState getServiceStateForSubscriber(int subId,
7842 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7843 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007845 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007846 return null;
7847 }
7848
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007849 boolean hasFinePermission = false;
7850 boolean hasCoarsePermission = false;
7851 if (!renounceFineLocationAccess) {
7852 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7853 LocationAccessPolicy.checkLocationPermission(mApp,
7854 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7855 .setCallingPackage(callingPackage)
7856 .setCallingFeatureId(callingFeatureId)
7857 .setCallingPid(Binder.getCallingPid())
7858 .setCallingUid(Binder.getCallingUid())
7859 .setMethod("getServiceStateForSubscriber")
7860 .setLogAsInfo(true)
7861 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7862 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7863 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7864 .build());
7865 hasFinePermission =
7866 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7867 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007868
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007869 if (!renounceCoarseLocationAccess) {
7870 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7871 LocationAccessPolicy.checkLocationPermission(mApp,
7872 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7873 .setCallingPackage(callingPackage)
7874 .setCallingFeatureId(callingFeatureId)
7875 .setCallingPid(Binder.getCallingPid())
7876 .setCallingUid(Binder.getCallingUid())
7877 .setMethod("getServiceStateForSubscriber")
7878 .setLogAsInfo(true)
7879 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7880 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7881 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7882 .build());
7883 hasCoarsePermission =
7884 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7885 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007886
Jack Yu479f40e2020-10-27 21:29:25 -07007887 final Phone phone = getPhone(subId);
7888 if (phone == null) {
7889 return null;
7890 }
7891
Jordan Liu0f2bc442020-11-18 16:47:37 -08007892 final long identity = Binder.clearCallingIdentity();
7893
Jack Yu479f40e2020-10-27 21:29:25 -07007894 boolean isCallingPackageDataService = phone.getDataServicePackages()
7895 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007897 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7898 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7899 Rlog.d(LOG_TAG,
7900 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7901 return null;
7902 }
7903
Hall Liuf19c44f2018-11-27 14:38:17 -08007904 ServiceState ss = phone.getServiceState();
7905
7906 // Scrub out the location info in ServiceState depending on what level of access
7907 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007908 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007909 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7910 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 } finally {
7912 Binder.restoreCallingIdentity(identity);
7913 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007914 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007915
7916 /**
7917 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7918 *
7919 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7920 * voicemail ringtone.
7921 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7922 * PhoneAccount.
7923 */
7924 @Override
7925 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7929 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007933 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
7936 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007937 }
7938
7939 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007940 * Sets the per-account voicemail ringtone.
7941 *
7942 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7943 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7944 *
7945 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7946 * voicemail ringtone.
7947 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7948 * PhoneAccount.
7949 */
7950 @Override
7951 public void setVoicemailRingtoneUri(String callingPackage,
7952 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007953 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007954 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007955 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7956 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7958 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7959 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961
7962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7965 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007966 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 }
7968 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007971 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007972 }
7973
7974 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007975 * Returns whether vibration is set for voicemail notification in Phone settings.
7976 *
7977 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7978 * voicemail vibration setting.
7979 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7980 */
7981 @Override
7982 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 final long identity = Binder.clearCallingIdentity();
7984 try {
7985 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7986 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007987 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
7993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007994 }
7995
Youhan Wange64578a2016-05-02 15:32:42 -07007996 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 * Sets the per-account voicemail vibration.
7998 *
7999 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8000 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8001 *
8002 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8003 * voicemail vibration setting.
8004 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8005 * specific PhoneAccount.
8006 */
8007 @Override
8008 public void setVoicemailVibrationEnabled(String callingPackage,
8009 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008010 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008011 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008012 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8013 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8015 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8016 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008017 }
8018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 final long identity = Binder.clearCallingIdentity();
8020 try {
8021 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8022 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008023 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 }
8025 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8026 } finally {
8027 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008028 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008029 }
8030
8031 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008032 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8033 *
8034 * @throws SecurityException if the caller does not have the required permission
8035 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008036 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008037 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008038 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008039 }
8040
8041 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008042 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8043 * permission.
8044 *
8045 * @throws SecurityException if the caller does not have the required permission
8046 */
8047 private void enforceSendSmsPermission() {
8048 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8049 }
8050
8051 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008052 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008053 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008054 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008055 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008056 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008057 final long identity = Binder.clearCallingIdentity();
8058 try {
8059 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008060 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 if (componentName == null) {
8062 throw new SecurityException(
8063 "Caller not current active visual voicemail package[null]");
8064 }
8065 String vvmPackage = componentName.getPackageName();
8066 if (!callingPackage.equals(vvmPackage)) {
8067 throw new SecurityException("Caller not current active visual voicemail package["
8068 + vvmPackage + "]");
8069 }
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008072 }
8073 }
8074
8075 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008076 * Return the application ID for the app type.
8077 *
8078 * @param subId the subscription ID that this request applies to.
8079 * @param appType the uicc app type.
8080 * @return Application ID for specificied app type, or null if no uicc.
8081 */
8082 @Override
8083 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008084 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008085 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086
8087 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008088 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 if (phone == null) {
8090 return null;
8091 }
8092 String aid = null;
8093 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008094 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 .getApplicationByType(appType).getAid();
8096 } catch (Exception e) {
8097 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8098 }
8099 return aid;
8100 } finally {
8101 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008102 }
Youhan Wange64578a2016-05-02 15:32:42 -07008103 }
8104
Youhan Wang4001d252016-05-11 10:29:41 -07008105 /**
8106 * Return the Electronic Serial Number.
8107 *
8108 * @param subId the subscription ID that this request applies to.
8109 * @return ESN or null if error.
8110 */
8111 @Override
8112 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008113 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008114 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115
8116 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008117 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 if (phone == null) {
8119 return null;
8120 }
8121 String esn = null;
8122 try {
8123 esn = phone.getEsn();
8124 } catch (Exception e) {
8125 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8126 }
8127 return esn;
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008130 }
Youhan Wang4001d252016-05-11 10:29:41 -07008131 }
8132
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008133 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008134 * Return the Preferred Roaming List Version.
8135 *
8136 * @param subId the subscription ID that this request applies to.
8137 * @return PRLVersion or null if error.
8138 */
8139 @Override
8140 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008141 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008142 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143
8144 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008145 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146 if (phone == null) {
8147 return null;
8148 }
8149 String cdmaPrlVersion = null;
8150 try {
8151 cdmaPrlVersion = phone.getCdmaPrlVersion();
8152 } catch (Exception e) {
8153 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8154 }
8155 return cdmaPrlVersion;
8156 } finally {
8157 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008158 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008159 }
8160
8161 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008162 * Get snapshot of Telephony histograms
8163 * @return List of Telephony histograms
8164 * @hide
8165 */
8166 @Override
8167 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8169 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170
8171 final long identity = Binder.clearCallingIdentity();
8172 try {
8173 return RIL.getTelephonyRILTimingHistograms();
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
8176 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008177 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008178
8179 /**
8180 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008181 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8182 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008183 * Require system privileges. In the future we may add this to carrier APIs.
8184 *
Michele Berionne482f8202018-11-27 18:57:59 -08008185 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008186 */
8187 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008188 @TelephonyManager.SetCarrierRestrictionResult
8189 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008190 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008191 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008192
Michele Berionne482f8202018-11-27 18:57:59 -08008193 if (carrierRestrictionRules == null) {
8194 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008195 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008197 final long identity = Binder.clearCallingIdentity();
8198 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008199 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008200 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008204 }
8205
8206 /**
8207 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008208 * Get the allowed carrier list and the excluded carrier list, including the priority between
8209 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008210 * Require system privileges. In the future we may add this to carrier APIs.
8211 *
Michele Berionne482f8202018-11-27 18:57:59 -08008212 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008213 */
8214 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008215 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008216 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008217 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218
8219 final long identity = Binder.clearCallingIdentity();
8220 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008221 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8222 if (response instanceof CarrierRestrictionRules) {
8223 return (CarrierRestrictionRules) response;
8224 }
8225 // Response is an Exception of some kind,
8226 // which is signalled to the user as a NULL retval
8227 return null;
8228 } catch (Exception e) {
8229 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8230 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 } finally {
8232 Binder.restoreCallingIdentity(identity);
8233 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008234 }
8235
fionaxu59545b42016-05-25 15:53:37 -07008236 /**
fionaxu59545b42016-05-25 15:53:37 -07008237 * Action set from carrier signalling broadcast receivers to enable/disable radio
8238 * @param subId the subscription ID that this action applies to.
8239 * @param enabled control enable or disable radio.
8240 * {@hide}
8241 */
8242 @Override
8243 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8244 enforceModifyPermission();
8245 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246
8247 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008248 if (phone == null) {
8249 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8250 return;
8251 }
8252 try {
8253 phone.carrierActionSetRadioEnabled(enabled);
8254 } catch (Exception e) {
8255 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 } finally {
8257 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008258 }
8259 }
8260
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008261 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008262 * Enable or disable Voice over NR (VoNR)
8263 * @param subId the subscription ID that this action applies to.
8264 * @param enabled enable or disable VoNR.
8265 * @return operation result.
8266 */
8267 @Override
8268 public int setVoNrEnabled(int subId, boolean enabled) {
8269 enforceModifyPermission();
8270 final Phone phone = getPhone(subId);
8271
8272 final long identity = Binder.clearCallingIdentity();
8273 if (phone == null) {
8274 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8275 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8276 }
8277
8278 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8279 try {
8280 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8281 workSource);
8282 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008283
8284 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8285 if (DBG) {
8286 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8287 }
8288 SubscriptionManager.setSubscriptionProperty(
8289 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8290 (enabled ? "1" : "0"));
8291 }
8292
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008293 return result;
8294 } finally {
8295 Binder.restoreCallingIdentity(identity);
8296 }
8297 }
8298
8299 /**
8300 * Is voice over NR enabled
8301 * @return true if VoNR is enabled else false
8302 */
8303 @Override
8304 public boolean isVoNrEnabled(int subId) {
8305 enforceReadPrivilegedPermission("isVoNrEnabled");
8306 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8307 final long identity = Binder.clearCallingIdentity();
8308 try {
8309 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8310 null, subId, workSource);
8311 if (DBG) log("isVoNrEnabled: " + isEnabled);
8312 return isEnabled;
8313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
8316 }
8317
8318 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008319 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8320 * network status based on which carrier apps could apply actions accordingly,
8321 * enable/disable default url handler for example.
8322 *
8323 * @param subId the subscription ID that this action applies to.
8324 * @param report control start/stop reporting the default network status.
8325 * {@hide}
8326 */
8327 @Override
8328 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8329 enforceModifyPermission();
8330 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331
8332 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008333 if (phone == null) {
8334 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8335 return;
8336 }
8337 try {
8338 phone.carrierActionReportDefaultNetworkStatus(report);
8339 } catch (Exception e) {
8340 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 } finally {
8342 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008343 }
8344 }
8345
8346 /**
fionaxud9622282017-07-17 17:51:30 -07008347 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8348 * @param subId the subscription ID that this action applies to.
8349 * {@hide}
8350 */
8351 @Override
8352 public void carrierActionResetAll(int subId) {
8353 enforceModifyPermission();
8354 final Phone phone = getPhone(subId);
8355 if (phone == null) {
8356 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8357 return;
8358 }
8359 try {
8360 phone.carrierActionResetAll();
8361 } catch (Exception e) {
8362 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8363 }
8364 }
8365
8366 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008367 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8368 * bug report is being generated.
8369 */
8370 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008371 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008372 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8373 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008374 writer.println("Permission Denial: can't dump Phone from pid="
8375 + Binder.getCallingPid()
8376 + ", uid=" + Binder.getCallingUid()
8377 + "without permission "
8378 + android.Manifest.permission.DUMP);
8379 return;
8380 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008381 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008382 }
Jack Yueb89b242016-06-22 13:27:47 -07008383
Brad Ebingerdac2f002018-04-03 15:17:52 -07008384 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008385 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8386 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8387 @NonNull String[] args) {
8388 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8389 this, in.getFileDescriptor(), out.getFileDescriptor(),
8390 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008391 }
8392
Jack Yueb89b242016-06-22 13:27:47 -07008393 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008394 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008395 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008396 * @param reason the reason the data enable change is taking place
8397 * @param enabled True if enabling the data, otherwise disabling.
8398 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008399 */
8400 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008401 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008402 boolean enabled) {
8403 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8404 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8405 try {
8406 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008407 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008408 } catch (SecurityException se) {
8409 enforceModifyPermission();
8410 }
8411 } else {
8412 enforceModifyPermission();
8413 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414
8415 final long identity = Binder.clearCallingIdentity();
8416 try {
8417 Phone phone = getPhone(subId);
8418 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008419 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8420 phone.carrierActionSetMeteredApnsEnabled(enabled);
8421 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008422 if (phone.isUsingNewDataStack()) {
8423 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8424 } else {
8425 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8426 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008428 }
8429 } finally {
8430 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008431 }
8432 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008433
8434 /**
8435 * Get Client request stats
8436 * @return List of Client Request Stats
8437 * @hide
8438 */
8439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008440 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8441 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008443 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008444 return null;
8445 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008446 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008448 final long identity = Binder.clearCallingIdentity();
8449 try {
8450 if (phone != null) {
8451 return phone.getClientRequestStats();
8452 }
8453
8454 return null;
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
8457 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008458 }
8459
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008460 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008461 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008462 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008463 }
Jack Yueb4124c2017-02-16 15:32:43 -08008464
8465 /**
Grace Chen70990072017-03-24 17:21:30 -07008466 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008467 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008468 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008469 * @param state State of SIM (power down, power up, pass through)
8470 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8471 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8472 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008473 *
8474 **/
8475 @Override
Grace Chen70990072017-03-24 17:21:30 -07008476 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008477 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008478 Phone phone = PhoneFactory.getPhone(slotIndex);
8479
vagdeviaf9a5b92018-08-15 16:01:53 -07008480 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 final long identity = Binder.clearCallingIdentity();
8483 try {
8484 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008485 phone.setSimPowerState(state, null, workSource);
8486 }
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
8489 }
8490 }
8491
8492 /**
8493 * Set SIM card power state.
8494 *
8495 * @param slotIndex SIM slot id.
8496 * @param state State of SIM (power down, power up, pass through)
8497 * @param callback callback to trigger after success or failure
8498 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8499 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8500 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8501 *
8502 **/
8503 @Override
8504 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8505 IIntegerConsumer callback) {
8506 enforceModifyPermission();
8507 Phone phone = PhoneFactory.getPhone(slotIndex);
8508
8509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8510
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 if (phone != null) {
8514 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8515 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516 }
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008519 }
8520 }
Shuo Qiandd210312017-04-12 22:11:33 +00008521
Tyler Gunn65d45c22017-06-05 11:22:26 -07008522 private boolean isUssdApiAllowed(int subId) {
8523 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008524 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008525 if (configManager == null) {
8526 return false;
8527 }
8528 PersistableBundle pb = configManager.getConfigForSubId(subId);
8529 if (pb == null) {
8530 return false;
8531 }
8532 return pb.getBoolean(
8533 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8534 }
8535
Shuo Qiandd210312017-04-12 22:11:33 +00008536 /**
8537 * Check if phone is in emergency callback mode
8538 * @return true if phone is in emergency callback mode
8539 * @param subId sub id
8540 */
goneil9c5f4872017-12-05 14:07:56 -08008541 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008542 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008543 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008544 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545
8546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 if (phone != null) {
8549 return phone.isInEcm();
8550 } else {
8551 return false;
8552 }
8553 } finally {
8554 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008555 }
8556 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008557
8558 /**
8559 * Get the current signal strength information for the given subscription.
8560 * Because this information is not updated when the device is in a low power state
8561 * it should not be relied-upon to be current.
8562 * @param subId Subscription index
8563 * @return the most recent cached signal strength info from the modem
8564 */
8565 @Override
8566 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567 final long identity = Binder.clearCallingIdentity();
8568 try {
8569 Phone p = getPhone(subId);
8570 if (p == null) {
8571 return null;
8572 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 return p.getSignalStrength();
8575 } finally {
8576 Binder.restoreCallingIdentity(identity);
8577 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008578 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008579
Pengquan Meng77b7f132018-08-22 14:49:57 -07008580 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008581 * Get the current modem radio state for the given slot.
8582 * @param slotIndex slot index.
8583 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008584 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008585 * @return the current radio power state from the modem
8586 */
8587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008588 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008589 Phone phone = PhoneFactory.getPhone(slotIndex);
8590 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8592 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008593 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8594 }
8595
8596 final long identity = Binder.clearCallingIdentity();
8597 try {
8598 return phone.getRadioPowerState();
8599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
8602 }
8603 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8604 }
8605
8606 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008607 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8608 *
8609 * <p>Requires one of the following permissions:
8610 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008611 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008612 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8613 * privileges.
8614 *
8615 * @param subId subscription id
8616 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8617 * {@code false}.
8618 */
8619 @Override
8620 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008621 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008622 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008623 try {
8624 mApp.enforceCallingOrSelfPermission(
8625 android.Manifest.permission.ACCESS_NETWORK_STATE,
8626 functionName);
8627 } catch (Exception e) {
8628 mApp.enforceCallingOrSelfPermission(
8629 permission.READ_BASIC_PHONE_STATE, functionName);
8630 }
Shuo Qian093013d2020-08-13 15:42:55 -07008631 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008632 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008633 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008634 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008635
Pengquan Menga1bb6272018-09-06 09:59:22 -07008636 boolean isEnabled = false;
8637 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008638 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008639 Phone phone = getPhone(subId);
8640 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008641 } finally {
8642 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008644 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008645 }
8646
8647
8648 /**
8649 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8650 *
8651 * <p> Requires permission:
8652 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8653 * privileges.
8654 *
8655 * @param subId subscription id
8656 * @param isEnabled {@code true} means enable, {@code false} means disable.
8657 */
8658 @Override
8659 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8661 mApp, subId, "setDataRoamingEnabled");
8662
Pengquan Menga1bb6272018-09-06 09:59:22 -07008663 final long identity = Binder.clearCallingIdentity();
8664 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008665 Phone phone = getPhone(subId);
8666 if (phone != null) {
8667 phone.setDataRoamingEnabled(isEnabled);
8668 }
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008671 }
8672 }
8673
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008674 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008675 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008676 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008677 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008678 mApp, subId, "isManualNetworkSelectionAllowed");
8679
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008680 boolean isAllowed = true;
8681 final long identity = Binder.clearCallingIdentity();
8682 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008683 Phone phone = getPhone(subId);
8684 if (phone != null) {
8685 isAllowed = phone.isCspPlmnEnabled();
8686 }
8687 } finally {
8688 Binder.restoreCallingIdentity(identity);
8689 }
8690 return isAllowed;
8691 }
8692
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008693 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8694 UiccProfile profile = port.getUiccProfile();
8695 if (profile == null ||
8696 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8697 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8698 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008699 }
8700 return true;
8701 }
8702
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008703 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008704 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008705 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008706 mApp.getSystemService(AppOpsManager.class)
8707 .checkPackage(Binder.getCallingUid(), callingPackage);
8708
Jordan Liu1e142fc2019-04-22 15:10:43 -07008709 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008710 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008711 try {
8712 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008713 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008714 } catch (SecurityException e) {
8715 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8716 // has carrier privileges on an active UICC
8717 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8718 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008719 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008720 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008721 }
sandeepjs0a502c42021-09-27 15:34:44 +00008722 // checking compatibility, if calling app's target SDK is T and beyond.
8723 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8724 Binder.getCallingUid())) {
8725 isIccIdAccessRestricted = true;
8726 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008727 final long identity = Binder.clearCallingIdentity();
8728 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008729 UiccController uiccController = UiccController.getInstance();
8730 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008731 if (hasReadPermission) {
8732 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008733 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008734
8735 // Remove private info if the caller doesn't have access
8736 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8737 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008738 //setting the value after compatibility check
8739 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008740 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8741 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008742 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008743 if (card == null) {
8744 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008745 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008746 continue;
8747 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008748 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8749 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008750 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008751 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008752 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008753 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8754 for (UiccPortInfo portInfo : portInfos) {
8755 UiccPort port = uiccController.getUiccPortForSlot(
8756 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8757 if (port == null) {
8758 // assume no access if port is null
8759 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8760 continue;
8761 }
8762 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8763 uiccPortInfos.add(portInfo);
8764 } else {
8765 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8766 }
8767 }
8768 filteredInfos.add(new UiccCardInfo(
8769 cardInfo.isEuicc(),
8770 cardInfo.getCardId(),
8771 null,
8772 cardInfo.getPhysicalSlotIndex(),
8773 cardInfo.isRemovable(),
8774 cardInfo.isMultipleEnabledProfilesSupported(),
8775 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008776 }
8777 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008778 } finally {
8779 Binder.restoreCallingIdentity(identity);
8780 }
8781 }
8782
sandeepjs0a502c42021-09-27 15:34:44 +00008783 /**
8784 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8785 * generally private and require carrier privileges to view.
8786 *
8787 * @hide
8788 */
8789 @NonNull
8790 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8791 List<UiccPortInfo> portinfo = new ArrayList<>();
8792 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8793 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8794 }
8795 return new UiccCardInfo(
8796 cardInfo.isEuicc(),
8797 cardInfo.getCardId(),
8798 null,
8799 cardInfo.getPhysicalSlotIndex(),
8800 cardInfo.isRemovable(),
8801 cardInfo.isMultipleEnabledProfilesSupported(),
8802 portinfo
8803 );
8804 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008805
sandeepjs0a502c42021-09-27 15:34:44 +00008806 /**
8807 * @hide
8808 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8809 * These values are generally private and require carrier privileges to view.
8810 */
8811 @NonNull
8812 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8813 return new UiccPortInfo(
8814 UiccPortInfo.ICCID_REDACTED,
8815 portInfo.getPortIndex(),
8816 portInfo.getLogicalSlotIndex(),
8817 portInfo.isActive()
8818 );
8819 }
8820 @Override
8821 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008822 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008823 mApp.getSystemService(AppOpsManager.class)
8824 .checkPackage(Binder.getCallingUid(), callingPackage);
8825
8826 boolean hasReadPermission = false;
8827 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008828
8829 try {
8830 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8831 hasReadPermission = true;
8832 } catch (SecurityException e) {
8833 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8834 // has carrier privileges on an active UICC
8835 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8836 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8837 hasReadPermission = true;
8838 }
8839 }
8840
8841 // checking compatibility, if calling app's target SDK is T and beyond.
8842 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8843 Binder.getCallingUid())) {
8844 isLogicalSlotAccessRestricted = true;
8845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008846 final long identity = Binder.clearCallingIdentity();
8847 try {
8848 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8849 if (slots == null) {
8850 Rlog.i(LOG_TAG, "slots is null.");
8851 return null;
8852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008853 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8854 for (int i = 0; i < slots.length; i++) {
8855 UiccSlot slot = slots[i];
8856 if (slot == null) {
8857 continue;
8858 }
8859
Jordan Liu7be7e652019-05-06 18:55:02 +00008860 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861 UiccCard card = slot.getUiccCard();
8862 if (card != null) {
8863 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008864 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008865 cardId = slot.getEid();
8866 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008867 // If cardId is null, use iccId of default port as cardId. Check if has
8868 // read permission otherwise set to null.(card is null which means no
8869 // carrier permission)
8870 cardId = hasReadPermission ? slot.getIccId(
8871 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008873 }
8874
Jordan Liu857451f2019-05-09 16:35:35 -07008875 if (cardId != null) {
8876 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8877 // if cardId is an EID, it's all digits so this is fine
8878 cardId = IccUtils.stripTrailingFs(cardId);
8879 }
8880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 int cardState = 0;
8882 switch (slot.getCardState()) {
8883 case CARDSTATE_ABSENT:
8884 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8885 break;
8886 case CARDSTATE_PRESENT:
8887 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8888 break;
8889 case CARDSTATE_ERROR:
8890 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8891 break;
8892 case CARDSTATE_RESTRICTED:
8893 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8894 break;
8895 default:
8896 break;
8897
8898 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008899 List<UiccPortInfo> portInfos = new ArrayList<>();
8900 int[] portIndexes = slot.getPortList();
8901 for (int portIdx : portIndexes) {
8902 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8903 callingPackage, hasReadPermission));
8904 if (slot.isPortActive(portIdx)) {
8905 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8906 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8907 port.getPhoneId(), true));
8908 } else {
8909 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8910 }
8911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008913 slot.isEuicc(),
8914 cardId,
8915 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008916 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008917 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008918 //setting the value after compatibility check
8919 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 }
8921 return infos;
8922 } finally {
8923 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008924 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008925 }
8926
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008927 /* Returns null if doesn't have read permission or carrier privilege access. */
8928 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8929 boolean hasReadPermission) {
8930 String iccId = slot.getIccId(portIndex);
8931 if (hasReadPermission) { // if has read permission
8932 return iccId;
8933 } else {
8934 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8935 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8936 // if no read permission, checking carrier privilege access
8937 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8938 return iccId;
8939 }
8940 }
8941 }
8942 // No read permission or carrier privilege access.
8943 return UiccPortInfo.ICCID_REDACTED;
8944 }
8945
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008946 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008947 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008948 public boolean switchSlots(int[] physicalSlots) {
8949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950
8951 final long identity = Binder.clearCallingIdentity();
8952 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008953 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8954 for (int i = 0; i < physicalSlots.length; i++) {
8955 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8956 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8957 physicalSlots[i], i));
8958 }
8959 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008963 }
Jack Yu4c988042018-02-27 15:30:01 -08008964
8965 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008966 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8967 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8968 enforceModifyPermission();
8969
8970 final long identity = Binder.clearCallingIdentity();
8971 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008972 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00008973 } finally {
8974 Binder.restoreCallingIdentity(identity);
8975 }
8976 }
8977
8978 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008979 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008980 final long identity = Binder.clearCallingIdentity();
8981 try {
8982 return UiccController.getInstance().getCardIdForDefaultEuicc();
8983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
8986 }
8987
Pengquan Meng85728fb2018-03-12 16:31:21 -07008988 /**
goneil47ffb6e2018-04-06 15:40:58 -07008989 * A test API to reload the UICC profile.
8990 *
8991 * <p>Requires that the calling app has permission
8992 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8993 * @hide
8994 */
8995 @Override
8996 public void refreshUiccProfile(int subId) {
8997 enforceModifyPermission();
8998
8999 final long identity = Binder.clearCallingIdentity();
9000 try {
9001 Phone phone = getPhone(subId);
9002 if (phone == null) {
9003 return;
9004 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009005 UiccPort uiccPort = phone.getUiccPort();
9006 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009007 return;
9008 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009009 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009010 if (uiccProfile == null) {
9011 return;
9012 }
9013 uiccProfile.refresh();
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
9016 }
9017 }
9018
9019 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009020 * Returns false if the mobile data is disabled by default, otherwise return true.
9021 */
9022 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009023 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009024 }
9025
9026 /**
9027 * Returns true if the data roaming is enabled by default, i.e the system property
9028 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9029 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9030 */
9031 private boolean getDefaultDataRoamingEnabled(int subId) {
9032 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009033 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009034 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009035 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9036 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9037 return isDataRoamingEnabled;
9038 }
9039
9040 /**
9041 * Returns the default network type for the given {@code subId}, if the default network type is
9042 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9043 */
9044 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009045 List<Integer> list = TelephonyProperties.default_network();
9046 int phoneId = mSubscriptionController.getPhoneId(subId);
9047 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9048 return list.get(phoneId);
9049 }
9050 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009051 }
fionaxua13278b2018-03-21 00:08:13 -07009052
9053 @Override
9054 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009055 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
9060 final Phone phone = getPhone(subId);
9061 if (phone == null) {
9062 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9063 return;
9064 }
Rambo Wanga7436882022-01-13 21:51:44 -08009065 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9066 if (cpt != null) {
9067 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9068 }
9069 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009070 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9071 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009072 if (carrierPrivilegeRules == null) {
9073 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9074 } else {
9075 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009077 } finally {
9078 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009079 }
fionaxua13278b2018-03-21 00:08:13 -07009080 }
9081
9082 @Override
9083 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009084 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009085
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
9088 final Phone phone = getPhone(subId);
9089 if (phone == null) {
9090 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9091 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9092 }
9093 return phone.getCarrierIdListVersion();
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009096 }
fionaxua13278b2018-03-21 00:08:13 -07009097 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009098
9099 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009100 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9101 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009103 mApp, subId, callingPackage, callingFeatureId,
9104 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009105 return -1;
9106 }
9107
9108 final long identity = Binder.clearCallingIdentity();
9109 try {
9110 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9111 } finally {
9112 Binder.restoreCallingIdentity(identity);
9113 }
9114 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009115
9116 @Override
9117 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009118 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009119 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009120 mApp, subId, "getCdmaRoamingMode");
9121
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
9124 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9125 } finally {
9126 Binder.restoreCallingIdentity(identity);
9127 }
9128 }
9129
9130 @Override
9131 public boolean setCdmaRoamingMode(int subId, int mode) {
9132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9133 mApp, subId, "setCdmaRoamingMode");
9134
9135 final long identity = Binder.clearCallingIdentity();
9136 try {
9137 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9138 } finally {
9139 Binder.restoreCallingIdentity(identity);
9140 }
9141 }
9142
9143 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009144 public int getCdmaSubscriptionMode(int subId) {
9145 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009146 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009147 mApp, subId, "getCdmaSubscriptionMode");
9148
9149 final long identity = Binder.clearCallingIdentity();
9150 try {
9151 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9152 } finally {
9153 Binder.restoreCallingIdentity(identity);
9154 }
9155 }
9156
9157 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009158 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9160 mApp, subId, "setCdmaSubscriptionMode");
9161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009169
sqianc5eccab2018-10-19 18:46:41 -07009170 @Override
sqian8c685422019-02-22 15:55:18 -08009171 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009172 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009174 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9175 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009176 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9177 }
9178 final long identity = Binder.clearCallingIdentity();
9179 try {
sqian854d44b2018-12-12 16:48:18 -08009180 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9181 for (Phone phone: PhoneFactory.getPhones()) {
9182 if (phone.getEmergencyNumberTracker() != null
9183 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9184 emergencyNumberListInternal.put(
9185 phone.getSubId(),
9186 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9187 }
sqian11b7a0e2018-12-05 18:48:28 -08009188 }
sqian854d44b2018-12-12 16:48:18 -08009189 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009190 } finally {
9191 Binder.restoreCallingIdentity(identity);
9192 }
sqianc5eccab2018-10-19 18:46:41 -07009193 }
9194
9195 @Override
sqian8c685422019-02-22 15:55:18 -08009196 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009197 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009198 if (!exactMatch) {
9199 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009200 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009201 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009202 }
9203 final long identity = Binder.clearCallingIdentity();
9204 try {
sqian854d44b2018-12-12 16:48:18 -08009205 for (Phone phone: PhoneFactory.getPhones()) {
9206 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009207 && phone.getEmergencyNumberTracker()
9208 .isEmergencyNumber(number, exactMatch)) {
9209 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009210 }
sqian11b7a0e2018-12-05 18:48:28 -08009211 }
9212 return false;
9213 } finally {
9214 Binder.restoreCallingIdentity(identity);
9215 }
9216 }
9217
sqianf4ca7ed2019-01-15 18:32:07 -08009218 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009219 * Start emergency callback mode for GsmCdmaPhone for testing.
9220 */
9221 @Override
9222 public void startEmergencyCallbackMode() {
9223 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9224 "startEmergencyCallbackMode");
9225 enforceModifyPermission();
9226 final long identity = Binder.clearCallingIdentity();
9227 try {
9228 for (Phone phone : PhoneFactory.getPhones()) {
9229 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9230 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9231 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9232 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9233 gsmCdmaPhone.obtainMessage(
9234 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9235 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9236 }
9237 }
9238 } finally {
9239 Binder.restoreCallingIdentity(identity);
9240 }
9241 }
9242
9243 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009244 * Update emergency number list for test mode.
9245 */
9246 @Override
9247 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9248 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9249 "updateEmergencyNumberListTestMode");
9250
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 for (Phone phone: PhoneFactory.getPhones()) {
9254 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9255 if (tracker != null) {
9256 tracker.executeEmergencyNumberTestModeCommand(action, num);
9257 }
9258 }
9259 } finally {
9260 Binder.restoreCallingIdentity(identity);
9261 }
9262 }
9263
9264 /**
9265 * Get the full emergency number list for test mode.
9266 */
9267 @Override
9268 public List<String> getEmergencyNumberListTestMode() {
9269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9270 "getEmergencyNumberListTestMode");
9271
9272 final long identity = Binder.clearCallingIdentity();
9273 try {
9274 Set<String> emergencyNumbers = new HashSet<>();
9275 for (Phone phone: PhoneFactory.getPhones()) {
9276 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9277 if (tracker != null) {
9278 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9279 emergencyNumbers.add(num.getNumber());
9280 }
9281 }
9282 }
9283 return new ArrayList<>(emergencyNumbers);
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
chen xud6b45bd2018-10-30 22:27:10 -07009289 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009290 public int getEmergencyNumberDbVersion(int subId) {
9291 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9292
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 final Phone phone = getPhone(subId);
9296 if (phone == null) {
9297 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9298 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9299 }
9300 return phone.getEmergencyNumberDbVersion();
9301 } finally {
9302 Binder.restoreCallingIdentity(identity);
9303 }
9304 }
9305
9306 @Override
9307 public void notifyOtaEmergencyNumberDbInstalled() {
9308 enforceModifyPermission();
9309
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 for (Phone phone: PhoneFactory.getPhones()) {
9313 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9314 if (tracker != null) {
9315 tracker.updateOtaEmergencyNumberDatabase();
9316 }
9317 }
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
9323 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009324 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009325 enforceActiveEmergencySessionPermission();
9326
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 for (Phone phone: PhoneFactory.getPhones()) {
9330 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9331 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009332 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9333 }
9334 }
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 }
9339
9340 @Override
9341 public void resetOtaEmergencyNumberDbFilePath() {
9342 enforceActiveEmergencySessionPermission();
9343
9344 final long identity = Binder.clearCallingIdentity();
9345 try {
9346 for (Phone phone: PhoneFactory.getPhones()) {
9347 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9348 if (tracker != null) {
9349 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009350 }
9351 }
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
9356
9357 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009358 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9359 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9360 Phone phone = getPhone(subId);
9361 if (phone == null) {
9362 return null;
9363 }
9364 final long identity = Binder.clearCallingIdentity();
9365 try {
9366 UiccProfile profile = UiccController.getInstance()
9367 .getUiccProfileForPhone(phone.getPhoneId());
9368 if (profile != null) {
9369 return profile.getCertsFromCarrierPrivilegeAccessRules();
9370 }
9371 } finally {
9372 Binder.restoreCallingIdentity(identity);
9373 }
9374 return null;
9375 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009376
9377 /**
9378 * Enable or disable a modem stack.
9379 */
9380 @Override
9381 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9382 enforceModifyPermission();
9383
9384 final long identity = Binder.clearCallingIdentity();
9385 try {
9386 Phone phone = PhoneFactory.getPhone(slotIndex);
9387 if (phone == null) {
9388 return false;
9389 } else {
9390 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9391 }
9392 } finally {
9393 Binder.restoreCallingIdentity(identity);
9394 }
9395 }
Michelecea4cf22018-12-21 15:00:11 -08009396
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009397 /**
9398 * Whether a modem stack is enabled or not.
9399 */
9400 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009401 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9402 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009403 Phone phone = PhoneFactory.getPhone(slotIndex);
9404 if (phone == null) return false;
9405
9406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009407 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9408 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009409 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9410 }
9411
9412 final long identity = Binder.clearCallingIdentity();
9413 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009414 try {
9415 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9416 } catch (NoSuchElementException ex) {
9417 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9418 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009419 } finally {
9420 Binder.restoreCallingIdentity(identity);
9421 }
9422 }
9423
Michelecea4cf22018-12-21 15:00:11 -08009424 @Override
Michele0ea7d782019-03-19 14:58:42 -07009425 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009426 enforceModifyPermission();
9427
9428 final long identity = Binder.clearCallingIdentity();
9429 try {
9430 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009431 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009432 .commit();
9433 } finally {
9434 Binder.restoreCallingIdentity(identity);
9435 }
9436 }
9437
9438 @Override
Michele0ea7d782019-03-19 14:58:42 -07009439 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009440 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009442 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9443 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009444 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009445 }
Michelecea4cf22018-12-21 15:00:11 -08009446
9447 final long identity = Binder.clearCallingIdentity();
9448 try {
Michele0ea7d782019-03-19 14:58:42 -07009449 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009454
Michele0ea7d782019-03-19 14:58:42 -07009455 @TelephonyManager.IsMultiSimSupportedResult
9456 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009457 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9458 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9459 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009460 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9461 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009462 }
9463 // Check if the hardware supports multisim functionality. If usage of multisim is not
9464 // supported by the modem, indicate that it is restricted.
9465 PhoneCapability staticCapability =
9466 mPhoneConfigurationManager.getStaticPhoneCapability();
9467 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009468 loge("isMultiSimSupportedInternal: no static configuration available");
9469 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009470 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009471 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009472 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9473 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009474 }
9475 // Check if support of multiple SIMs is restricted by carrier
9476 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009477 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009478 }
9479
Michele0ea7d782019-03-19 14:58:42 -07009480 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009481 }
9482
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009483 /**
9484 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009485 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9486 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9487 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009488 * @param numOfSims number of active sims we want to switch to
9489 */
9490 @Override
9491 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009492 if (numOfSims == 1) {
9493 enforceModifyPermission();
9494 } else {
9495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9496 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9497 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009498 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009499
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009500 try {
Michele30b57b22019-03-01 12:01:14 -08009501 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009502 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009503 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9504 return;
9505 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009506 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 }
9511
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009512 @Override
9513 public boolean isApplicationOnUicc(int subId, int appType) {
9514 enforceReadPrivilegedPermission("isApplicationOnUicc");
9515 Phone phone = getPhone(subId);
9516 if (phone == null) {
9517 return false;
9518 }
9519 final long identity = Binder.clearCallingIdentity();
9520 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009521 UiccPort uiccPort = phone.getUiccPort();
9522 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009523 return false;
9524 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009525 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009526 if (uiccProfile == null) {
9527 return false;
9528 }
9529 if (TelephonyManager.APPTYPE_SIM <= appType
9530 && appType <= TelephonyManager.APPTYPE_ISIM) {
9531 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9532 }
9533 return false;
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
9536 }
9537 }
9538
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009539 /**
chen xub4baa772019-04-03 10:23:41 -07009540 * Get whether making changes to modem configurations will trigger reboot.
9541 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009542 */
9543 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009544 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9545 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009547 mApp, subId, callingPackage, callingFeatureId,
9548 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009549 return false;
9550 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009551 final long identity = Binder.clearCallingIdentity();
9552 try {
9553 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9554 } finally {
9555 Binder.restoreCallingIdentity(identity);
9556 }
9557 }
9558
Nathan Harold29f5f052019-02-15 13:41:57 -08009559 private void updateModemStateMetrics() {
9560 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9561 // TODO: check the state for each modem if the api is ready.
9562 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9563 }
9564
Pengquan Meng3889a572019-01-23 11:16:29 -08009565 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009566 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009567 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009568 // Verify that the callingPackage belongs to the calling UID
9569 mApp.getSystemService(AppOpsManager.class)
9570 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009571 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009572 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009573 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009574 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9575 if (slotInfos != null) {
9576 for (int i = 0; i < slotInfos.length; i++) {
9577 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9578 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9579 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9580 portInfo.getLogicalSlotIndex()));
9581 }
9582 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009583 }
9584 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009585 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009590
9591 /**
9592 * Get the IRadio HAL Version
9593 */
9594 @Override
9595 public int getRadioHalVersion() {
9596 Phone phone = getDefaultPhone();
9597 if (phone == null) return -1;
9598 HalVersion hv = phone.getHalVersion();
9599 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9600 return hv.major * 100 + hv.minor;
9601 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009602
9603 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009604 * Get the current calling package name.
9605 * @return the current calling package name
9606 */
9607 @Override
9608 public String getCurrentPackageName() {
9609 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9610 }
9611
9612 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009613 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9614 * corresponding network requests on a subId.
9615 *
9616 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009617 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009618 * 2) APN is un-metered for this subscription, or
9619 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009620 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009621 *
9622 * @return whether data is allowed for a apn type.
9623 *
9624 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009625 */
9626 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009627 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009628 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9629 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009630
9631 // Now that all security checks passes, perform the operation as ourselves.
9632 final long identity = Binder.clearCallingIdentity();
9633 try {
9634 Phone phone = getPhone(subId);
9635 if (phone == null) return false;
9636
Jack Yu41407ee2019-05-13 16:54:09 -07009637 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009638 boolean isDataEnabled;
9639 if (phone.isUsingNewDataStack()) {
9640 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9641 } else {
9642 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9643 }
9644 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009645 } finally {
9646 Binder.restoreCallingIdentity(identity);
9647 }
9648 }
9649
9650 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009651 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009652 enforceReadPrivilegedPermission("isApnMetered");
9653
9654 // Now that all security checks passes, perform the operation as ourselves.
9655 final long identity = Binder.clearCallingIdentity();
9656 try {
9657 Phone phone = getPhone(subId);
9658 if (phone == null) return true; // By default return true.
9659
Jack Yu41407ee2019-05-13 16:54:09 -07009660 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009661 } finally {
9662 Binder.restoreCallingIdentity(identity);
9663 }
9664 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009665
9666 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009667 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9668 int subscriptionId, IBooleanConsumer resultCallback) {
9669 enforceModifyPermission();
9670 long token = Binder.clearCallingIdentity();
9671 try {
9672 Phone phone = getPhone(subscriptionId);
9673 if (phone == null) {
9674 try {
9675 if (resultCallback != null) {
9676 resultCallback.accept(false);
9677 }
9678 } catch (RemoteException e) {
9679 // ignore
9680 }
9681 return;
9682 }
9683 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9684 Pair.create(specifiers, (x) -> {
9685 try {
9686 if (resultCallback != null) {
9687 resultCallback.accept(x);
9688 }
9689 } catch (RemoteException e) {
9690 // ignore
9691 }
9692 });
9693 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9694 } finally {
9695 Binder.restoreCallingIdentity(token);
9696 }
9697 }
9698
9699 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009700 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9701 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009702 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009703 mApp, subId, "getSystemSelectionChannels");
9704 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9705 final long identity = Binder.clearCallingIdentity();
9706 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009707 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9708 if (result instanceof IllegalStateException) {
9709 throw (IllegalStateException) result;
9710 }
9711 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009712 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9713 return specifiers;
9714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
9719 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009720 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009721 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009722 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9723 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9724 if (iccRecords == null) {
9725 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9726 return false;
9727 }
9728 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9729 }
9730
9731 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009732 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9733 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009734 if (callingPackage == null) {
9735 callingPackage = getCurrentPackageName();
9736 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009737 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9738 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009739 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9740 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009741 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9742 }
9743 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9744 Intent intent = new Intent();
9745 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9746 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9747 // Bring up choose default SMS subscription dialog right now
9748 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9749 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9750 mApp.startActivity(intent);
9751 }
chen xud5ca2d52019-05-28 15:20:57 -07009752
9753 @Override
9754 public String getMmsUAProfUrl(int subId) {
9755 //TODO investigate if this API should require proper permission check in R b/133791609
9756 final long identity = Binder.clearCallingIdentity();
9757 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009758 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9759 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9760 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9761 return carrierUAProfUrl;
9762 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009763 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9764 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009765 } finally {
9766 Binder.restoreCallingIdentity(identity);
9767 }
9768 }
9769
9770 @Override
9771 public String getMmsUserAgent(int subId) {
9772 //TODO investigate if this API should require proper permission check in R b/133791609
9773 final long identity = Binder.clearCallingIdentity();
9774 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009775 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9776 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9777 if (!TextUtils.isEmpty(carrierUserAgent)) {
9778 return carrierUserAgent;
9779 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009780 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9781 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
Jack Yub07d4972019-05-28 16:12:25 -07009786
9787 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009788 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9789 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009790
Jack Yub07d4972019-05-28 16:12:25 -07009791 final long identity = Binder.clearCallingIdentity();
9792 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009793 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009794 if (phone == null) return false;
9795
Hall Liua62f5da2020-09-25 10:42:19 -07009796 switch (policy) {
9797 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009798 if (phone.isUsingNewDataStack()) {
9799 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9800 } else {
9801 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9802 }
Hall Liua62f5da2020-09-25 10:42:19 -07009803 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009804 if (phone.isUsingNewDataStack()) {
9805 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9806 } else {
9807 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9808 }
Hall Liua62f5da2020-09-25 10:42:19 -07009809 default:
9810 throw new IllegalArgumentException(policy + " is not a valid policy");
9811 }
Jack Yub07d4972019-05-28 16:12:25 -07009812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 }
9816
9817 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009818 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009819 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009820 enforceModifyPermission();
9821
changbettyd5c246e2019-12-24 15:40:37 +08009822 final long identity = Binder.clearCallingIdentity();
9823 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009824 Phone phone = getPhone(subscriptionId);
9825 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009826
Hall Liua62f5da2020-09-25 10:42:19 -07009827 switch (policy) {
9828 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009829 if (phone.isUsingNewDataStack()) {
9830 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9831 } else {
9832 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9833 }
Hall Liua62f5da2020-09-25 10:42:19 -07009834 break;
9835 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009836 if (phone.isUsingNewDataStack()) {
9837 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9838 } else {
9839 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9840 }
Hall Liua62f5da2020-09-25 10:42:19 -07009841 break;
9842 default:
9843 throw new IllegalArgumentException(policy + " is not a valid policy");
9844 }
changbettyd5c246e2019-12-24 15:40:37 +08009845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
9849
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009850 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009851 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009852 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9853 * otherwise.
9854 */
9855 @Override
9856 public void setCepEnabled(boolean isCepEnabled) {
9857 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9858
9859 final long identity = Binder.clearCallingIdentity();
9860 try {
9861 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9862 for (Phone phone : PhoneFactory.getPhones()) {
9863 Phone defaultPhone = phone.getImsPhone();
9864 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9865 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9866 ImsPhoneCallTracker imsPhoneCallTracker =
9867 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9868 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9869 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9870 + imsPhone.getMsisdn());
9871 }
9872 }
9873 } finally {
9874 Binder.restoreCallingIdentity(identity);
9875 }
9876 }
allenwtsu46dcc572020-01-08 18:24:03 +08009877
9878 /**
9879 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9880 *
9881 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9882 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9883 * before being read.
9884 */
9885 @Override
9886 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9887 isCompressed) {
9888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9889 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9891 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9892 }
9893 if (!isImsAvailableOnDevice()) {
9894 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9895 "IMS not available on device.");
9896 }
9897
9898 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009899 try {
Hui Wang761a6682020-10-31 05:12:53 +00009900 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9901 } finally {
9902 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009903 }
9904 }
zoey chene02881a2019-12-30 16:11:23 +08009905
9906 @Override
9907 public boolean isIccLockEnabled(int subId) {
9908 enforceReadPrivilegedPermission("isIccLockEnabled");
9909
9910 // Now that all security checks passes, perform the operation as ourselves.
9911 final long identity = Binder.clearCallingIdentity();
9912 try {
9913 Phone phone = getPhone(subId);
9914 if (phone != null && phone.getIccCard() != null) {
9915 return phone.getIccCard().getIccLockEnabled();
9916 } else {
9917 return false;
9918 }
9919 } finally {
9920 Binder.restoreCallingIdentity(identity);
9921 }
9922 }
9923
9924 /**
9925 * Set the ICC pin lock enabled or disabled.
9926 *
9927 * @return an integer representing the status of IccLock enabled or disabled in the following
9928 * three cases:
9929 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9930 * successfully.
9931 * - Positive number and zero for remaining password attempts.
9932 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9933 *
9934 */
9935 @Override
9936 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9937 enforceModifyPermission();
9938
9939 Phone phone = getPhone(subId);
9940 if (phone == null) {
9941 return 0;
9942 }
9943 // Now that all security checks passes, perform the operation as ourselves.
9944 final long identity = Binder.clearCallingIdentity();
9945 try {
9946 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9947 new Pair<Boolean, String>(enabled, password), phone, null);
9948 return attemptsRemaining;
9949
9950 } catch (Exception e) {
9951 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9952 } finally {
9953 Binder.restoreCallingIdentity(identity);
9954 }
9955 return 0;
9956 }
9957
9958 /**
9959 * Change the ICC password used in ICC pin lock.
9960 *
9961 * @return an integer representing the status of IccLock changed in the following three cases:
9962 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9963 * - Positive number and zero for remaining password attempts.
9964 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9965 *
9966 */
9967 @Override
9968 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9969 enforceModifyPermission();
9970
9971 Phone phone = getPhone(subId);
9972 if (phone == null) {
9973 return 0;
9974 }
9975 // Now that all security checks passes, perform the operation as ourselves.
9976 final long identity = Binder.clearCallingIdentity();
9977 try {
9978 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9979 new Pair<String, String>(oldPassword, newPassword), phone, null);
9980 return attemptsRemaining;
9981
9982 } catch (Exception e) {
9983 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9984 } finally {
9985 Binder.restoreCallingIdentity(identity);
9986 }
9987 return 0;
9988 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009989
9990 /**
9991 * Request for receiving user activity notification
9992 */
9993 @Override
9994 public void requestUserActivityNotification() {
9995 if (!mNotifyUserActivity.get()
9996 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9997 mNotifyUserActivity.set(true);
9998 }
9999 }
10000
10001 /**
10002 * Called when userActivity is signalled in the power manager.
10003 * This is safe to call from any thread, with any window manager locks held or not.
10004 */
10005 @Override
10006 public void userActivity() {
10007 // ***************************************
10008 // * Inherited from PhoneWindowManager *
10009 // ***************************************
10010 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10011 // WITH ITS LOCKS HELD.
10012 //
10013 // This code must be VERY careful about the locks
10014 // it acquires.
10015 // In fact, the current code acquires way too many,
10016 // and probably has lurking deadlocks.
10017
10018 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10019 throw new SecurityException("Only the OS may call notifyUserActivity()");
10020 }
10021
10022 if (mNotifyUserActivity.getAndSet(false)) {
10023 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10024 USER_ACTIVITY_NOTIFICATION_DELAY);
10025 }
10026 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010027
10028 @Override
10029 public boolean canConnectTo5GInDsdsMode() {
10030 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10031 }
Jack Yud10cdd42020-09-28 20:28:01 -070010032
10033 @Override
10034 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10035 String callingFeatureId) {
10036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10037 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10038 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10039 }
10040
10041 Phone phone = getPhone(subId);
10042 if (phone == null) {
10043 throw new RuntimeException("phone is not available");
10044 }
10045 // Now that all security checks passes, perform the operation as ourselves.
10046 final long identity = Binder.clearCallingIdentity();
10047 try {
10048 return phone.getEquivalentHomePlmns();
10049 } finally {
10050 Binder.restoreCallingIdentity(identity);
10051 }
10052 }
Daniel Bright59e67312020-11-13 11:49:37 -080010053
10054 @Override
10055 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010056 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10057 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010058 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010059 if (radioInterfaceCapabilities == null) {
10060 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010061 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010062 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010063 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010064
Hui Wang641e81c2020-10-12 12:14:23 -070010065 @Override
10066 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10067 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010068 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10069 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10070 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10071 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10072 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010073 if (DBG) {
10074 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10075 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10076 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10077 }
10078
10079 if (!SubscriptionManager.isValidSubscriptionId(subId)
10080 || appType < TelephonyManager.APPTYPE_UNKNOWN
10081 || appType > TelephonyManager.APPTYPE_ISIM
10082 || nafUrl == null || securityProtocol == null || callback == null) {
10083 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10084 if (callback != null) {
10085 try {
10086 callback.onAuthenticationFailure(
10087 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10088 } catch (RemoteException exception) {
10089 log("Fail to notify onAuthenticationFailure due to " + exception);
10090 }
10091 return;
10092 }
10093 }
10094
10095 final long token = Binder.clearCallingIdentity();
10096 try {
10097 getGbaManager(subId).bootstrapAuthenticationRequest(
10098 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10099 forceBootStrapping, callback));
10100 } finally {
10101 Binder.restoreCallingIdentity(token);
10102 }
10103 }
10104
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010105 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010106 * Attempts to set the radio power state for all phones for thermal reason.
10107 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010108 * requested radio power state will actually be set. See {@link
10109 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10110 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010111 * @param enable {@code true} if trying to turn radio on.
10112 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10113 * false}.
10114 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010115 private boolean setRadioPowerForThermal(boolean enable) {
10116 boolean isPhoneAvailable = false;
10117 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10118 Phone phone = PhoneFactory.getPhone(i);
10119 if (phone != null) {
10120 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10121 isPhoneAvailable = true;
10122 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010123 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010124
10125 // return true if successfully informed the phone object about the thermal radio power
10126 // request.
10127 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010128 }
10129
10130 private int handleDataThrottlingRequest(int subId,
10131 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010132 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10133 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10134 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10135 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10136 throw new IllegalArgumentException("modem does not support data throttling");
10137 }
10138
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010139 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10140 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010141 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010142 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10143 }
10144
10145 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10146
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010147 if (isDataThrottlingSupported) {
10148 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010149 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010150 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10151 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10152 } else if (thermalMitigationResult
10153 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010154 log("Modem likely does not support data throttling on secondary carrier. Data " +
10155 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10156 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010157 }
10158 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010159 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010160
10161 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010162 }
10163
Jack Nudelman644b91a2021-03-12 14:09:48 -080010164 private static List<String> getThermalMitigationAllowlist(Context context) {
10165 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10166 for (String pckg : context.getResources()
10167 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10168 sThermalMitigationAllowlistedPackages.add(pckg);
10169 }
10170 }
10171
10172 return sThermalMitigationAllowlistedPackages;
10173 }
10174
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010175 private boolean isAnyPhoneInEmergencyState() {
10176 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10177 if (tm.isInEmergencyCall()) {
10178 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10179 return true;
10180 }
10181 for (Phone phone : PhoneFactory.getPhones()) {
10182 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10183 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10184 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10185 + phone.isInEcm());
10186 return true;
10187 }
10188 }
10189
10190 return false;
10191 }
10192
Jack Nudelman644b91a2021-03-12 14:09:48 -080010193 /**
10194 * Used by shell commands to add an authorized package name for thermal mitigation.
10195 * @param packageName name of package to be allowlisted
10196 * @param context
10197 */
10198 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10199 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10200 sThermalMitigationAllowlistedPackages.add(packageName);
10201 }
10202
10203 /**
10204 * Used by shell commands to remove an authorized package name for thermal mitigation.
10205 * @param packageName name of package to remove from allowlist
10206 * @param context
10207 */
10208 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10209 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10210 sThermalMitigationAllowlistedPackages.remove(packageName);
10211 }
10212
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010213 /**
10214 * Thermal mitigation request to control functionalities at modem.
10215 *
10216 * @param subId the id of the subscription.
10217 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010218 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010219 *
10220 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10221 */
10222 @Override
10223 @ThermalMitigationResult
10224 public int sendThermalMitigationRequest(
10225 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010226 ThermalMitigationRequest thermalMitigationRequest,
10227 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010228 enforceModifyPermission();
10229
Jack Nudelman644b91a2021-03-12 14:09:48 -080010230 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10231 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10232 .contains(callingPackage)) {
10233 throw new SecurityException("Calling package must be configured in the device config. "
10234 + "calling package: " + callingPackage);
10235 }
10236
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010237 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10238 final long identity = Binder.clearCallingIdentity();
10239
10240 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10241 try {
10242 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10243 switch (thermalMitigationAction) {
10244 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10245 thermalMitigationResult =
10246 handleDataThrottlingRequest(subId,
10247 thermalMitigationRequest.getDataThrottlingRequest());
10248 break;
10249 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10250 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10251 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10252 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10253 }
10254
10255 // Ensure that radio is on. If not able to power on due to phone being
10256 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010257 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010258 thermalMitigationResult =
10259 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10260 break;
10261 }
10262
10263 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10264 false);
10265 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10266 break;
10267 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10268 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10269 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10270 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10271 }
10272
10273 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10274 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010275 Phone phone = getPhone(subId);
10276 if (phone == null) {
10277 thermalMitigationResult =
10278 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10279 break;
10280 }
10281
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010282 TelephonyConnectionService service =
10283 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010284 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010285 Log.e(LOG_TAG, "An emergency call is pending");
10286 thermalMitigationResult =
10287 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10288 break;
10289 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010290 thermalMitigationResult =
10291 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10292 break;
10293 }
10294 } else {
10295 thermalMitigationResult =
10296 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10297 break;
10298 }
10299
10300 // Turn radio off. If not able to power off due to phone being unavailable,
10301 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010302 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010303 thermalMitigationResult =
10304 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10305 break;
10306 }
10307 thermalMitigationResult =
10308 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10309 break;
10310 default:
10311 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10312 + "not exist. Requested action: " + thermalMitigationAction);
10313 }
10314 } catch (IllegalArgumentException e) {
10315 throw e;
10316 } catch (Exception e) {
10317 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10318 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10319 } finally {
10320 Binder.restoreCallingIdentity(identity);
10321 }
10322
10323 if (DBG) {
10324 log("thermalMitigationRequest returning with thermalMitigationResult: "
10325 + thermalMitigationResult);
10326 }
10327
10328 return thermalMitigationResult;
10329 }
Hui Wang641e81c2020-10-12 12:14:23 -070010330
10331 /**
10332 * Set the GbaService Package Name that Telephony will bind to.
10333 *
10334 * @param subId The sim that the GbaService is associated with.
10335 * @param packageName The name of the package to be replaced with.
10336 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10337 */
10338 @Override
10339 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10340 enforceModifyPermission();
10341
10342 final long identity = Binder.clearCallingIdentity();
10343 try {
10344 return getGbaManager(subId).overrideServicePackage(packageName);
10345 } finally {
10346 Binder.restoreCallingIdentity(identity);
10347 }
10348 }
10349
10350 /**
10351 * Return the package name of the currently bound GbaService.
10352 *
10353 * @param subId The sim that the GbaService is associated with.
10354 * @return the package name of the GbaService configuration, null if GBA is not supported.
10355 */
10356 @Override
10357 public String getBoundGbaService(int subId) {
10358 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10359
10360 final long identity = Binder.clearCallingIdentity();
10361 try {
10362 return getGbaManager(subId).getServicePackage();
10363 } finally {
10364 Binder.restoreCallingIdentity(identity);
10365 }
10366 }
10367
10368 /**
10369 * Set the release time for telephony to unbind GbaService.
10370 *
10371 * @param subId The sim that the GbaService is associated with.
10372 * @param interval The release time to unbind GbaService by millisecond.
10373 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10374 */
10375 @Override
10376 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10377 enforceModifyPermission();
10378
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 return getGbaManager(subId).overrideReleaseTime(interval);
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 }
10386
10387 /**
10388 * Return the release time for telephony to unbind GbaService.
10389 *
10390 * @param subId The sim that the GbaService is associated with.
10391 * @return The release time to unbind GbaService by millisecond.
10392 */
10393 @Override
10394 public int getGbaReleaseTime(int subId) {
10395 enforceReadPrivilegedPermission("getGbaReleaseTime");
10396
10397 final long identity = Binder.clearCallingIdentity();
10398 try {
10399 return getGbaManager(subId).getReleaseTime();
10400 } finally {
10401 Binder.restoreCallingIdentity(identity);
10402 }
10403 }
10404
10405 private GbaManager getGbaManager(int subId) {
10406 GbaManager instance = GbaManager.getInstance(subId);
10407 if (instance == null) {
10408 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10409 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10410 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10411 }
10412 return instance;
10413 }
Hui Wang761a6682020-10-31 05:12:53 +000010414
10415 /**
10416 * indicate whether the device and the carrier can support
10417 * RCS VoLTE single registration.
10418 */
10419 @Override
10420 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010421 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10422 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10423 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10424 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010425
10426 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10427 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10428 }
10429
10430 final long identity = Binder.clearCallingIdentity();
10431 try {
10432 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10433 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010434 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10435 if (isCapable != null) {
10436 return isCapable;
10437 }
Hui Wang761a6682020-10-31 05:12:53 +000010438 }
Hui Wang67af90e2021-06-04 16:57:15 -070010439 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10440 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010441 } finally {
10442 Binder.restoreCallingIdentity(identity);
10443 }
10444 }
10445
10446 /**
10447 * Register RCS provisioning callback.
10448 */
10449 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010450 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010451 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010452 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010453 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010454 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10455 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010456
10457 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10458 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10459 }
10460 if (!isImsAvailableOnDevice()) {
10461 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10462 "IMS not available on device.");
10463 }
10464
10465 final long identity = Binder.clearCallingIdentity();
10466 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010467 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010468 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010469 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10470 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010471 }
Hui Wang761a6682020-10-31 05:12:53 +000010472 } finally {
10473 Binder.restoreCallingIdentity(identity);
10474 }
10475 }
10476
10477 /**
10478 * Unregister RCS provisioning callback.
10479 */
10480 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010481 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010482 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010483 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010484 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010485 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10486 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010487
10488 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10489 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10490 }
10491 if (!isImsAvailableOnDevice()) {
10492 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10493 "IMS not available on device.");
10494 }
10495
10496 final long identity = Binder.clearCallingIdentity();
10497 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010498 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010499 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010500 } finally {
10501 Binder.restoreCallingIdentity(identity);
10502 }
10503 }
10504
10505 /**
10506 * trigger RCS reconfiguration.
10507 */
10508 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010509 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10510 "triggerRcsReconfiguration",
10511 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010512
10513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10514 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10515 }
10516 if (!isImsAvailableOnDevice()) {
10517 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10518 "IMS not available on device.");
10519 }
10520
10521 final long identity = Binder.clearCallingIdentity();
10522 try {
10523 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10524 } finally {
10525 Binder.restoreCallingIdentity(identity);
10526 }
10527 }
10528
10529 /**
10530 * Provide the client configuration parameters of the RCS application.
10531 */
10532 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010533 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10534 "setRcsClientConfiguration",
10535 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010536
10537 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10538 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10539 }
10540 if (!isImsAvailableOnDevice()) {
10541 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10542 "IMS not available on device.");
10543 }
10544
10545 final long identity = Binder.clearCallingIdentity();
10546
10547 try {
10548 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10549 if (configBinder == null) {
10550 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010551 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10552 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010553 } else {
10554 configBinder.setRcsClientConfiguration(rcc);
10555 }
joonhunshinfa314642021-09-17 06:33:39 +000010556
10557 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10558 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010559 } catch (RemoteException e) {
10560 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010561 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10562 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
10568 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010569 * Enables or disables the test mode for RCS VoLTE single registration.
10570 */
10571 @Override
10572 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10573 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10574 "setRcsSingleRegistrationTestModeEnabled");
10575
10576 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10577 }
10578
10579 /**
10580 * Gets the test mode for RCS VoLTE single registration.
10581 */
10582 @Override
10583 public boolean getRcsSingleRegistrationTestModeEnabled() {
10584 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10585 "getRcsSingleRegistrationTestModeEnabled");
10586
10587 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10588 }
10589
10590 /**
Hui Wang761a6682020-10-31 05:12:53 +000010591 * Overrides the config of RCS VoLTE single registration enabled for the device.
10592 */
10593 @Override
10594 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10595 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10596 "setDeviceSingleRegistrationEnabledOverride");
10597 enforceModifyPermission();
10598
10599 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10600 : Boolean.parseBoolean(enabledStr);
10601 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010602 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010603 }
10604
10605 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010606 * Sends a device to device communication message. Only usable via shell.
10607 * @param message message to send.
10608 * @param value message value.
10609 */
10610 @Override
10611 public void sendDeviceToDeviceMessage(int message, int value) {
10612 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010613 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010614 enforceModifyPermission();
10615
10616 final long identity = Binder.clearCallingIdentity();
10617 try {
10618 TelephonyConnectionService service =
10619 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10620 if (service == null) {
10621 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10622 return;
10623 }
10624 service.sendTestDeviceToDeviceMessage(message, value);
10625 } finally {
10626 Binder.restoreCallingIdentity(identity);
10627 }
10628 }
10629
Tyler Gunnbabbda02021-02-10 11:05:02 -080010630 /**
10631 * Sets the specified device to device transport active.
10632 * @param transport The transport to set active.
10633 */
10634 @Override
10635 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10637 "setActiveDeviceToDeviceTransport");
10638 enforceModifyPermission();
10639
10640 final long identity = Binder.clearCallingIdentity();
10641 try {
10642 TelephonyConnectionService service =
10643 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10644 if (service == null) {
10645 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10646 return;
10647 }
10648 service.setActiveDeviceToDeviceTransport(transport);
10649 } finally {
10650 Binder.restoreCallingIdentity(identity);
10651 }
10652 }
Tyler Gunn92479152021-01-20 16:30:10 -080010653
Tyler Gunnd4575212021-05-03 14:46:49 -070010654 @Override
10655 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10657 "setDeviceToDeviceForceEnabled");
10658
10659 final long identity = Binder.clearCallingIdentity();
10660 try {
10661 Arrays.stream(PhoneFactory.getPhones()).forEach(
10662 p -> {
10663 Phone thePhone = p.getImsPhone();
10664 if (thePhone != null && thePhone instanceof ImsPhone) {
10665 ImsPhone imsPhone = (ImsPhone) thePhone;
10666 CallTracker tracker = imsPhone.getCallTracker();
10667 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10668 ImsPhoneCallTracker imsPhoneCallTracker =
10669 (ImsPhoneCallTracker) tracker;
10670 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10671 }
10672 }
10673 }
10674 );
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
10679
Tyler Gunn92479152021-01-20 16:30:10 -080010680 /**
Hui Wang761a6682020-10-31 05:12:53 +000010681 * Gets the config of RCS VoLTE single registration enabled for the device.
10682 */
10683 @Override
10684 public boolean getDeviceSingleRegistrationEnabled() {
10685 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10686 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10687 }
10688
10689 /**
10690 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10691 */
10692 @Override
10693 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10695 "setCarrierSingleRegistrationEnabledOverride");
10696 enforceModifyPermission();
10697
10698 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10699 : Boolean.parseBoolean(enabledStr);
10700 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10701 subId, enabled);
10702 }
10703
10704 /**
10705 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10706 */
10707 @Override
10708 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10709 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10710 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10711 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010712
10713 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010714 * Overrides the ims feature validation result
10715 */
10716 @Override
10717 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10719 "setImsFeatureValidationOverride");
10720
10721 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10722 : Boolean.parseBoolean(enabledStr);
10723 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10724 subId, enabled);
10725 }
10726
10727 /**
10728 * Gets the ims feature validation override value
10729 */
10730 @Override
10731 public boolean getImsFeatureValidationOverride(int subId) {
10732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10733 "getImsFeatureValidationOverride");
10734 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10735 }
10736
10737 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010738 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10739 * their mobile plan.
10740 */
10741 @Override
10742 public String getMobileProvisioningUrl() {
10743 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10744 final long identity = Binder.clearCallingIdentity();
10745 try {
10746 return getDefaultPhone().getMobileProvisioningUrl();
10747 } finally {
10748 Binder.restoreCallingIdentity(identity);
10749 }
10750 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010751
James.cf Linbcdf8b32021-01-14 16:44:13 +080010752 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010753 * Get the EAB contact from the EAB database.
10754 */
10755 @Override
10756 public String getContactFromEab(String contact) {
10757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10758 enforceModifyPermission();
10759 final long identity = Binder.clearCallingIdentity();
10760 try {
10761 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10762 } finally {
10763 Binder.restoreCallingIdentity(identity);
10764 }
10765 }
10766
10767 /**
Calvin Pana1434322021-07-01 19:27:01 +080010768 * Get the EAB capability from the EAB database.
10769 */
10770 @Override
10771 public String getCapabilityFromEab(String contact) {
10772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10773 enforceModifyPermission();
10774 final long identity = Binder.clearCallingIdentity();
10775 try {
10776 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10777 } finally {
10778 Binder.restoreCallingIdentity(identity);
10779 }
10780 }
10781
10782 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010783 * Remove the EAB contacts from the EAB database.
10784 */
10785 @Override
10786 public int removeContactFromEab(int subId, String contacts) {
10787 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10788 enforceModifyPermission();
10789 final long identity = Binder.clearCallingIdentity();
10790 try {
10791 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10792 } finally {
10793 Binder.restoreCallingIdentity(identity);
10794 }
10795 }
10796
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010797 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010798 public boolean getDeviceUceEnabled() {
10799 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10800 final long identity = Binder.clearCallingIdentity();
10801 try {
10802 return mApp.getDeviceUceEnabled();
10803 } finally {
10804 Binder.restoreCallingIdentity(identity);
10805 }
10806 }
10807
10808 @Override
10809 public void setDeviceUceEnabled(boolean isEnabled) {
10810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10811 final long identity = Binder.clearCallingIdentity();
10812 try {
10813 mApp.setDeviceUceEnabled(isEnabled);
10814 } finally {
10815 Binder.restoreCallingIdentity(identity);
10816 }
10817 }
10818
Brad Ebinger14d467f2021-02-12 06:18:28 +000010819 /**
10820 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10821 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10822 */
10823 // Used for SHELL command only right now.
10824 @Override
10825 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10826 List<String> featureTags) {
10827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10828 "addUceRegistrationOverrideShell");
10829 final long identity = Binder.clearCallingIdentity();
10830 try {
10831 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10832 new ArraySet<>(featureTags));
10833 } catch (ImsException e) {
10834 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10835 } finally {
10836 Binder.restoreCallingIdentity(identity);
10837 }
10838 }
10839
10840 /**
10841 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10842 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10843 */
10844 // Used for SHELL command only right now.
10845 @Override
10846 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10847 List<String> featureTags) {
10848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10849 "removeUceRegistrationOverrideShell");
10850 final long identity = Binder.clearCallingIdentity();
10851 try {
10852 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10853 new ArraySet<>(featureTags));
10854 } catch (ImsException e) {
10855 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10856 } finally {
10857 Binder.restoreCallingIdentity(identity);
10858 }
10859 }
10860
10861 /**
10862 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10863 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10864 */
10865 // Used for SHELL command only right now.
10866 @Override
10867 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10868 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10869 "clearUceRegistrationOverrideShell");
10870 final long identity = Binder.clearCallingIdentity();
10871 try {
10872 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10873 } catch (ImsException e) {
10874 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10875 } finally {
10876 Binder.restoreCallingIdentity(identity);
10877 }
10878 }
10879
10880 /**
10881 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10882 */
10883 // Used for SHELL command only right now.
10884 @Override
10885 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10887 "getLatestRcsContactUceCapabilityShell");
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10891 } catch (ImsException e) {
10892 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10893 } finally {
10894 Binder.restoreCallingIdentity(identity);
10895 }
10896 }
10897
10898 /**
10899 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10900 * device does not have an active PUBLISH.
10901 */
10902 // Used for SHELL command only right now.
10903 @Override
10904 public String getLastUcePidfXmlShell(int subId) {
10905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10909 } catch (ImsException e) {
10910 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
10915
James.cf Line8713a42021-04-29 16:04:26 +080010916 /**
10917 * Remove UCE requests cannot be sent to the network status.
10918 */
10919 // Used for SHELL command only right now.
10920 @Override
10921 public boolean removeUceRequestDisallowedStatus(int subId) {
10922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10926 } catch (ImsException e) {
10927 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
10932
James.cf Lin0fc71b02021-05-25 01:37:38 +080010933 /**
10934 * Remove UCE requests cannot be sent to the network status.
10935 */
10936 // Used for SHELL command only.
10937 @Override
10938 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10939 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10940 final long identity = Binder.clearCallingIdentity();
10941 try {
10942 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10943 } catch (ImsException e) {
10944 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10945 } finally {
10946 Binder.restoreCallingIdentity(identity);
10947 }
10948 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010949
James.cf Lin4b784aa2021-01-31 03:25:15 +080010950 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010951 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10952 String callingPackage) {
10953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10954 mApp, subId, "setSignalStrengthUpdateRequest");
10955
10956 final int callingUid = Binder.getCallingUid();
10957 // Verify that tha callingPackage belongs to the calling UID
10958 mApp.getSystemService(AppOpsManager.class)
10959 .checkPackage(callingUid, callingPackage);
10960
Rambo Wang3607f502021-02-01 21:51:40 -080010961 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010962
10963 final long identity = Binder.clearCallingIdentity();
10964 try {
10965 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10966 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10967
10968 if (result instanceof IllegalStateException) {
10969 throw (IllegalStateException) result;
10970 }
10971 } finally {
10972 Binder.restoreCallingIdentity(identity);
10973 }
10974 }
10975
10976 @Override
10977 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10978 String callingPackage) {
10979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10980 mApp, subId, "clearSignalStrengthUpdateRequest");
10981
10982 final int callingUid = Binder.getCallingUid();
10983 // Verify that tha callingPackage belongs to the calling UID
10984 mApp.getSystemService(AppOpsManager.class)
10985 .checkPackage(callingUid, callingPackage);
10986
10987 final long identity = Binder.clearCallingIdentity();
10988 try {
10989 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10990 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10991
10992 if (result instanceof IllegalStateException) {
10993 throw (IllegalStateException) result;
10994 }
10995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
10999
Rambo Wang3607f502021-02-01 21:51:40 -080011000 private static void validateSignalStrengthUpdateRequest(Context context,
11001 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011002 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11003 // phone/system process do not have further restriction on request
11004 return;
11005 }
11006
11007 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011008 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011009 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011010 context.enforceCallingOrSelfPermission(
11011 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11012 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011013 }
11014
11015 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11016 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11017 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11018 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11019 || info.isEnabled()) {
11020 throw new IllegalArgumentException(
11021 "Only system can set hide fields in SignalThresholdInfo");
11022 }
11023
11024 // Thresholds length for each RAN need in range. This has been validated in
11025 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11026 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11027 final int[] thresholds = info.getThresholds();
11028 Objects.requireNonNull(thresholds);
11029 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11030 || thresholds.length
11031 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11032 throw new IllegalArgumentException(
11033 "thresholds length is out of range: " + thresholds.length);
11034 }
11035 }
11036 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011037
11038 /**
11039 * Gets the current phone capability.
11040 *
11041 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11042 * @return the PhoneCapability which describes the data connection capability of modem.
11043 * It's used to evaluate possible phone config change, for example from single
11044 * SIM device to multi-SIM device.
11045 */
11046 @Override
11047 public PhoneCapability getPhoneCapability() {
11048 enforceReadPrivilegedPermission("getPhoneCapability");
11049 final long identity = Binder.clearCallingIdentity();
11050 try {
11051 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
Michele Berionne5e411512020-11-13 02:36:59 +000011056
11057 /**
11058 * Prepare TelephonyManager for an unattended reboot. The reboot is
11059 * required to be done shortly after the API is invoked.
11060 */
11061 @Override
11062 @TelephonyManager.PrepareUnattendedRebootResult
11063 public int prepareForUnattendedReboot() {
11064 enforceRebootPermission();
11065
11066 final long identity = Binder.clearCallingIdentity();
11067 try {
11068 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11069 } finally {
11070 Binder.restoreCallingIdentity(identity);
11071 }
11072 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011073
11074 /**
11075 * Request to get the current slicing configuration including URSP rules and
11076 * NSSAIs (configured, allowed and rejected).
11077 *
11078 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11079 */
11080 @Override
11081 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011082 TelephonyPermissions
11083 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11084 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011085
11086 final long identity = Binder.clearCallingIdentity();
11087 try {
11088 Phone phone = getDefaultPhone();
11089 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011094
11095 /**
11096 * Register an IMS connection state callback
11097 */
11098 @Override
11099 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11100 String callingPackage) {
11101 if (feature == ImsFeature.FEATURE_MMTEL) {
11102 // ImsMmTelManager
11103 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11104 TelephonyPermissions
11105 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11106 mApp, subId, "registerImsStateCallback");
11107 } else if (feature == ImsFeature.FEATURE_RCS) {
11108 // ImsRcsManager or SipDelegateManager
11109 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11110 Binder.getCallingUid(), "registerImsStateCallback",
11111 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11112 Manifest.permission.READ_PRECISE_PHONE_STATE,
11113 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11114 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11115 }
11116
11117 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11118 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11119 "IMS not available on device.");
11120 }
11121
11122 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11123 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11124 }
11125
11126 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11127 if (controller == null) {
11128 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11129 "IMS not available on device.");
11130 }
11131
11132 if (callingPackage == null) {
11133 callingPackage = getCurrentPackageName();
11134 }
11135
11136 final long token = Binder.clearCallingIdentity();
11137 try {
11138 int slotId = getSlotIndexOrException(subId);
11139 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11140 } catch (ImsException e) {
11141 throw new ServiceSpecificException(e.getCode());
11142 } finally {
11143 Binder.restoreCallingIdentity(token);
11144 }
11145 }
11146
11147 /**
11148 * Unregister an IMS connection state callback
11149 */
11150 @Override
11151 public void unregisterImsStateCallback(IImsStateCallback cb) {
11152 final long token = Binder.clearCallingIdentity();
11153 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11154 if (controller == null) {
11155 return;
11156 }
11157 try {
11158 controller.unregisterImsStateCallback(cb);
11159 } finally {
11160 Binder.restoreCallingIdentity(token);
11161 }
11162 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011163
11164 /**
11165 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11166 *
11167 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11168 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11169 * SecurityException.
11170 * If there is current registered network this value will be same as the registered cell
11171 * identity. If the device goes out of service the previous cell identity is cached and
11172 * will be returned. If the cache age of the Cell identity is more than 24 hours
11173 * it will be cleared and null will be returned.
11174 *
11175 */
11176 @Override
11177 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11178 String callingFeatureId) {
11179 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11180 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11181 LocationAccessPolicy.checkLocationPermission(mApp,
11182 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11183 .setCallingPackage(callingPackage)
11184 .setCallingFeatureId(callingFeatureId)
11185 .setCallingPid(Binder.getCallingPid())
11186 .setCallingUid(Binder.getCallingUid())
11187 .setMethod("getLastKnownCellIdentity")
11188 .setLogAsInfo(true)
11189 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11190 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11191 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11192 .build());
11193
11194 boolean hasFinePermission =
11195 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11196 if (!hasFinePermission
11197 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11198 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11199 + "and BIND_CONNECTION_SERVICE permission.");
11200 }
11201
11202 final long identity = Binder.clearCallingIdentity();
11203 try {
11204 Phone phone = getPhone(subId);
11205 if (phone == null) return null;
11206 ServiceStateTracker sst = phone.getServiceStateTracker();
11207 if (sst == null) return null;
11208 return sst.getLastKnownCellIdentity();
11209 } finally {
11210 Binder.restoreCallingIdentity(identity);
11211 }
11212 }
jimsun38340bf2021-10-26 15:01:23 +080011213
11214 /**
11215 * Sets the modem service class Name that Telephony will bind to.
11216 *
11217 * @param serviceName The class name of the modem service.
11218 * @return true if the operation is succeed, otherwise false.
11219 */
11220 public boolean setModemService(String serviceName) {
11221 Log.d(LOG_TAG, "setModemService - " + serviceName);
11222 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11224 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11225 "setModemService");
11226 return mPhoneConfigurationManager.setModemService(serviceName);
11227 }
11228
11229 /**
11230 * Return the class name of the currently bounded modem service.
11231 *
11232 * @return the class name of the modem service.
11233 */
11234 public String getModemService() {
11235 String result;
11236 Log.d(LOG_TAG, "getModemService");
11237 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11238 TelephonyPermissions
11239 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11240 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11241 "getModemService");
11242 result = mPhoneConfigurationManager.getModemService();
11243 Log.d(LOG_TAG, "result = " + result);
11244 return result;
11245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011246}