blob: 5003247717203a20bcb13b8517024f9634e61f92 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000036import android.compat.annotation.ChangeId;
37import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070038import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070039import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.content.Context;
41import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070043import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080044import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070075import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080076import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080077import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070078import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080079import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070080import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080081import android.telephony.CellIdentityCdma;
82import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070084import android.telephony.CellInfoGsm;
85import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070086import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070088import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070089import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070090import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080091import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070094import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080095import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080096import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800100import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800101import android.telephony.SignalStrengthUpdateRequest;
102import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800103import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800105import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800110import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000113import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700114import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800116import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800117import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800118import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700119import android.telephony.gba.GbaAuthRequest;
120import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700121import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000124import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700125import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700126import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800127import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700128import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700132import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800134import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800136import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700139import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800141import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Andrew Lee312e8172014-10-23 17:01:36 -0700143import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800144import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800145import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800146import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700149import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700150import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800151import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700156import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800157import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800158import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800159import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700160import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000161import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800163import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700166import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700167import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700170import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800171import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700172import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700173import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700174import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700175import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800176import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800177import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700178import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700179import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700180import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800181import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800182import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700184import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700186import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800187import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700188import com.android.internal.telephony.imsphone.ImsPhone;
189import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000190import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800191import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700192import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700193import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800194import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800196import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700197import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000200import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800201import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000202import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800203import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700204import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700205import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800206import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800207import com.android.phone.callcomposer.CallComposerPictureManager;
208import com.android.phone.callcomposer.CallComposerPictureTransfer;
209import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700210import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700211import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800212import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700214import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800215import com.android.services.telephony.TelecomAccountRegistry;
216import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800217import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800218
Hall Liu82694d52020-12-11 18:22:04 -0800219import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700220import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.IOException;
222import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800225import java.util.Arrays;
sandeepjsb6c87872021-09-27 15:34:44 +0000226import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800227import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800228import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800229import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100230import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800231import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700232import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800233import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800234import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800236import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800237import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239/**
240 * Implementation of the ITelephony interface.
241 */
Santos Cordon117fee72014-05-16 17:56:12 -0700242public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 private static final String LOG_TAG = "PhoneInterfaceManager";
244 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
245 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800246 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
248 // Message codes used with mMainThreadHandler
249 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700250 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
251 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700252 private static final int CMD_OPEN_CHANNEL = 9;
253 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
254 private static final int CMD_CLOSE_CHANNEL = 11;
255 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800256 private static final int CMD_NV_READ_ITEM = 13;
257 private static final int EVENT_NV_READ_ITEM_DONE = 14;
258 private static final int CMD_NV_WRITE_ITEM = 15;
259 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
260 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
261 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700262 private static final int CMD_RESET_MODEM_CONFIG = 19;
263 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800264 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
265 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800266 private static final int CMD_SEND_ENVELOPE = 25;
267 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000268 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
269 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700270 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
271 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
272 private static final int CMD_EXCHANGE_SIM_IO = 31;
273 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800274 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
275 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700276 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
277 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700278 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
279 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700280 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
281 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
282 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700284 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
285 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
286 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
287 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700288 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800289 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
290 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000291 private static final int CMD_SWITCH_SLOTS = 50;
292 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700293 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
294 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
295 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
296 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
297 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
298 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
299 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
300 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700301 private static final int CMD_GET_ALL_CELL_INFO = 60;
302 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
303 private static final int CMD_GET_CELL_LOCATION = 62;
304 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700305 private static final int CMD_MODEM_REBOOT = 64;
306 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700307 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
308 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800309 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
310 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700311 private static final int CMD_GET_MODEM_STATUS = 70;
312 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700313 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
314 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700315 private static final int CMD_ERASE_MODEM_CONFIG = 74;
316 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800317 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
318 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
319 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
320 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800321 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
322 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800323 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800324 private static final int CMD_GET_CALL_FORWARDING = 83;
325 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
326 private static final int CMD_SET_CALL_FORWARDING = 85;
327 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
328 private static final int CMD_GET_CALL_WAITING = 87;
329 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
330 private static final int CMD_SET_CALL_WAITING = 89;
331 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700332 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
333 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
334 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
335 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700336 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
337 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800338 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
339 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800340 private static final int CMD_SET_DATA_THROTTLING = 99;
341 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800342 private static final int CMD_SET_SIM_POWER = 101;
343 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800344 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
345 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
346 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
347 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800348 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
349 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000350 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800351 private static final int CMD_GET_SLICING_CONFIG = 110;
352 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800353 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700354 private static final int CMD_ENABLE_VONR = 113;
355 private static final int EVENT_ENABLE_VONR_DONE = 114;
356 private static final int CMD_IS_VONR_ENABLED = 115;
357 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800359 // Parameters of select command.
360 private static final int SELECT_COMMAND = 0xA4;
361 private static final int SELECT_P1 = 0x04;
362 private static final int SELECT_P2 = 0;
363 private static final int SELECT_P3 = 0x10;
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 /** The singleton instance. */
366 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800367 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800371 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700372 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700374 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800376 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700378 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800379 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380
Peter Wangdafb9ac2020-01-15 14:13:38 -0800381 /** User Activity */
382 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800383 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
384
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700385 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
386
Derek Tan97ebb422014-09-05 16:55:38 -0700387 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
388 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800389 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800390 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700391
Michelecea4cf22018-12-21 15:00:11 -0800392 // String to store multi SIM allowed
393 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
394
Derek Tan740e1672017-06-27 14:56:27 -0700395 // The AID of ISD-R.
396 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
397
yinxub1bed742017-04-17 11:45:04 -0700398 private NetworkScanRequestTracker mNetworkScanRequestTracker;
399
David Kelly5e06a7f2018-03-12 14:10:59 +0000400 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
401 private static final int MANUFACTURER_CODE_LENGTH = 8;
402
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800403 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800404 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800405
Derek Tan89e89d42014-07-08 17:00:10 -0700406 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700407 * Experiment flag to enable erase modem config on reset network, default value is false
408 */
409 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
410 "reset_network_erase_modem_config_enabled";
411
Rambo Wang0f050d82021-02-12 11:43:36 -0800412 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjsb6c87872021-09-27 15:34:44 +0000413 /**
414 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
415 * one ICCID active at the same time.
416 * Apps should use below API signatures if targeting SDK is T and beyond.
417 *
418 * @hide
419 */
420 @ChangeId
421 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
422 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800423
Naina Nallurid63128d2019-09-17 14:10:30 -0700424 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 * A request object to use for transmitting data to an ICC.
426 */
427 private static final class IccAPDUArgument {
428 public int channel, cla, command, p1, p2, p3;
429 public String data;
430
431 public IccAPDUArgument(int channel, int cla, int command,
432 int p1, int p2, int p3, String data) {
433 this.channel = channel;
434 this.cla = cla;
435 this.command = command;
436 this.p1 = p1;
437 this.p2 = p2;
438 this.p3 = p3;
439 this.data = data;
440 }
441 }
442
443 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700444 * A request object to use for transmitting data to an ICC.
445 */
446 private static final class ManualNetworkSelectionArgument {
447 public OperatorInfo operatorInfo;
448 public boolean persistSelection;
449
450 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
451 this.operatorInfo = operatorInfo;
452 this.persistSelection = persistSelection;
453 }
454 }
455
456 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
458 * request after sending. The main thread will notify the request when it is complete.
459 */
460 private static final class MainThreadRequest {
461 /** The argument to use for the request */
462 public Object argument;
463 /** The result of the request that is run on the main thread */
464 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800465 // The subscriber id that this request applies to. Defaults to
466 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
467 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468
Nathan Harold92bed182018-10-12 18:16:49 -0700469 // In cases where subId is unavailable, the caller needs to specify the phone.
470 public Phone phone;
471
vagdeviaf9a5b92018-08-15 16:01:53 -0700472 public WorkSource workSource;
473
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 public MainThreadRequest(Object argument) {
475 this.argument = argument;
476 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800477
Nathan Harold92bed182018-10-12 18:16:49 -0700478 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
479 this.argument = argument;
480 if (phone != null) {
481 this.phone = phone;
482 }
483 this.workSource = workSource;
484 }
485
vagdeviaf9a5b92018-08-15 16:01:53 -0700486 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800487 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800488 if (subId != null) {
489 this.subId = subId;
490 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700491 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 }
494
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800495 private static final class IncomingThirdPartyCallArgs {
496 public final ComponentName component;
497 public final String callId;
498 public final String callerDisplayName;
499
500 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
501 String callerDisplayName) {
502 this.component = component;
503 this.callId = callId;
504 this.callerDisplayName = callerDisplayName;
505 }
506 }
507
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 /**
509 * A handler that processes messages on the main thread in the phone process. Since many
510 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
511 * inbound binder threads to the main thread in the phone process. The Binder thread
512 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
513 * on, which will be notified when the operation completes and will contain the result of the
514 * request.
515 *
516 * <p>If a MainThreadRequest object is provided in the msg.obj field,
517 * note that request.result must be set to something non-null for the calling thread to
518 * unblock.
519 */
520 private final class MainThreadHandler extends Handler {
521 @Override
522 public void handleMessage(Message msg) {
523 MainThreadRequest request;
524 Message onCompleted;
525 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000526 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800528 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529
530 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 case CMD_HANDLE_USSD_REQUEST: {
532 request = (MainThreadRequest) msg.obj;
533 final Phone phone = getPhoneFromRequest(request);
534 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
535 String ussdRequest = ussdObject.first;
536 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700537
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 if (!isUssdApiAllowed(request.subId)) {
539 // Carrier does not support use of this API, return failure.
540 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
541 UssdResponse response = new UssdResponse(ussdRequest, null);
542 Bundle returnData = new Bundle();
543 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
544 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700545
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 request.result = true;
547 notifyRequester(request);
548 return;
549 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 try {
552 request.result = phone != null
553 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
554 } catch (CallStateException cse) {
555 request.result = false;
556 }
557 // Wake up the requesting thread
558 notifyRequester(request);
559 break;
pkanwar32d516d2016-10-14 19:37:38 -0700560 }
561
Yorke Lee716f67e2015-06-17 15:39:16 -0700562 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700564 final Phone phone = getPhoneFromRequest(request);
565 request.result = phone != null ?
566 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
567 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000576 uiccPort = getUiccPortFromRequest(request);
577 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 loge("iccTransmitApduLogicalChannel: No UICC");
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
583 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000584 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 iccArgument.channel, iccArgument.cla, iccArgument.command,
586 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
594 if (ar.exception == null && ar.result != null) {
595 request.result = ar.result;
596 } else {
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
598 if (ar.result == null) {
599 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800600 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800602 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 } else {
604 loge("iccTransmitApduLogicalChannel: Unknown exception");
605 }
606 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
611 request = (MainThreadRequest) msg.obj;
612 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000613 uiccPort = getUiccPortFromRequest(request);
614 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 loge("iccTransmitApduBasicChannel: No UICC");
616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 } else {
619 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
620 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000621 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
623 iccArgument.p3, iccArgument.data, onCompleted);
624 }
625 break;
626
627 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result;
632 } else {
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
634 if (ar.result == null) {
635 loge("iccTransmitApduBasicChannel: Empty response");
636 } else if (ar.exception instanceof CommandException) {
637 loge("iccTransmitApduBasicChannel: CommandException: " +
638 ar.exception);
639 } else {
640 loge("iccTransmitApduBasicChannel: Unknown exception");
641 }
642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 break;
645
646 case CMD_EXCHANGE_SIM_IO:
647 request = (MainThreadRequest) msg.obj;
648 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000649 uiccPort = getUiccPortFromRequest(request);
650 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 loge("iccExchangeSimIO: No UICC");
652 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 } else {
655 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
656 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000657 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
659 iccArgument.data, onCompleted);
660 }
661 break;
662
663 case EVENT_EXCHANGE_SIM_IO_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result;
668 } else {
669 request.result = new IccIoResult(0x6f, 0, (byte[])null);
670 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 break;
673
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 case CMD_SEND_ENVELOPE:
675 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000676 uiccPort = getUiccPortFromRequest(request);
677 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 loge("sendEnvelopeWithStatus: No UICC");
679 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 } else {
682 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 break;
686
687 case EVENT_SEND_ENVELOPE_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800692 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700693 request.result = new IccIoResult(0x6F, 0, (byte[])null);
694 if (ar.result == null) {
695 loge("sendEnvelopeWithStatus: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("sendEnvelopeWithStatus: CommandException: " +
698 ar.exception);
699 } else {
700 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
701 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800704 break;
705
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 case CMD_OPEN_CHANNEL:
707 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000708 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800709 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700711 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800712 request.result = new IccOpenLogicalChannelResponse(-1,
713 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 } else {
716 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000717 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800718 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
722 case EVENT_OPEN_CHANNEL_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 int[] result = (int[]) ar.result;
728 int channelId = result[0];
729 byte[] selectResponse = null;
730 if (result.length > 1) {
731 selectResponse = new byte[result.length - 1];
732 for (int i = 1; i < result.length; ++i) {
733 selectResponse[i - 1] = (byte) result[i];
734 }
735 }
736 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700737 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 if (ar.result == null) {
740 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 if (ar.exception != null) {
743 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
744 }
745
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700746 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700747 if (ar.exception instanceof CommandException) {
748 CommandException.Error error =
749 ((CommandException) (ar.exception)).getCommandError();
750 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700751 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700752 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700753 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 }
755 }
756 openChannelResp = new IccOpenLogicalChannelResponse(
757 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700759 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 break;
762
763 case CMD_CLOSE_CHANNEL:
764 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000765 uiccPort = getUiccPortFromRequest(request);
766 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900768 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 } else {
771 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000772 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 break;
775
776 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800777 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
778 break;
779
780 case CMD_NV_READ_ITEM:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
784 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
787 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800790 if (ar.exception == null && ar.result != null) {
791 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800793 request.result = "";
794 if (ar.result == null) {
795 loge("nvReadItem: Empty response");
796 } else if (ar.exception instanceof CommandException) {
797 loge("nvReadItem: CommandException: " +
798 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800800 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 }
802 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700803 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 break;
805
Jake Hambye994d462014-02-03 13:10:13 -0800806 case CMD_NV_WRITE_ITEM:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
809 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800810 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700811 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
814 case EVENT_NV_WRITE_ITEM_DONE:
815 handleNullReturnEvent(msg, "nvWriteItem");
816 break;
817
818 case CMD_NV_WRITE_CDMA_PRL:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800821 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800822 break;
823
824 case EVENT_NV_WRITE_CDMA_PRL_DONE:
825 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
826 break;
827
chen xu6dac5ab2018-10-26 17:39:23 -0700828 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800829 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700830 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800831 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800832 break;
833
chen xu6dac5ab2018-10-26 17:39:23 -0700834 case EVENT_RESET_MODEM_CONFIG_DONE:
835 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800836 break;
837
Sooraj Sasindran37444802020-08-11 10:40:43 -0700838 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
841 request);
842 Phone phone = getPhoneFromRequest(request);
843 if (phone != null) {
844 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
845 } else {
846 loge("isNRDualConnectivityEnabled: No phone object");
847 request.result = false;
848 notifyRequester(request);
849 }
850 break;
851 }
852
853 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 // request.result must be set to something non-null
860 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700861 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700862 request.result = ar.result;
863 } else {
864 request.result = false;
865 }
866 if (ar.result == null) {
867 loge("isNRDualConnectivityEnabled: Empty response");
868 } else if (ar.exception instanceof CommandException) {
869 loge("isNRDualConnectivityEnabled: CommandException: "
870 + ar.exception);
871 } else {
872 loge("isNRDualConnectivityEnabled: Unknown exception");
873 }
874 }
875 notifyRequester(request);
876 break;
877
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700878 case CMD_IS_VONR_ENABLED: {
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
881 request);
882 Phone phone = getPhoneFromRequest(request);
883 if (phone != null) {
884 phone.isVoNrEnabled(onCompleted, request.workSource);
885 } else {
886 loge("isVoNrEnabled: No phone object");
887 request.result = false;
888 notifyRequester(request);
889 }
890 break;
891 }
892
893 case EVENT_IS_VONR_ENABLED_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
899 // request.result must be set to something non-null
900 // for the calling thread to unblock
901 if (ar.result != null) {
902 request.result = ar.result;
903 } else {
904 request.result = false;
905 }
906 if (ar.result == null) {
907 loge("isVoNrEnabled: Empty response");
908 } else if (ar.exception instanceof CommandException) {
909 loge("isVoNrEnabled: CommandException: "
910 + ar.exception);
911 } else {
912 loge("isVoNrEnabled: Unknown exception");
913 }
914 }
915 notifyRequester(request);
916 break;
917
Sooraj Sasindran37444802020-08-11 10:40:43 -0700918 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
921 Phone phone = getPhoneFromRequest(request);
922 if (phone != null) {
923 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
924 request.workSource);
925 } else {
926 loge("enableNrDualConnectivity: No phone object");
927 request.result =
928 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
929 notifyRequester(request);
930 }
931 break;
932 }
933
934 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 if (ar.exception == null) {
938 request.result =
939 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
940 } else {
941 request.result =
942 TelephonyManager
943 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
944 if (ar.exception instanceof CommandException) {
945 CommandException.Error error =
946 ((CommandException) (ar.exception)).getCommandError();
947 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
948 request.result =
949 TelephonyManager
950 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000951 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
952 request.result =
953 TelephonyManager
954 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700955 }
956 loge("enableNrDualConnectivity" + ": CommandException: "
957 + ar.exception);
958 } else {
959 loge("enableNrDualConnectivity" + ": Unknown exception");
960 }
961 }
962 notifyRequester(request);
963 break;
964 }
965
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700966 case CMD_ENABLE_VONR: {
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
969 Phone phone = getPhoneFromRequest(request);
970 if (phone != null) {
971 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
972 request.workSource);
973 } else {
974 loge("setVoNrEnabled: No phone object");
975 request.result =
976 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
977 notifyRequester(request);
978 }
979 break;
980 }
981
982 case EVENT_ENABLE_VONR_DONE: {
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception == null) {
986 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
987 } else {
988 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
989 if (ar.exception instanceof CommandException) {
990 CommandException.Error error =
991 ((CommandException) (ar.exception)).getCommandError();
992 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
993 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
994 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
995 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
996 } else {
997 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
998 }
999 loge("setVoNrEnabled" + ": CommandException: "
1000 + ar.exception);
1001 } else {
1002 loge("setVoNrEnabled" + ": Unknown exception");
1003 }
1004 }
1005 notifyRequester(request);
1006 break;
1007 }
1008
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1012 request);
1013 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 break;
1015
SongFerngWang3ef3e072020-12-21 16:41:52 +08001016 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception == null && ar.result != null) {
1020 request.result = ar.result; // Integer
1021 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301022 // request.result must be set to something non-null
1023 // for the calling thread to unblock
1024 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001025 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001026 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001028 loge("getAllowedNetworkTypesBitmask: CommandException: "
1029 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001030 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001031 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 }
1033 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001034 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001035 break;
1036
SongFerngWang3ef3e072020-12-21 16:41:52 +08001037 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001038 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001039 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1040 request);
1041 Pair<Integer, Long> reasonWithNetworkTypes =
1042 (Pair<Integer, Long>) request.argument;
1043 getPhoneFromRequest(request).setAllowedNetworkTypes(
1044 reasonWithNetworkTypes.first,
1045 reasonWithNetworkTypes.second,
1046 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001047 break;
1048
SongFerngWang3ef3e072020-12-21 16:41:52 +08001049 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1050 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001051 break;
1052
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001053 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1054 request = (MainThreadRequest)msg.obj;
1055 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001056 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001057 break;
1058
1059 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1060 ar = (AsyncResult)msg.obj;
1061 request = (MainThreadRequest)ar.userObj;
1062 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001063 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001064 break;
1065
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001066 case CMD_SET_VOICEMAIL_NUMBER:
1067 request = (MainThreadRequest) msg.obj;
1068 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1069 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001070 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1071 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001072 break;
1073
1074 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1075 handleNullReturnEvent(msg, "setVoicemailNumber");
1076 break;
1077
Stuart Scott54788802015-03-30 13:18:01 -07001078 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1079 request = (MainThreadRequest) msg.obj;
1080 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1081 request);
1082 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1083 break;
1084
1085 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1086 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1087 break;
1088
Shishir Agrawal302c8692015-06-19 13:49:39 -07001089 case CMD_PERFORM_NETWORK_SCAN:
1090 request = (MainThreadRequest) msg.obj;
1091 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1092 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1093 break;
1094
Hall Liu27d24262020-09-18 19:04:59 -07001095 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001098 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1099 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1100 request.argument;
1101 int callForwardingReason = args.first;
1102 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001103 break;
Hall Liu27d24262020-09-18 19:04:59 -07001104 }
1105 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001106 ar = (AsyncResult) msg.obj;
1107 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001108 TelephonyManager.CallForwardingInfoCallback callback =
1109 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1110 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001111 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001112 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001113 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1114 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1115 // Service Class is a bit mask per 3gpp 27.007. Search for
1116 // any service for voice call.
1117 if ((callForwardInfo.serviceClass
1118 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001119 callForwardingInfo = new CallForwardingInfo(
1120 callForwardInfo.status
1121 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001122 callForwardInfo.reason,
1123 callForwardInfo.number,
1124 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001125 break;
1126 }
1127 }
1128 // Didn't find a call forward info for voice call.
1129 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001130 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1131 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001132 }
Hall Liu27d24262020-09-18 19:04:59 -07001133 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 } else {
1135 if (ar.result == null) {
1136 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1137 }
1138 if (ar.exception != null) {
1139 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1140 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001141 int errorCode = TelephonyManager
1142 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001143 if (ar.exception instanceof CommandException) {
1144 CommandException.Error error =
1145 ((CommandException) (ar.exception)).getCommandError();
1146 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001147 errorCode = TelephonyManager
1148 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001149 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001150 errorCode = TelephonyManager
1151 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001152 }
1153 }
Hall Liu27d24262020-09-18 19:04:59 -07001154 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001155 }
Shuo Qian4a594052020-01-23 11:59:30 -08001156 break;
Hall Liu27d24262020-09-18 19:04:59 -07001157 }
Shuo Qian4a594052020-01-23 11:59:30 -08001158
Hall Liu27d24262020-09-18 19:04:59 -07001159 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001160 request = (MainThreadRequest) msg.obj;
1161 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001162 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001163 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001164 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1165 request.argument).first;
1166 request.phone.setCallForwardingOption(
1167 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001168 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001169 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001170 callForwardingInfoToSet.getReason(),
1171 callForwardingInfoToSet.getNumber(),
1172 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1173 break;
Hall Liu27d24262020-09-18 19:04:59 -07001174 }
Shuo Qian4a594052020-01-23 11:59:30 -08001175
Hall Liu27d24262020-09-18 19:04:59 -07001176 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001177 ar = (AsyncResult) msg.obj;
1178 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001179 Consumer<Integer> callback =
1180 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1181 request.argument).second;
1182 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001184 int errorCode = TelephonyManager.CallForwardingInfoCallback
1185 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001186 if (ar.exception instanceof CommandException) {
1187 CommandException.Error error =
1188 ((CommandException) (ar.exception)).getCommandError();
1189 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001190 errorCode = TelephonyManager.CallForwardingInfoCallback
1191 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001192 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001193 errorCode = TelephonyManager.CallForwardingInfoCallback
1194 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001195 }
1196 }
1197 callback.accept(errorCode);
1198 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001199 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001200 }
Shuo Qian4a594052020-01-23 11:59:30 -08001201 break;
Hall Liu27d24262020-09-18 19:04:59 -07001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203
Hall Liu27d24262020-09-18 19:04:59 -07001204 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1207 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1208 break;
Hall Liu27d24262020-09-18 19:04:59 -07001209 }
Shuo Qian4a594052020-01-23 11:59:30 -08001210
Hall Liu27d24262020-09-18 19:04:59 -07001211 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001214 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001215 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1216 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001217 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 // Service Class is a bit mask per 3gpp 27.007.
1219 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001220 if (callForwardResults.length > 1
1221 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001222 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001223 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001224 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1225 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001227 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 }
1229 } else {
1230 if (ar.result == null) {
1231 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1232 }
1233 if (ar.exception != null) {
1234 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1235 }
1236 if (ar.exception instanceof CommandException) {
1237 CommandException.Error error =
1238 ((CommandException) (ar.exception)).getCommandError();
1239 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1240 callForwardingStatus =
1241 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1242 }
1243 }
1244 }
Hall Liu27d24262020-09-18 19:04:59 -07001245 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 break;
Hall Liu27d24262020-09-18 19:04:59 -07001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248
Hall Liu27d24262020-09-18 19:04:59 -07001249 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001252 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1253 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001254 break;
Hall Liu27d24262020-09-18 19:04:59 -07001255 }
Shuo Qian4a594052020-01-23 11:59:30 -08001256
Hall Liu27d24262020-09-18 19:04:59 -07001257 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001258 ar = (AsyncResult) msg.obj;
1259 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001260 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1261 Consumer<Integer> callback =
1262 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1263 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001264 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001265 if (ar.exception instanceof CommandException) {
1266 CommandException.Error error =
1267 ((CommandException) (ar.exception)).getCommandError();
1268 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1269 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1270 } else {
1271 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1272 }
1273 } else {
1274 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1275 }
1276 } else {
1277 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1278 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280 break;
Hall Liu27d24262020-09-18 19:04:59 -07001281 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001282 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1283 ar = (AsyncResult) msg.obj;
1284 request = (MainThreadRequest) ar.userObj;
1285 CellNetworkScanResult cellScanResult;
1286 if (ar.exception == null && ar.result != null) {
1287 cellScanResult = new CellNetworkScanResult(
1288 CellNetworkScanResult.STATUS_SUCCESS,
1289 (List<OperatorInfo>) ar.result);
1290 } else {
1291 if (ar.result == null) {
1292 loge("getCellNetworkScanResults: Empty response");
1293 }
1294 if (ar.exception != null) {
1295 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1296 }
1297 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1298 if (ar.exception instanceof CommandException) {
1299 CommandException.Error error =
1300 ((CommandException) (ar.exception)).getCommandError();
1301 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1302 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1303 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1304 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1305 }
1306 }
1307 cellScanResult = new CellNetworkScanResult(errorCode, null);
1308 }
1309 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001310 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001311 break;
1312
1313 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1314 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001315 ManualNetworkSelectionArgument selArg =
1316 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001317 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1318 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001319 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1320 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001321 break;
1322
1323 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001324 ar = (AsyncResult) msg.obj;
1325 request = (MainThreadRequest) ar.userObj;
1326 if (ar.exception == null) {
1327 request.result = true;
1328 } else {
1329 request.result = false;
1330 loge("setNetworkSelectionModeManual " + ar.exception);
1331 }
1332 notifyRequester(request);
1333 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001334 break;
1335
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001336 case CMD_GET_MODEM_ACTIVITY_INFO:
1337 request = (MainThreadRequest) msg.obj;
1338 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001339 if (defaultPhone != null) {
1340 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 } else {
1342 ResultReceiver result = (ResultReceiver) request.argument;
1343 Bundle bundle = new Bundle();
1344 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001345 new ModemActivityInfo(0, 0, 0,
1346 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001347 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001348 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001349 break;
1350
Hall Liud0f208c2020-10-14 16:54:44 -07001351 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001354 ResultReceiver result = (ResultReceiver) request.argument;
1355
Hall Liud0f208c2020-10-14 16:54:44 -07001356 ModemActivityInfo ret = null;
1357 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001358 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001359 // Update the last modem activity info and the result of the request.
1360 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1361 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001362 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001363 int[] txTimeMs = info.getTransmitTimeMillis();
1364 int[] lastModemTxTimeMs = mLastModemActivityInfo
1365 .getTransmitTimeMillis();
1366 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1367 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1368 }
Hall Liu49656c02020-10-09 19:00:11 -07001369 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001370 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1371 + mLastModemActivityInfo.getSleepTimeMillis());
1372 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1373 + mLastModemActivityInfo.getIdleTimeMillis());
1374 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1375 mLastModemActivityInfo.setReceiveTimeMillis(
1376 info.getReceiveTimeMillis()
1377 + mLastModemActivityInfo.getReceiveTimeMillis());
1378 }
Hall Liu49656c02020-10-09 19:00:11 -07001379 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001380 mLastModemActivityInfo.getSleepTimeMillis(),
1381 mLastModemActivityInfo.getIdleTimeMillis(),
1382 mLastModemActivityInfo.getTransmitTimeMillis(),
1383 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001384 } else {
1385 if (ar.result == null) {
1386 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001387 error = TelephonyManager.ModemActivityInfoException
1388 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 } else if (ar.exception instanceof CommandException) {
1390 loge("queryModemActivityInfo: CommandException: " +
1391 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001392 error = TelephonyManager.ModemActivityInfoException
1393 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001394 } else {
1395 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001396 error = TelephonyManager.ModemActivityInfoException
1397 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 }
1399 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001400 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001401 if (ret != null) {
1402 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1403 } else {
1404 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1405 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001406 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001407 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001408 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001409 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410
Meng Wang1a7c35a2016-05-05 20:56:15 -07001411 case CMD_SET_ALLOWED_CARRIERS:
1412 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001413 CarrierRestrictionRules argument =
1414 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001415 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001416 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 break;
1418
1419 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception == null && ar.result != null) {
1423 request.result = ar.result;
1424 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001425 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1426 if (ar.exception instanceof CommandException) {
1427 loge("setAllowedCarriers: CommandException: " + ar.exception);
1428 CommandException.Error error =
1429 ((CommandException) (ar.exception)).getCommandError();
1430 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1431 request.result =
1432 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1433 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001434 } else {
1435 loge("setAllowedCarriers: Unknown exception");
1436 }
1437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001438 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001439 break;
1440
1441 case CMD_GET_ALLOWED_CARRIERS:
1442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001444 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001445 break;
1446
1447 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001453 request.result = new IllegalStateException(
1454 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001455 if (ar.result == null) {
1456 loge("getAllowedCarriers: Empty response");
1457 } else if (ar.exception instanceof CommandException) {
1458 loge("getAllowedCarriers: CommandException: " +
1459 ar.exception);
1460 } else {
1461 loge("getAllowedCarriers: Unknown exception");
1462 }
1463 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001464 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001465 break;
1466
Nathan Haroldb3014052017-01-25 15:57:32 -08001467 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 if (ar.exception == null && ar.result != null) {
1471 request.result = ar.result;
1472 } else {
1473 request.result = new IllegalArgumentException(
1474 "Failed to retrieve Forbidden Plmns");
1475 if (ar.result == null) {
1476 loge("getForbiddenPlmns: Empty response");
1477 } else {
1478 loge("getForbiddenPlmns: Unknown exception");
1479 }
1480 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001481 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001482 break;
1483
1484 case CMD_GET_FORBIDDEN_PLMNS:
1485 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001486 uiccPort = getUiccPortFromRequest(request);
1487 if (uiccPort == null) {
1488 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001489 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001490 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001491 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001492 break;
1493 }
1494 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001495 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001496 if (uiccApp == null) {
1497 loge("getForbiddenPlmns() no app with specified type -- "
1498 + appType);
1499 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001501 break;
1502 } else {
1503 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1504 + " specified type -- " + appType);
1505 }
1506 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1507 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1508 onCompleted);
1509 break;
1510
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001511 case CMD_SWITCH_SLOTS:
1512 request = (MainThreadRequest) msg.obj;
1513 int[] physicalSlots = (int[]) request.argument;
1514 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1515 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1516 break;
1517
1518 case EVENT_SWITCH_SLOTS_DONE:
1519 ar = (AsyncResult) msg.obj;
1520 request = (MainThreadRequest) ar.userObj;
1521 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
1523 break;
1524 case CMD_GET_NETWORK_SELECTION_MODE:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1527 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1528 break;
1529
1530 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception != null) {
1534 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1535 } else {
1536 int mode = ((int[]) ar.result)[0];
1537 if (mode == 0) {
1538 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1539 } else {
1540 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1541 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001543 notifyRequester(request);
1544 break;
1545 case CMD_GET_CDMA_ROAMING_MODE:
1546 request = (MainThreadRequest) msg.obj;
1547 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1548 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1549 break;
1550 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 if (ar.exception != null) {
1554 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1555 } else {
1556 request.result = ((int[]) ar.result)[0];
1557 }
1558 notifyRequester(request);
1559 break;
1560 case CMD_SET_CDMA_ROAMING_MODE:
1561 request = (MainThreadRequest) msg.obj;
1562 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1563 int mode = (int) request.argument;
1564 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1565 break;
1566 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1567 ar = (AsyncResult) msg.obj;
1568 request = (MainThreadRequest) ar.userObj;
1569 request.result = ar.exception == null;
1570 notifyRequester(request);
1571 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001572 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1573 request = (MainThreadRequest) msg.obj;
1574 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1575 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1576 break;
1577 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 if (ar.exception != null) {
1581 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1582 } else {
1583 request.result = ((int[]) ar.result)[0];
1584 }
1585 notifyRequester(request);
1586 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001587 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1588 request = (MainThreadRequest) msg.obj;
1589 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1590 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001591 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1592 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001593 break;
1594 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
1597 request.result = ar.exception == null;
1598 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001599 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001600 case CMD_GET_ALL_CELL_INFO:
1601 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001602 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001603 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001605 case EVENT_GET_ALL_CELL_INFO_DONE:
1606 ar = (AsyncResult) msg.obj;
1607 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001608 // If a timeout occurs, the response will be null
1609 request.result = (ar.exception == null && ar.result != null)
1610 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001611 synchronized (request) {
1612 request.notifyAll();
1613 }
1614 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001615 case CMD_REQUEST_CELL_INFO_UPDATE:
1616 request = (MainThreadRequest) msg.obj;
1617 request.phone.requestCellInfoUpdate(request.workSource,
1618 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1619 break;
1620 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1624 try {
1625 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001626 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001627 cb.onError(
1628 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1629 ar.exception.getClass().getName(),
1630 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001631 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001632 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001633 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001634 } else {
1635 // use the result as returned
1636 cb.onCellInfo((List<CellInfo>) ar.result);
1637 }
1638 } catch (RemoteException re) {
1639 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1640 }
1641 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001642 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001643 request = (MainThreadRequest) msg.obj;
1644 WorkSource ws = (WorkSource) request.argument;
1645 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001646 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001647 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001648 }
1649 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001650 ar = (AsyncResult) msg.obj;
1651 request = (MainThreadRequest) ar.userObj;
1652 if (ar.exception == null) {
1653 request.result = ar.result;
1654 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001655 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001656 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001657 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 }
1659
1660 synchronized (request) {
1661 request.notifyAll();
1662 }
1663 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001664 }
chen xu6dac5ab2018-10-26 17:39:23 -07001665 case CMD_MODEM_REBOOT:
1666 request = (MainThreadRequest) msg.obj;
1667 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001668 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001669 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001670 case EVENT_CMD_MODEM_REBOOT_DONE:
1671 handleNullReturnEvent(msg, "rebootModem");
1672 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001673 case CMD_REQUEST_ENABLE_MODEM:
1674 request = (MainThreadRequest) msg.obj;
1675 boolean enable = (boolean) request.argument;
1676 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001677 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001678 PhoneConfigurationManager.getInstance()
1679 .enablePhone(request.phone, enable, onCompleted);
1680 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001681 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001685 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001686 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001687 if ((boolean) request.result) {
1688 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1689 updateModemStateMetrics();
1690 } else {
1691 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1692 + ar.exception);
1693 }
1694 notifyRequester(request);
1695 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001696 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001697 case CMD_GET_MODEM_STATUS:
1698 request = (MainThreadRequest) msg.obj;
1699 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1700 PhoneConfigurationManager.getInstance()
1701 .getPhoneStatusFromModem(request.phone, onCompleted);
1702 break;
1703 case EVENT_GET_MODEM_STATUS_DONE:
1704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 int id = request.phone.getPhoneId();
1707 if (ar.exception == null && ar.result != null) {
1708 request.result = ar.result;
1709 //update the cache as modem status has changed
1710 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1711 (boolean) request.result);
1712 } else {
1713 // Return true if modem status cannot be retrieved. For most cases,
1714 // modem status is on. And for older version modems, GET_MODEM_STATUS
1715 // and disable modem are not supported. Modem is always on.
1716 // TODO: this should be fixed in R to support a third
1717 // status UNKNOWN b/131631629
1718 request.result = true;
1719 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1720 + ar.exception);
1721 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001722 notifyRequester(request);
1723 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001724 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1727 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1728 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1729 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1730 break;
1731 }
1732 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1736 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1737 args.second.accept(ar.exception == null);
1738 notifyRequester(request);
1739 break;
1740 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001741 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1742 request = (MainThreadRequest) msg.obj;
1743 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1744 Phone phone = getPhoneFromRequest(request);
1745 if (phone != null) {
1746 phone.getSystemSelectionChannels(onCompleted);
1747 } else {
1748 loge("getSystemSelectionChannels: No phone object");
1749 request.result = new ArrayList<RadioAccessSpecifier>();
1750 notifyRequester(request);
1751 }
1752 break;
1753 }
1754 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 if (ar.exception == null && ar.result != null) {
1758 request.result = ar.result;
1759 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001760 request.result = new IllegalStateException(
1761 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001762 if (ar.result == null) {
1763 loge("getSystemSelectionChannels: Empty response");
1764 } else {
1765 loge("getSystemSelectionChannels: Unknown exception");
1766 }
1767 }
1768 notifyRequester(request);
1769 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001770 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 if (ar.exception == null && ar.result != null) {
1774 request.result = ar.result;
1775 } else {
1776 request.result = -1;
1777 loge("Failed to set Forbidden Plmns");
1778 if (ar.result == null) {
1779 loge("setForbidenPlmns: Empty response");
1780 } else if (ar.exception != null) {
1781 loge("setForbiddenPlmns: Exception: " + ar.exception);
1782 request.result = -1;
1783 } else {
1784 loge("setForbiddenPlmns: Unknown exception");
1785 }
1786 }
1787 notifyRequester(request);
1788 break;
1789 case CMD_SET_FORBIDDEN_PLMNS:
1790 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001791 uiccPort = getUiccPortFromRequest(request);
1792 if (uiccPort == null) {
1793 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001794 request.result = -1;
1795 notifyRequester(request);
1796 break;
1797 }
1798 Pair<Integer, List<String>> setFplmnsArgs =
1799 (Pair<Integer, List<String>>) request.argument;
1800 appType = setFplmnsArgs.first;
1801 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001802 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001803 if (uiccApp == null) {
1804 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1805 request.result = -1;
1806 loge("Failed to get UICC App");
1807 notifyRequester(request);
1808 } else {
1809 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1810 ((SIMRecords) uiccApp.getIccRecords())
1811 .setForbiddenPlmns(onCompleted, fplmns);
1812 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001813 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001814 case CMD_ERASE_MODEM_CONFIG:
1815 request = (MainThreadRequest) msg.obj;
1816 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1817 defaultPhone.eraseModemConfig(onCompleted);
1818 break;
1819 case EVENT_ERASE_MODEM_CONFIG_DONE:
1820 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001821 break;
zoey chene02881a2019-12-30 16:11:23 +08001822
Kai Shif70f46f2021-03-03 13:59:46 -08001823 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1824 request = (MainThreadRequest) msg.obj;
1825 request.result = defaultPhone.eraseDataInSharedPreferences();
1826 notifyRequester(request);
1827 break;
1828
zoey chene02881a2019-12-30 16:11:23 +08001829 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1832 Pair<String, String> changed = (Pair<String, String>) request.argument;
1833 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1834 changed.first, changed.second, onCompleted);
1835 break;
1836 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 if (ar.exception == null) {
1840 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001841 // If the operation is successful, update the PIN storage
1842 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1843 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001844 UiccController.getInstance().getPinStorage()
1845 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001846 } else {
1847 request.result = msg.arg1;
1848 }
1849 notifyRequester(request);
1850 break;
1851
Michele Berionne5e411512020-11-13 02:36:59 +00001852 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001853 request = (MainThreadRequest) msg.obj;
1854 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1855 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1856 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1857 enabled.first, enabled.second, onCompleted);
1858 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001859 }
zoey chene02881a2019-12-30 16:11:23 +08001860 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1861 ar = (AsyncResult) msg.obj;
1862 request = (MainThreadRequest) ar.userObj;
1863 if (ar.exception == null) {
1864 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001865 // If the operation is successful, update the PIN storage
1866 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1867 int phoneId = getPhoneFromRequest(request).getPhoneId();
1868 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001869 UiccController.getInstance().getPinStorage()
1870 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001871 } else {
1872 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1873 }
zoey chene02881a2019-12-30 16:11:23 +08001874 } else {
1875 request.result = msg.arg1;
1876 }
Michele Berionne5e411512020-11-13 02:36:59 +00001877
1878
zoey chene02881a2019-12-30 16:11:23 +08001879 notifyRequester(request);
1880 break;
1881
Peter Wangdafb9ac2020-01-15 14:13:38 -08001882 case MSG_NOTIFY_USER_ACTIVITY:
1883 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001884 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001885 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1886 getDefaultPhone().getContext().sendBroadcastAsUser(
1887 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1888 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001889
1890 case CMD_SET_DATA_THROTTLING: {
1891 request = (MainThreadRequest) msg.obj;
1892 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1893 DataThrottlingRequest dataThrottlingRequest =
1894 (DataThrottlingRequest) request.argument;
1895 Phone phone = getPhoneFromRequest(request);
1896 if (phone != null) {
1897 phone.setDataThrottling(onCompleted,
1898 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1899 dataThrottlingRequest.getCompletionDurationMillis());
1900 } else {
1901 loge("setDataThrottling: No phone object");
1902 request.result =
1903 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1904 notifyRequester(request);
1905 }
1906
1907 break;
1908 }
1909 case EVENT_SET_DATA_THROTTLING_DONE:
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912
1913 if (ar.exception == null) {
1914 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1915 } else if (ar.exception instanceof CommandException) {
1916 loge("setDataThrottling: CommandException: " + ar.exception);
1917 CommandException.Error error =
1918 ((CommandException) (ar.exception)).getCommandError();
1919
1920 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1921 request.result = TelephonyManager
1922 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1923 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1924 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001925 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1926 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001927 } else {
1928 request.result =
1929 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1930 }
1931 } else {
1932 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1933 }
1934 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1935 notifyRequester(request);
1936 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001937
1938 case CMD_SET_SIM_POWER: {
1939 request = (MainThreadRequest) msg.obj;
1940 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1941 request = (MainThreadRequest) msg.obj;
1942 int stateToSet =
1943 ((Pair<Integer, IIntegerConsumer>)
1944 request.argument).first;
1945 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1946 break;
1947 }
1948 case EVENT_SET_SIM_POWER_DONE: {
1949 ar = (AsyncResult) msg.obj;
1950 request = (MainThreadRequest) ar.userObj;
1951 IIntegerConsumer callback =
1952 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1953 if (ar.exception != null) {
1954 loge("setSimPower exception: " + ar.exception);
1955 int errorCode = TelephonyManager.CallForwardingInfoCallback
1956 .RESULT_ERROR_UNKNOWN;
1957 if (ar.exception instanceof CommandException) {
1958 CommandException.Error error =
1959 ((CommandException) (ar.exception)).getCommandError();
1960 if (error == CommandException.Error.SIM_ERR) {
1961 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1962 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1963 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1964 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1965 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1966 } else {
1967 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1968 }
1969 }
1970 try {
1971 callback.accept(errorCode);
1972 } catch (RemoteException e) {
1973 // Ignore if the remote process is no longer available to call back.
1974 Log.w(LOG_TAG, "setSimPower: callback not available.");
1975 }
1976 } else {
1977 try {
1978 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1979 } catch (RemoteException e) {
1980 // Ignore if the remote process is no longer available to call back.
1981 Log.w(LOG_TAG, "setSimPower: callback not available.");
1982 }
1983 }
1984 break;
1985 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001986 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1987 request = (MainThreadRequest) msg.obj;
1988
1989 final Phone phone = getPhoneFromRequest(request);
1990 if (phone == null || phone.getServiceStateTracker() == null) {
1991 request.result = new IllegalStateException("Phone or SST is null");
1992 notifyRequester(request);
1993 break;
1994 }
1995
1996 Pair<Integer, SignalStrengthUpdateRequest> pair =
1997 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1998 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1999 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002000 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002001 request.subId, pair.first /*callingUid*/,
2002 pair.second /*request*/, onCompleted);
2003 break;
2004 }
2005 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2006 ar = (AsyncResult) msg.obj;
2007 request = (MainThreadRequest) ar.userObj;
2008 // request.result will be the exception of ar if present, true otherwise.
2009 // Be cautious not to leave result null which will wait() forever
2010 request.result = ar.exception != null ? ar.exception : true;
2011 notifyRequester(request);
2012 break;
2013 }
2014 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2015 request = (MainThreadRequest) msg.obj;
2016
2017 Phone phone = getPhoneFromRequest(request);
2018 if (phone == null || phone.getServiceStateTracker() == null) {
2019 request.result = new IllegalStateException("Phone or SST is null");
2020 notifyRequester(request);
2021 break;
2022 }
2023
2024 Pair<Integer, SignalStrengthUpdateRequest> pair =
2025 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2026 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2027 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002028 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002029 request.subId, pair.first /*callingUid*/,
2030 pair.second /*request*/, onCompleted);
2031 break;
2032 }
2033 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2034 ar = (AsyncResult) msg.obj;
2035 request = (MainThreadRequest) ar.userObj;
2036 request.result = ar.exception != null ? ar.exception : true;
2037 notifyRequester(request);
2038 break;
2039 }
Jordan Liu109698e2020-11-24 14:50:34 -08002040
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002041 case CMD_GET_SLICING_CONFIG: {
2042 request = (MainThreadRequest) msg.obj;
2043 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2044 request.phone.getSlicingConfig(onCompleted);
2045 break;
2046 }
2047 case EVENT_GET_SLICING_CONFIG_DONE: {
2048 ar = (AsyncResult) msg.obj;
2049 request = (MainThreadRequest) ar.userObj;
2050 ResultReceiver result = (ResultReceiver) request.argument;
2051
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002052 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002053 Bundle bundle = new Bundle();
2054 int resultCode = 0;
2055 if (ar.exception != null) {
2056 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2057 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002058 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002059 } else if (ar.result == null) {
2060 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002061 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002062 } else {
2063 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002064 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2065 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002066 }
2067
2068 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002069 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002070 }
2071 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2072 result.send(resultCode, bundle);
2073 notifyRequester(request);
2074 break;
2075 }
2076
Michele Berionne5e411512020-11-13 02:36:59 +00002077 case CMD_PREPARE_UNATTENDED_REBOOT:
2078 request = (MainThreadRequest) msg.obj;
2079 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002080 UiccController.getInstance().getPinStorage()
2081 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002082 notifyRequester(request);
2083 break;
2084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 default:
2086 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2087 break;
2088 }
2089 }
Jake Hambye994d462014-02-03 13:10:13 -08002090
Pengquan Menga1bb6272018-09-06 09:59:22 -07002091 private void notifyRequester(MainThreadRequest request) {
2092 synchronized (request) {
2093 request.notifyAll();
2094 }
2095 }
2096
Jake Hambye994d462014-02-03 13:10:13 -08002097 private void handleNullReturnEvent(Message msg, String command) {
2098 AsyncResult ar = (AsyncResult) msg.obj;
2099 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2100 if (ar.exception == null) {
2101 request.result = true;
2102 } else {
2103 request.result = false;
2104 if (ar.exception instanceof CommandException) {
2105 loge(command + ": CommandException: " + ar.exception);
2106 } else {
2107 loge(command + ": Unknown exception");
2108 }
2109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002110 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
2114 /**
2115 * Posts the specified command to be executed on the main thread,
2116 * waits for the request to complete, and returns the result.
2117 * @see #sendRequestAsync
2118 */
2119 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002120 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2121 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002122 }
2123
2124 /**
2125 * Posts the specified command to be executed on the main thread,
2126 * waits for the request to complete, and returns the result.
2127 * @see #sendRequestAsync
2128 */
2129 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2130 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002131 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002132 }
2133
2134 /**
2135 * Posts the specified command to be executed on the main thread,
2136 * waits for the request to complete, and returns the result.
2137 * @see #sendRequestAsync
2138 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002139 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002140 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2141 }
2142
2143 /**
2144 * Posts the specified command to be executed on the main thread,
2145 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2146 * if not timeout or null otherwise.
2147 * @see #sendRequestAsync
2148 */
2149 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2150 long timeoutInMs) {
2151 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002152 }
2153
2154 /**
2155 * Posts the specified command to be executed on the main thread,
2156 * waits for the request to complete, and returns the result.
2157 * @see #sendRequestAsync
2158 */
Nathan Harold92bed182018-10-12 18:16:49 -07002159 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002160 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002161 }
2162
2163 /**
2164 * Posts the specified command to be executed on the main thread,
2165 * waits for the request to complete, and returns the result.
2166 * @see #sendRequestAsync
2167 */
2168 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002169 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2170 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002171 }
2172
2173 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002174 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2175 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2176 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002177 * @see #sendRequestAsync
2178 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2180 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2182 throw new RuntimeException("This method will deadlock if called from the main thread.");
2183 }
2184
Nathan Harold92bed182018-10-12 18:16:49 -07002185 MainThreadRequest request = null;
2186 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2187 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2188 } else if (phone != null) {
2189 request = new MainThreadRequest(argument, phone, workSource);
2190 } else {
2191 request = new MainThreadRequest(argument, subId, workSource);
2192 }
2193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 Message msg = mMainThreadHandler.obtainMessage(command, request);
2195 msg.sendToTarget();
2196
Rambo Wang0f050d82021-02-12 11:43:36 -08002197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 if (timeoutInMs >= 0) {
2200 // Wait for at least timeoutInMs before returning null request result
2201 long now = SystemClock.elapsedRealtime();
2202 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002203 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002204 try {
2205 request.wait(deadline - now);
2206 } catch (InterruptedException e) {
2207 // Do nothing, go back and check if request is completed or timeout
2208 } finally {
2209 now = SystemClock.elapsedRealtime();
2210 }
2211 }
2212 } else {
2213 // Wait for the request to complete
2214 while (request.result == null) {
2215 try {
2216 request.wait();
2217 } catch (InterruptedException e) {
2218 // Do nothing, go back and wait until the request is complete
2219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002223 if (request.result == null) {
2224 Log.wtf(LOG_TAG,
2225 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 return request.result;
2228 }
2229
2230 /**
2231 * Asynchronous ("fire and forget") version of sendRequest():
2232 * Posts the specified command to be executed on the main thread, and
2233 * returns immediately.
2234 * @see #sendRequest
2235 */
2236 private void sendRequestAsync(int command) {
2237 mMainThreadHandler.sendEmptyMessage(command);
2238 }
2239
2240 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002242 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002243 */
2244 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 sendRequestAsync(command, argument, null, null);
2246 }
2247
2248 /**
2249 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2250 * @see {@link #sendRequest(int,Object)}
2251 */
2252 private void sendRequestAsync(
2253 int command, Object argument, Phone phone, WorkSource workSource) {
2254 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002255 Message msg = mMainThreadHandler.obtainMessage(command, request);
2256 msg.sendToTarget();
2257 }
2258
2259 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 * Initialize the singleton PhoneInterfaceManager instance.
2261 * This is only done once, at startup, from PhoneApp.onCreate().
2262 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 synchronized (PhoneInterfaceManager.class) {
2265 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002266 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 } else {
2268 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2269 }
2270 return sInstance;
2271 }
2272 }
2273
2274 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002275 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002278 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002279 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002281 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002283 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002284 mTelephonySharedPreferences =
2285 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002286 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002287 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002288 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002289 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 publish();
2292 }
2293
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002294 private Phone getDefaultPhone() {
2295 Phone thePhone = getPhone(getDefaultSubscription());
2296 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2297 }
2298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 private void publish() {
2300 if (DBG) log("publish: " + this);
2301
Peter Wangc035ce42020-01-08 21:00:22 -08002302 TelephonyFrameworkInitializer
2303 .getTelephonyServiceManager()
2304 .getTelephonyServiceRegisterer()
2305 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
Stuart Scott584921c2015-01-15 17:10:34 -08002308 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002309 if (request.phone != null) {
2310 return request.phone;
2311 } else {
2312 return getPhoneFromSubId(request.subId);
2313 }
2314 }
2315
2316 private Phone getPhoneFromSubId(int subId) {
2317 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2318 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002319 }
2320
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002321 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002322 Phone phone = getPhoneFromRequest(request);
2323 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002324 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002325 }
2326
Wink Saville36469e72014-06-11 15:17:00 -07002327 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002329 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331
Kai Shif70f46f2021-03-03 13:59:46 -08002332 private void sendEraseModemConfig(@NonNull Phone phone) {
2333 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2334 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2335 }
2336
2337 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2338 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2339 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002340 }
2341
Peter Wang44b186e2020-01-13 23:33:09 -08002342 private boolean isImsAvailableOnDevice() {
2343 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2344 if (pm == null) {
2345 // For some reason package manger is not available.. This will fail internally anyway,
2346 // so do not throw error and allow.
2347 return true;
2348 }
2349 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2350 }
2351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002353 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002354 }
2355
Wink Savilleb564aae2014-10-23 10:18:09 -07002356 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 if (DBG) log("dial: " + number);
2358 // No permission check needed here: This is just a wrapper around the
2359 // ACTION_DIAL intent, which is available to any app since it puts up
2360 // the UI before it does anything.
2361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 String url = createTelUrl(number);
2365 if (url == null) {
2366 return;
2367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 // PENDING: should we just silently fail if phone is offhook or ringing?
2370 PhoneConstants.State state = mCM.getState(subId);
2371 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2372 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2373 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2374 mApp.startActivity(intent);
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379 }
2380
2381 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002382 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
2384
Wink Savilleb564aae2014-10-23 10:18:09 -07002385 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 if (DBG) log("call: " + number);
2387
2388 // This is just a wrapper around the ACTION_CALL intent, but we still
2389 // need to do a permission check since we're calling startActivity()
2390 // from the context of the phone app.
2391 enforceCallPermission();
2392
Jordan Liu1617b712019-07-10 15:06:26 -07002393 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 != AppOpsManager.MODE_ALLOWED) {
2395 return;
2396 }
2397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 String url = createTelUrl(number);
2401 if (url == null) {
2402 return;
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002405 boolean isValid = false;
2406 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2407 if (slist != null) {
2408 for (SubscriptionInfo subInfoRecord : slist) {
2409 if (subInfoRecord.getSubscriptionId() == subId) {
2410 isValid = true;
2411 break;
2412 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002413 }
Wink Saville08874612014-08-31 19:19:58 -07002414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 if (!isValid) {
2416 return;
2417 }
Wink Saville08874612014-08-31 19:19:58 -07002418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2420 intent.putExtra(SUBSCRIPTION_KEY, subId);
2421 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2422 mApp.startActivity(intent);
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427
Wink Savilleb564aae2014-10-23 10:18:09 -07002428 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002429 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002430 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002434 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002435 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2436 }
2437
Wink Savilleb564aae2014-10-23 10:18:09 -07002438 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002443 Phone phone = getPhone(subId);
2444 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 checkSimPin.start();
2446 return checkSimPin.unlockSim(null, pin);
2447 } finally {
2448 Binder.restoreCallingIdentity(identity);
2449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 }
2451
Wink Savilleb564aae2014-10-23 10:18:09 -07002452 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454
2455 final long identity = Binder.clearCallingIdentity();
2456 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002457 Phone phone = getPhone(subId);
2458 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 checkSimPuk.start();
2460 return checkSimPuk.unlockSim(puk, pin);
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
2463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
2466 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002467 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 * a synchronous one.
2469 */
2470 private static class UnlockSim extends Thread {
2471
2472 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002473 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474
2475 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002476 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2477 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478
2479 // For replies from SimCard interface
2480 private Handler mHandler;
2481
2482 // For async handler to identify request type
2483 private static final int SUPPLY_PIN_COMPLETE = 100;
2484
Michele Berionne5e411512020-11-13 02:36:59 +00002485 UnlockSim(int phoneId, IccCard simCard) {
2486 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 mSimCard = simCard;
2488 }
2489
2490 @Override
2491 public void run() {
2492 Looper.prepare();
2493 synchronized (UnlockSim.this) {
2494 mHandler = new Handler() {
2495 @Override
2496 public void handleMessage(Message msg) {
2497 AsyncResult ar = (AsyncResult) msg.obj;
2498 switch (msg.what) {
2499 case SUPPLY_PIN_COMPLETE:
2500 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2501 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002502 mRetryCount = msg.arg1;
2503 if (ar.exception != null) {
2504 if (ar.exception instanceof CommandException &&
2505 ((CommandException)(ar.exception)).getCommandError()
2506 == CommandException.Error.PASSWORD_INCORRECT) {
2507 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002508 } //When UiccCardApp dispose,handle message and return exception
2509 else if (ar.exception instanceof CommandException &&
2510 ((CommandException) (ar.exception)).getCommandError()
2511 == CommandException.Error.ABORTED) {
2512 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002513 } else {
2514 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2515 }
2516 } else {
2517 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 mDone = true;
2520 UnlockSim.this.notifyAll();
2521 }
2522 break;
2523 }
2524 }
2525 };
2526 UnlockSim.this.notifyAll();
2527 }
2528 Looper.loop();
2529 }
2530
2531 /*
2532 * Use PIN or PUK to unlock SIM card
2533 *
2534 * If PUK is null, unlock SIM card with PIN
2535 *
2536 * If PUK is not null, unlock SIM card with PUK and set PIN code
2537 */
Wink Saville9de0f752013-10-22 19:04:03 -07002538 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
2540 while (mHandler == null) {
2541 try {
2542 wait();
2543 } catch (InterruptedException e) {
2544 Thread.currentThread().interrupt();
2545 }
2546 }
2547 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2548
2549 if (puk == null) {
2550 mSimCard.supplyPin(pin, callback);
2551 } else {
2552 mSimCard.supplyPuk(puk, pin, callback);
2553 }
2554
2555 while (!mDone) {
2556 try {
2557 Log.d(LOG_TAG, "wait for done");
2558 wait();
2559 } catch (InterruptedException e) {
2560 // Restore the interrupted status
2561 Thread.currentThread().interrupt();
2562 }
2563 }
2564 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002565 int[] resultArray = new int[2];
2566 resultArray[0] = mResult;
2567 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002568
2569 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002570 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002571 }
2572
Wink Saville9de0f752013-10-22 19:04:03 -07002573 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575 }
2576
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002577 /**
2578 * This method has been removed due to privacy and stability concerns.
2579 */
2580 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002582 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2583 return;
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Nathan Harold1f889d82020-06-04 17:05:26 -07002586 @Override
2587 public void updateServiceLocationWithPackageName(String callingPackage) {
2588 mApp.getSystemService(AppOpsManager.class)
2589 .checkPackage(Binder.getCallingUid(), callingPackage);
2590
Nathan Haroldf096d982020-11-18 17:18:06 -08002591 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002592 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2593 // Callers targeting S have no business invoking this method.
2594 return;
2595 }
2596
2597 LocationAccessPolicy.LocationPermissionResult locationResult =
2598 LocationAccessPolicy.checkLocationPermission(mApp,
2599 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2600 .setCallingPackage(callingPackage)
2601 .setCallingFeatureId(null)
2602 .setCallingPid(Binder.getCallingPid())
2603 .setCallingUid(Binder.getCallingUid())
2604 .setMethod("updateServiceLocation")
2605 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2606 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2607 .build());
2608 // Apps that lack location permission have no business calling this method;
2609 // however, because no permission was declared in the public API, denials must
2610 // all be "soft".
2611 switch (locationResult) {
2612 case DENIED_HARD: /* fall through */
2613 case DENIED_SOFT:
2614 return;
2615 }
2616
2617 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002620 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002622 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 @Override
2631 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 return isRadioOnWithFeature(callingPackage, null);
2633 }
2634
2635
2636 @Override
2637 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2638 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2639 callingFeatureId);
2640 }
2641
2642 @Deprecated
2643 @Override
2644 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2645 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002649 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2650 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002652 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 return false;
2654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 return isRadioOnForSubscriber(subId);
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002662 }
2663
2664 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
2669 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2670 } else {
2671 return false;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
2678 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
Wink Saville36469e72014-06-11 15:17:00 -07002681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 final Phone phone = getPhone(subId);
2688 if (phone != null) {
2689 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Wink Saville36469e72014-06-11 15:17:00 -07002694 }
2695
2696 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002697 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 if (phone == null) {
2707 return false;
2708 }
2709 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2710 toggleRadioOnOffForSubscriber(subId);
2711 }
2712 return true;
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
Wink Saville36469e72014-06-11 15:17:00 -07002717
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002719 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 /*
2721 * If any of the Radios are available, it will need to be
2722 * shutdown. So return true if any Radio is available.
2723 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2727 Phone phone = PhoneFactory.getPhone(i);
2728 if (phone != null && phone.isRadioAvailable()) return true;
2729 }
2730 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2731 return false;
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002734 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 }
2736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002738 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 enforceModifyPermission();
2740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2744 logv("Shutting down Phone " + i);
2745 shutdownRadioUsingPhoneId(i);
2746 }
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002749 }
2750 }
2751
2752 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002753 Phone phone = PhoneFactory.getPhone(phoneId);
2754 if (phone != null && phone.isRadioAvailable()) {
2755 phone.shutdownRadio();
2756 }
2757 }
2758
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2765 if (defaultPhone != null) {
2766 defaultPhone.setRadioPower(turnOn);
2767 return true;
2768 } else {
2769 loge("There's no default phone.");
2770 return false;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002774 }
Wink Saville36469e72014-06-11 15:17:00 -07002775 }
2776
Wink Savilleb564aae2014-10-23 10:18:09 -07002777 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(subId);
2783 if (phone != null) {
2784 phone.setRadioPower(turnOn);
2785 return true;
2786 } else {
2787 return false;
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Wink Saville36469e72014-06-11 15:17:00 -07002794 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 public boolean enableDataConnectivity() {
2797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 int subId = mSubscriptionController.getDefaultDataSubId();
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002804 phone.getDataEnabledSettings().setDataEnabled(
2805 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 return true;
2807 } else {
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
2814
Wink Saville36469e72014-06-11 15:17:00 -07002815 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 public boolean disableDataConnectivity() {
2818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 int subId = mSubscriptionController.getDefaultDataSubId();
2823 final Phone phone = getPhone(subId);
2824 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002825 phone.getDataEnabledSettings().setDataEnabled(
2826 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 return true;
2828 } else {
2829 return false;
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 }
2835
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002837 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 final Phone phone = getPhone(subId);
2841 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002842 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843 } else {
2844 return false;
2845 }
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 }
2850
2851 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002852 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002853 }
2854
pkanwarae03a6b2016-11-06 20:37:09 -08002855 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 enforceCallPermission();
2857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2861 return;
2862 }
2863 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2864 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
pkanwar32d516d2016-10-14 19:37:38 -07002868 };
2869
Wink Savilleb564aae2014-10-23 10:18:09 -07002870 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2876 return false;
2877 }
2878 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002884 /**
2885 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2886 * tag on getCallState Binder call.
2887 */
2888 @Deprecated
2889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002891 if (CompatChanges.isChangeEnabled(
2892 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2893 Binder.getCallingUid())) {
2894 // Do not allow this API to be called on API version 31+, it should only be
2895 // called on old apps using this Binder call directly.
2896 throw new SecurityException("This method can only be used for applications "
2897 + "targeting API version 30 or less.");
2898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 final long identity = Binder.clearCallingIdentity();
2900 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002901 Phone phone = getPhone(getDefaultSubscription());
2902 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2903 PhoneConstantConversions.convertCallState(phone.getState());
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 }
2908
2909 @Override
2910 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2911 if (CompatChanges.isChangeEnabled(
2912 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2913 Binder.getCallingUid())) {
2914 // Check READ_PHONE_STATE for API version 31+
2915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2916 featureId, "getCallStateForSubscription")) {
2917 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2918 + "targeting API level 31+.");
2919 }
2920 }
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2925 PhoneConstantConversions.convertCallState(phone.getState());
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002932 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002933 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2934 }
2935
2936 @Override
2937 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002942 if (phone.isUsingNewDataStack()) {
2943 return phone.getDataNetworkController().getInternetDataNetworkState();
2944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2946 } else {
2947 return PhoneConstantConversions.convertDataState(
2948 PhoneConstants.DataState.DISCONNECTED);
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
Sanket Padawe356d7632015-06-22 14:03:32 -07002955 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002956 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002957 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2958 }
2959
2960 @Override
2961 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 if (phone != null) {
2966 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2967 } else {
2968 return TelephonyManager.DATA_ACTIVITY_NONE;
2969 }
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
2974
2975 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002976 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002978 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002979
2980 LocationAccessPolicy.LocationPermissionResult locationResult =
2981 LocationAccessPolicy.checkLocationPermission(mApp,
2982 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2983 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002984 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002985 .setCallingPid(Binder.getCallingPid())
2986 .setCallingUid(Binder.getCallingUid())
2987 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002988 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002989 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2990 .build());
2991 switch (locationResult) {
2992 case DENIED_HARD:
2993 throw new SecurityException("Not allowed to access cell location");
2994 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002995 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2996 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 }
2998
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002999 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003003 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003004 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Svetoslav64fad262015-04-14 14:35:21 -07003008 }
3009
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003011 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003012 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3013 // registered cell info, so return a NULL country instead.
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003016 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3017 // Get default phone in this case.
3018 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3019 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003020 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003022 if (phone == null) return "";
3023 ServiceStateTracker sst = phone.getServiceStateTracker();
3024 if (sst == null) return "";
3025 LocaleTracker lt = sst.getLocaleTracker();
3026 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003027 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003031 }
3032
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003033 /**
3034 * This method was removed due to potential issues caused by performing partial
3035 * updates of service state, and lack of a credible use case.
3036 *
3037 * This has the ability to break the telephony implementation by disabling notification of
3038 * changes in device connectivity. DO NOT USE THIS!
3039 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003040 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 public void enableLocationUpdates() {
3042 mApp.enforceCallingOrSelfPermission(
3043 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -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 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 @Override
3054 public void disableLocationUpdates() {
3055 mApp.enforceCallingOrSelfPermission(
3056 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
3059 @Override
3060 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003061 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3062 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003063 try {
3064 mApp.getSystemService(AppOpsManager.class)
3065 .checkPackage(Binder.getCallingUid(), callingPackage);
3066 } catch (SecurityException e) {
3067 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3068 throw e;
3069 }
3070
Nathan Haroldf096d982020-11-18 17:18:06 -08003071 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003072 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3073 throw new SecurityException(
3074 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3075 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003076
Jordan Liu1617b712019-07-10 15:06:26 -07003077 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3079 return null;
3080 }
Svetoslav64fad262015-04-14 14:35:21 -07003081
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003082 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003083
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003084 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003085 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086
Nathan Haroldf180aac2018-06-01 18:43:55 -07003087 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3088 for (CellInfo ci : info) {
3089 if (ci instanceof CellInfoGsm) {
3090 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3091 } else if (ci instanceof CellInfoWcdma) {
3092 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003095 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
3097
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003098 private List<CellInfo> getCachedCellInfo() {
3099 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3100 for (Phone phone : PhoneFactory.getPhones()) {
3101 List<CellInfo> info = phone.getAllCellInfo();
3102 if (info != null) cellInfos.addAll(info);
3103 }
3104 return cellInfos;
3105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003106
3107 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003108 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003109 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003110 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003111
3112 LocationAccessPolicy.LocationPermissionResult locationResult =
3113 LocationAccessPolicy.checkLocationPermission(mApp,
3114 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3115 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003116 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003117 .setCallingPid(Binder.getCallingPid())
3118 .setCallingUid(Binder.getCallingUid())
3119 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003120 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003121 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3122 .build());
3123 switch (locationResult) {
3124 case DENIED_HARD:
3125 throw new SecurityException("Not allowed to access cell info");
3126 case DENIED_SOFT:
3127 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 }
3129
Nathan Haroldf096d982020-11-18 17:18:06 -08003130 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003131 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3132 return getCachedCellInfo();
3133 }
3134
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003135 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003136 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3140 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003141 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003142 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143 if (info != null) cellInfos.addAll(info);
3144 }
3145 return cellInfos;
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149 }
3150
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003151 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003152 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3153 String callingFeatureId) {
3154 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3155 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003156 }
3157
3158 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003159 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3160 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003161 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003162 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003163 }
3164
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003165 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3166 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003167 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003168 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003169
3170 LocationAccessPolicy.LocationPermissionResult locationResult =
3171 LocationAccessPolicy.checkLocationPermission(mApp,
3172 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3173 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003174 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003175 .setCallingPid(Binder.getCallingPid())
3176 .setCallingUid(Binder.getCallingUid())
3177 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003178 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3179 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 .build());
3181 switch (locationResult) {
3182 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003183 if (TelephonyPermissions
3184 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003185 // Safetynet logging for b/154934934
3186 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3187 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003188 throw new SecurityException("Not allowed to access cell info");
3189 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003190 if (TelephonyPermissions
3191 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003192 // Safetynet logging for b/154934934
3193 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3194 }
Nathan Harold5320c422019-05-09 10:26:08 -07003195 try {
3196 cb.onCellInfo(new ArrayList<CellInfo>());
3197 } catch (RemoteException re) {
3198 // Drop without consequences
3199 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003200 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003201 }
3202
Nathan Harolda939a962019-05-09 10:13:47 -07003203
3204 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003205 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3206
3207 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3208 }
3209
3210 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003212 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003217 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
Shishir Agrawala9f32182016-04-12 12:00:16 -07003223 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003224 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003225 Phone phone = PhoneFactory.getPhone(slotIndex);
3226 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003227 return null;
3228 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003229 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003230 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003231 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003232 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003233 return null;
3234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 return phone.getImei();
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003242 }
3243
3244 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003245 public String getTypeAllocationCodeForSlot(int slotIndex) {
3246 Phone phone = PhoneFactory.getPhone(slotIndex);
3247 String tac = null;
3248 if (phone != null) {
3249 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003250 try {
3251 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3252 } catch (IndexOutOfBoundsException e) {
3253 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3254 return null;
3255 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003256 }
3257 return tac;
3258 }
3259
3260 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003261 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003262 try {
3263 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3264 } catch (SecurityException se) {
3265 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3266 throw new SecurityException("Package " + callingPackage + " does not belong to "
3267 + Binder.getCallingUid());
3268 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003269 Phone phone = PhoneFactory.getPhone(slotIndex);
3270 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003271 return null;
3272 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003273
Jeff Davidson913390f2018-02-23 17:11:49 -08003274 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003275 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003276 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003277 return null;
3278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 return phone.getMeid();
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Jack Yu2af8d712017-03-15 17:14:14 -07003286 }
3287
3288 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003289 public String getManufacturerCodeForSlot(int slotIndex) {
3290 Phone phone = PhoneFactory.getPhone(slotIndex);
3291 String manufacturerCode = null;
3292 if (phone != null) {
3293 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003294 try {
3295 manufacturerCode =
3296 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3297 } catch (IndexOutOfBoundsException e) {
3298 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3299 return null;
3300 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003301 }
3302 return manufacturerCode;
3303 }
3304
3305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003306 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3307 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003308 Phone phone = PhoneFactory.getPhone(slotIndex);
3309 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003310 return null;
3311 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003312 int subId = phone.getSubId();
3313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003314 mApp, subId, callingPackage, callingFeatureId,
3315 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003316 return null;
3317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318
3319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 return phone.getDeviceSvn();
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003325 }
3326
fionaxu43304da2017-11-27 22:51:16 -08003327 @Override
3328 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 final Phone phone = getPhone(subId);
3332 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
fionaxu43304da2017-11-27 22:51:16 -08003336 }
3337
3338 @Override
3339 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 final Phone phone = getPhone(subId);
3343 return phone == null ? null : phone.getCarrierName();
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
fionaxu43304da2017-11-27 22:51:16 -08003347 }
3348
calvinpanffe225e2018-11-01 19:43:06 +08003349 @Override
chen xu0026ca62019-03-06 15:28:50 -08003350 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 final Phone phone = getPhone(subId);
3354 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003355 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
3359 }
3360
3361 @Override
chen xu0026ca62019-03-06 15:28:50 -08003362 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003366 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
3370 }
3371
chen xu651eec72018-11-11 19:03:44 -08003372 @Override
chen xu864e11c2018-12-06 22:10:03 -08003373 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3374 if (!isSubscriptionMccMnc) {
3375 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3376 }
chen xu651eec72018-11-11 19:03:44 -08003377 final Phone phone = PhoneFactory.getPhone(slotIndex);
3378 if (phone == null) {
3379 return TelephonyManager.UNKNOWN_CARRIER_ID;
3380 }
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
3388
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 //
3390 // Internal helper methods.
3391 //
3392
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003393 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003394 * Make sure the caller is the calling package itself
3395 *
3396 * @throws SecurityException if the caller is not the calling package
3397 */
3398 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3399 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003400 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3401 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003402 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003403 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003404 } catch (PackageManager.NameNotFoundException e) {
3405 // packageUid is -1
3406 }
3407 if (packageUid != callingUid) {
3408 throw new SecurityException(message + ": Package " + callingPackage
3409 + " does not belong to " + callingUid);
3410 }
3411 }
3412
3413 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3415 *
3416 * @throws SecurityException if the caller does not have the required permission
3417 */
3418 private void enforceModifyPermission() {
3419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3420 }
3421
Shuo Qian3b6ee772019-11-13 17:43:31 -08003422 private void enforceActiveEmergencySessionPermission() {
3423 mApp.enforceCallingOrSelfPermission(
3424 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3425 }
3426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 /**
3428 * Make sure the caller has the CALL_PHONE permission.
3429 *
3430 * @throws SecurityException if the caller does not have the required permission
3431 */
3432 private void enforceCallPermission() {
3433 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3434 }
3435
paulhu5a773602019-08-23 19:17:33 +08003436 private void enforceSettingsPermission() {
3437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003438 }
3439
Michele Berionne5e411512020-11-13 02:36:59 +00003440 private void enforceRebootPermission() {
3441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3442 }
3443
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 private String createTelUrl(String number) {
3445 if (TextUtils.isEmpty(number)) {
3446 return null;
3447 }
3448
Jake Hambye994d462014-02-03 13:10:13 -08003449 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 }
3451
Ihab Awadf9e92732013-12-05 18:02:52 -08003452 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3454 }
3455
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003456 private static void logv(String msg) {
3457 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3458 }
3459
Ihab Awadf9e92732013-12-05 18:02:52 -08003460 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3462 }
3463
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003464 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003466 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003467 }
3468
Sanket Padawe356d7632015-06-22 14:03:32 -07003469 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003470 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 final Phone phone = PhoneFactory.getPhone(slotIndex);
3474 if (phone == null) {
3475 return PhoneConstants.PHONE_TYPE_NONE;
3476 } else {
3477 return phone.getPhoneType();
3478 }
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 }
3483
3484 /**
3485 * Returns the CDMA ERI icon index to display
3486 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003488 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3489 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3490 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003491 }
3492
Sanket Padawe356d7632015-06-22 14:03:32 -07003493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003494 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3495 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003497 mApp, subId, callingPackage, callingFeatureId,
3498 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003499 return -1;
3500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 final Phone phone = getPhone(subId);
3505 if (phone != null) {
3506 return phone.getCdmaEriIconIndex();
3507 } else {
3508 return -1;
3509 }
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 }
3514
3515 /**
3516 * Returns the CDMA ERI icon mode,
3517 * 0 - ON
3518 * 1 - FLASHING
3519 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3522 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3523 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003524 }
3525
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003527 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3528 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003530 mApp, subId, callingPackage, callingFeatureId,
3531 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 return -1;
3533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = getPhone(subId);
3538 if (phone != null) {
3539 return phone.getCdmaEriIconMode();
3540 } else {
3541 return -1;
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547
3548 /**
3549 * Returns the CDMA ERI text,
3550 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3553 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3554 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003555 }
3556
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3559 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003561 mApp, subId, callingPackage, callingFeatureId,
3562 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 return null;
3564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 return phone.getCdmaEriText();
3571 } else {
3572 return null;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003577 }
3578
3579 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003580 * Returns the CDMA MDN.
3581 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003583 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3585 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586
3587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591 return phone.getLine1Number();
3592 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003593 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594 return null;
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003598 }
3599 }
3600
3601 /**
3602 * Returns the CDMA MIN.
3603 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003605 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3607 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 final Phone phone = getPhone(subId);
3612 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3613 return phone.getCdmaMin();
3614 } else {
3615 return null;
3616 }
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003619 }
3620 }
3621
Hall Liud892bec2018-11-30 14:51:45 -08003622 @Override
3623 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3624 INumberVerificationCallback callback, String callingPackage) {
3625 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3626 != PERMISSION_GRANTED) {
3627 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3628 }
3629 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3630
3631 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3632 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003633 throw new SecurityException("Calling package must be configured in the device config: "
3634 + "calling package: " + callingPackage
3635 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003636 }
3637
3638 if (range == null) {
3639 throw new NullPointerException("Range must be non-null");
3640 }
3641
3642 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003643 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003644
3645 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3646 }
3647
Junda Liuca05d5d2014-08-14 22:36:34 -07003648 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 * Returns true if CDMA provisioning needs to run.
3650 */
3651 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 final long identity = Binder.clearCallingIdentity();
3653 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 }
3659
3660 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003661 * Sets the voice mail number of a given subId.
3662 */
3663 @Override
3664 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003665 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3666 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3671 new Pair<String, String>(alphaTag, number), new Integer(subId));
3672 return success;
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003676 }
3677
Ta-wei Yen87c49842016-05-13 21:19:52 -07003678 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003679 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003681 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3682 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003683 if (!TextUtils.equals(callingPackage, systemDialer)) {
3684 throw new SecurityException("caller must be system dialer");
3685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3690 if (phoneAccountHandle == null) {
3691 return null;
3692 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003693 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003696 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003697 }
3698
3699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003700 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3701 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003704 mApp, subId, callingPackage, callingFeatureId,
3705 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003706 return null;
3707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003709 final long identity = Binder.clearCallingIdentity();
3710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003715 }
3716
3717 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003718 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3719 VisualVoicemailSmsFilterSettings settings) {
3720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003725 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003729 }
3730
3731 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003732 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 mApp, callingPackage, subId);
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 VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3746 String callingPackage, int subId) {
3747 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
3749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003756 }
3757
3758 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003759 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003765 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003769 }
3770
3771 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003772 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3773 String callingAttributionTag, int subId, String number, int port, String text,
3774 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003776 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003777 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003778 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003779 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3780 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003781 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003782
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003783 /**
fionaxu0152e512016-11-14 13:36:14 -08003784 * Sets the voice activation state of a given subId.
3785 */
3786 @Override
3787 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3789 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 final Phone phone = getPhone(subId);
3794 if (phone != null) {
3795 phone.setVoiceActivationState(activationState);
3796 } else {
3797 loge("setVoiceActivationState fails with invalid subId: " + subId);
3798 }
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003801 }
3802 }
3803
3804 /**
3805 * Sets the data activation state of a given subId.
3806 */
3807 @Override
3808 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3810 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811
3812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 final Phone phone = getPhone(subId);
3815 if (phone != null) {
3816 phone.setDataActivationState(activationState);
3817 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003818 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819 }
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003822 }
3823 }
3824
3825 /**
3826 * Returns the voice activation state of a given subId.
3827 */
3828 @Override
3829 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831
fionaxu0152e512016-11-14 13:36:14 -08003832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 if (phone != null) {
3836 return phone.getVoiceActivationState();
3837 } else {
3838 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3839 }
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003842 }
3843 }
3844
3845 /**
3846 * Returns the data activation state of a given subId.
3847 */
3848 @Override
3849 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851
fionaxu0152e512016-11-14 13:36:14 -08003852 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 if (phone != null) {
3856 return phone.getDataActivationState();
3857 } else {
3858 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3859 }
3860 } finally {
3861 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003862 }
3863 }
3864
3865 /**
Wink Saville36469e72014-06-11 15:17:00 -07003866 * Returns the unread count of voicemails for a subId
3867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003869 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3870 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003872 mApp, subId, callingPackage, callingFeatureId,
3873 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003874 return 0;
3875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 if (phone != null) {
3880 return phone.getVoiceMessageCount();
3881 } else {
3882 return 0;
3883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 }
3888
3889 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003890 * returns true, if the device is in a state where both voice and data
3891 * are supported simultaneously. This can change based on location or network condition.
3892 */
3893 @Override
3894 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 final Phone phone = getPhone(subId);
3898 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003902 }
3903
3904 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003905 * Send the dialer code if called from the current default dialer or the caller has
3906 * carrier privilege.
3907 * @param inputCode The dialer code to send
3908 */
3909 @Override
3910 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003911 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003913 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3914 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003915 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003916 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003917 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
fionaxu235cc5e2017-03-06 22:25:57 -08003926 }
3927
Pengquan Menga1bb6272018-09-06 09:59:22 -07003928 @Override
3929 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003930 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003931 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003932 mApp, subId, "getNetworkSelectionMode");
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 if (!isActiveSubscription(subId)) {
3936 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3937 }
3938 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003942 }
3943
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003945 public boolean isInEmergencySmsMode() {
3946 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 for (Phone phone : PhoneFactory.getPhones()) {
3950 if (phone.isInEmergencySmsMode()) {
3951 return true;
3952 }
3953 }
3954 } finally {
3955 Binder.restoreCallingIdentity(identity);
3956 }
3957 return false;
3958 }
3959
shilu366312e2019-12-17 09:28:10 -08003960 /**
3961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3962 * @param subId The subscription to use to check the configuration.
3963 * @param c The callback that will be used to send the result.
3964 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003965 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003966 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3967 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003968 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003969 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003970
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003971 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3972 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3973 "IMS not available on device.");
3974 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 final long token = Binder.clearCallingIdentity();
3976 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003977 int slotId = getSlotIndexOrException(subId);
3978 verifyImsMmTelConfiguredOrThrow(slotId);
3979 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003980 } catch (ImsException e) {
3981 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 } finally {
3983 Binder.restoreCallingIdentity(token);
3984 }
3985 }
3986
shilu366312e2019-12-17 09:28:10 -08003987 /**
3988 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3989 * @param subId The subscription to use to check the configuration.
3990 * @param c The callback that will be used to send the result.
3991 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003993 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003994 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003995 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003996 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3997 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3998 }
Meng Wangafbc5852019-09-19 17:37:13 -07003999 final long token = Binder.clearCallingIdentity();
4000 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004001 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4002 .removeRegistrationCallbackForSubscription(c, subId);
4003 } catch (ImsException e) {
4004 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4005 + "is inactive, ignoring unregister.");
4006 // If the subscription is no longer active, just return, since the callback
4007 // will already have been removed internally.
4008 } finally {
4009 Binder.restoreCallingIdentity(token);
4010 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 }
4012
Brad Ebingera34a6c22019-10-22 17:36:18 -07004013 /**
4014 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4015 */
4016 @Override
4017 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4018 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4019 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4020 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4021 "IMS not available on device.");
4022 }
4023 final long token = Binder.clearCallingIdentity();
4024 try {
4025 Phone phone = getPhone(subId);
4026 if (phone == null) {
4027 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4028 + subId + "'");
4029 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4030 }
4031 phone.getImsRegistrationState(regState -> {
4032 try {
4033 consumer.accept((regState == null)
4034 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4035 } catch (RemoteException e) {
4036 // Ignore if the remote process is no longer available to call back.
4037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4038 }
4039 });
4040 } finally {
4041 Binder.restoreCallingIdentity(token);
4042 }
4043 }
4044
4045 /**
4046 * Get the transport type for the IMS service registration state.
4047 */
4048 @Override
4049 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004050 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004051 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004052 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4053 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4054 "IMS not available on device.");
4055 }
4056 final long token = Binder.clearCallingIdentity();
4057 try {
4058 Phone phone = getPhone(subId);
4059 if (phone == null) {
4060 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4061 + subId + "'");
4062 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4063 }
4064 phone.getImsRegistrationTech(regTech -> {
4065 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4066 int regTechConverted = (regTech == null)
4067 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4068 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4069 regTechConverted);
4070 try {
4071 consumer.accept(regTechConverted);
4072 } catch (RemoteException e) {
4073 // Ignore if the remote process is no longer available to call back.
4074 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4075 }
4076 });
4077 } finally {
4078 Binder.restoreCallingIdentity(token);
4079 }
4080 }
4081
shilu366312e2019-12-17 09:28:10 -08004082 /**
4083 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4084 * @param subId The subscription to use to check the configuration.
4085 * @param c The callback that will be used to send the result.
4086 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004088 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4089 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004090 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004091 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004092 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4093 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4094 "IMS not available on device.");
4095 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 final long token = Binder.clearCallingIdentity();
4097 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004098 int slotId = getSlotIndexOrException(subId);
4099 verifyImsMmTelConfiguredOrThrow(slotId);
4100 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004101 } catch (ImsException e) {
4102 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 } finally {
4104 Binder.restoreCallingIdentity(token);
4105 }
4106 }
4107
shilu366312e2019-12-17 09:28:10 -08004108 /**
4109 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4110 * @param subId The subscription to use to check the configuration.
4111 * @param c The callback that will be used to send the result.
4112 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004114 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004115 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004116 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004117 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4118 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4119 }
Meng Wangafbc5852019-09-19 17:37:13 -07004120
4121 final long token = Binder.clearCallingIdentity();
4122 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004123 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004124 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004125 } catch (ImsException e) {
4126 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4127 + "is inactive, ignoring unregister.");
4128 // If the subscription is no longer active, just return, since the callback
4129 // will already have been removed internally.
4130 } finally {
4131 Binder.restoreCallingIdentity(token);
4132 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 }
4134
4135 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004136 public boolean isCapable(int subId, int capability, int regTech) {
4137 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 final long token = Binder.clearCallingIdentity();
4139 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004140 int slotId = getSlotIndexOrException(subId);
4141 verifyImsMmTelConfiguredOrThrow(slotId);
4142 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4145 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004146 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004147 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4148 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 } finally {
4150 Binder.restoreCallingIdentity(token);
4151 }
4152 }
4153
4154 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004155 public boolean isAvailable(int subId, int capability, int regTech) {
4156 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 final long token = Binder.clearCallingIdentity();
4158 try {
4159 Phone phone = getPhone(subId);
4160 if (phone == null) return false;
4161 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004162 } catch (com.android.ims.ImsException e) {
4163 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4164 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 } finally {
4166 Binder.restoreCallingIdentity(token);
4167 }
4168 }
4169
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004170 /**
4171 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4172 * subscription.
4173 * @param subId The subscription to use to check the configuration.
4174 * @param callback The callback that will be used to send the result.
4175 * @param capability The MmTelFeature capability that will be used to send the result.
4176 * @param transportType The transport type of the MmTelFeature capability.
4177 */
4178 @Override
4179 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4180 int transportType) {
4181 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4182 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4183 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4184 "IMS not available on device.");
4185 }
4186 final long token = Binder.clearCallingIdentity();
4187 try {
4188 int slotId = getSlotIndex(subId);
4189 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4190 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4191 + subId + "'");
4192 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4193 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004194 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004195 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4196 transportType, aBoolean -> {
4197 try {
4198 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4199 } catch (RemoteException e) {
4200 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4201 + "running. Ignore");
4202 }
4203 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004204 } catch (ImsException e) {
4205 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004206 } finally {
4207 Binder.restoreCallingIdentity(token);
4208 }
4209 }
4210
shilu366312e2019-12-17 09:28:10 -08004211 /**
4212 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4213 * @param subId The subscription to use to check the configuration.
4214 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 @Override
4216 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004217 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004218 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004219
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 final long token = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004223 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 } catch (ImsException e) {
4226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 } finally {
4228 Binder.restoreCallingIdentity(token);
4229 }
4230 }
4231
4232 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004233 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004235 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 final long identity = Binder.clearCallingIdentity();
4237 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004238 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004239 // This setting doesn't require an active ImsService connection, so do not verify. The
4240 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004241 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
shilu366312e2019-12-17 09:28:10 -08004249 /**
4250 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4251 * @param subId The subscription to use to check the configuration.
4252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004254 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004256 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 final long identity = Binder.clearCallingIdentity();
4258 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004260 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004262 } catch (ImsException e) {
4263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
4267 }
4268
4269 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004270 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004272 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004276 // This setting doesn't require an active ImsService connection, so do not verify. The
4277 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004279 } catch (ImsException e) {
4280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
4284 }
4285
shilu366312e2019-12-17 09:28:10 -08004286 /**
4287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4288 * @param subId The subscription to use to check the configuration.
4289 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 @Override
4291 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004292 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004293 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 final long identity = Binder.clearCallingIdentity();
4295 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004297 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004299 } catch (ImsException e) {
4300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
4304 }
4305
4306 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004307 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004309 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 final long identity = Binder.clearCallingIdentity();
4311 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004312 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004313 // This setting doesn't require an active ImsService connection, so do not verify. The
4314 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004316 } catch (ImsException e) {
4317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 }
4322
shilu366312e2019-12-17 09:28:10 -08004323 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004324 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 */
4328 @Override
4329 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004331 mApp, subId, "isCrossSimCallingEnabledByUser");
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
4342 }
4343
4344 /**
4345 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4346 * Requires MODIFY_PHONE_STATE permission.
4347 * @param subId The subscription to use to check the configuration.
4348 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4349 * false otherwise
4350 */
4351 @Override
4352 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4354 "setCrossSimCallingEnabled");
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004358 // This setting doesn't require an active ImsService connection, so do not verify. The
4359 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004361 } catch (ImsException e) {
4362 throw new ServiceSpecificException(e.getCode());
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
4366 }
4367
4368 /**
shilu366312e2019-12-17 09:28:10 -08004369 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4370 * @param subId The subscription to use to check the configuration.
4371 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004373
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004375 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004376 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 final long identity = Binder.clearCallingIdentity();
4378 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004380 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004382 } catch (ImsException e) {
4383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
4387 }
4388
4389 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004390 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004392 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 final long identity = Binder.clearCallingIdentity();
4394 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004396 // This setting doesn't require an active ImsService connection, so do not verify. The
4397 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004399 } catch (ImsException e) {
4400 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
4406 @Override
4407 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4409 "setVoWiFiNonPersistent");
4410 final long identity = Binder.clearCallingIdentity();
4411 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004413 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (ImsException e) {
4416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420 }
4421
shilu366312e2019-12-17 09:28:10 -08004422 /**
4423 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4424 * @param subId The subscription to use to check the configuration.
4425 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004426 @Override
4427 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004428 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004429 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 final long identity = Binder.clearCallingIdentity();
4431 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004433 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004434 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004435 } catch (ImsException e) {
4436 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
4440 }
4441
4442 @Override
4443 public void setVoWiFiModeSetting(int subId, int mode) {
4444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4445 "setVoWiFiModeSetting");
4446 final long identity = Binder.clearCallingIdentity();
4447 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004448 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004449 // This setting doesn't require an active ImsService connection, so do not verify. The
4450 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004452 } catch (ImsException e) {
4453 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
4457 }
4458
4459 @Override
4460 public int getVoWiFiRoamingModeSetting(int subId) {
4461 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004465 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004467 } catch (ImsException e) {
4468 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
4472 }
4473
4474 @Override
4475 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4477 "setVoWiFiRoamingModeSetting");
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004481 // This setting doesn't require an active ImsService connection, so do not verify. The
4482 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
4491 @Override
4492 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4494 "setRttCapabilityEnabled");
4495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004498 // This setting doesn't require an active ImsService connection, so do not verify. The
4499 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (ImsException e) {
4502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
shilu366312e2019-12-17 09:28:10 -08004508 /**
4509 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4510 * @param subId The subscription to use to check the configuration.
4511 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 @Override
4513 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004515 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 final long identity = Binder.clearCallingIdentity();
4517 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004519 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
4522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
4526 }
4527
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004528 @Override
4529 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4530 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4531 final long identity = Binder.clearCallingIdentity();
4532 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004533 if (!isImsAvailableOnDevice()) {
4534 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4535 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004536 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 int slotId = getSlotIndexOrException(subId);
4538 verifyImsMmTelConfiguredOrThrow(slotId);
4539 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004540 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 } catch (ImsException e) {
4542 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
4546 }
4547
4548 @Override
4549 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4550 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4551 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4554 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004555 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004556 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004557 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004559 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4560 + "is inactive, ignoring unregister.");
4561 // If the subscription is no longer active, just return, since the callback will already
4562 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
4566 }
4567
allenwtsu99c623b2020-01-03 18:24:23 +08004568
4569 private void checkModifyPhoneStatePermission(int subId, String message) {
4570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4571 message);
4572 }
4573
4574 private boolean isImsProvisioningRequired(int subId, int capability,
4575 boolean isMmtelCapability) {
4576 Phone phone = getPhone(subId);
4577 if (phone == null) {
4578 loge("phone instance null for subid " + subId);
4579 return false;
4580 }
4581 if (isMmtelCapability) {
4582 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4583 return false;
4584 }
4585 } else {
4586 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4587 return false;
4588 }
4589 }
4590 return true;
4591 }
4592
4593 @Override
4594 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4595 boolean isProvisioned) {
4596 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4597
4598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4601 if (!isImsProvisioningRequired(subId, capability, false)) {
4602 return;
4603 }
4604
4605 // this capability requires provisioning, route to the correct API.
4606 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4607 switch (capability) {
4608 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4609 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4610 ims.setEabProvisioned(isProvisioned);
4611 break;
4612 default: {
4613 throw new IllegalArgumentException("Tried to set provisioning for "
4614 + "rcs capability '" + capability + "', which does not require "
4615 + "provisioning.");
4616 }
4617 }
4618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
4621
4622 }
4623
4624
4625 @Override
4626 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4627 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4631 if (!isImsProvisioningRequired(subId, capability, false)) {
4632 return true;
4633 }
4634
4635 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4636 switch (capability) {
4637 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4638 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4639 return ims.isEabProvisionedOnDevice();
4640
4641 default: {
4642 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4643 + "capability '" + capability + "', which does not require "
4644 + "provisioning.");
4645 }
4646 }
4647
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
4651 }
4652
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4655 boolean isProvisioned) {
4656 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004657 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4658 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4661 }
allenwtsu99c623b2020-01-03 18:24:23 +08004662 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004663 final long identity = Binder.clearCallingIdentity();
4664 try {
4665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004666 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 return;
4668 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004669 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4670 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4671 loge("setImsProvisioningStatusForCapability: called for technology that does "
4672 + "not support provisioning - " + tech);
4673 return;
4674 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675
4676 // this capability requires provisioning, route to the correct API.
4677 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4678 switch (capability) {
4679 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4680 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4681 ims.setVolteProvisioned(isProvisioned);
4682 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4683 ims.setWfcProvisioned(isProvisioned);
4684 }
4685 break;
4686 }
4687 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4688 // There is currently no difference in VT provisioning type.
4689 ims.setVtProvisioned(isProvisioned);
4690 break;
4691 }
4692 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4693 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4694 // change the capability of the feature instead if needed.
4695 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4696 == isProvisioned) {
4697 // No change in provisioning.
4698 return;
4699 }
4700 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4701 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004702 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004703 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004704 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4705 + ", Exception" + e.getMessage());
4706 }
4707 break;
4708 }
4709 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004710 throw new IllegalArgumentException("Tried to set provisioning for "
4711 + "MmTel capability '" + capability + "', which does not require "
4712 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713 }
4714 }
4715
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
4719 }
4720
4721 @Override
4722 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4723 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004724 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4725 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4726 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4728 }
4729 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004733 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 return true;
4735 }
4736
Brad Ebinger0d79c572021-04-17 15:20:49 -07004737 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4738 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4739 loge("getImsProvisioningStatusForCapability: called for technology that does "
4740 + "not support provisioning - " + tech);
4741 return true;
4742 }
4743
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4745 switch (capability) {
4746 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4747 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4748 return ims.isVolteProvisionedOnDevice();
4749 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4750 return ims.isWfcProvisionedOnDevice();
4751 }
4752 // This should never happen, since we are checking tech above to make sure it
4753 // is either LTE or IWLAN.
4754 throw new IllegalArgumentException("Invalid radio technology for voice "
4755 + "capability.");
4756 }
4757 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4758 // There is currently no difference in VT provisioning type.
4759 return ims.isVtProvisionedOnDevice();
4760 }
4761 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4762 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4763 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4764 }
4765 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004766 throw new IllegalArgumentException(
4767 "Tried to get provisioning for MmTel capability '" + capability
4768 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004769 }
4770 }
4771
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
4774 }
4775 }
4776
4777 @Override
4778 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4779 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4780 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4781 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4782 }
4783 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4784 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4785 return (provisionedBits & capability) > 0;
4786 }
4787
4788 @Override
4789 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4790 boolean isProvisioned) {
4791 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4792 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4793 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4794 }
4795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4796 "setProvisioningStatusForCapability");
4797 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4798 // If the current provisioning status for capability already matches isProvisioned,
4799 // do nothing.
4800 if (((provisionedBits & capability) > 0) == isProvisioned) {
4801 return;
4802 }
4803 if (isProvisioned) {
4804 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4805 } else {
4806 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4807 }
4808 }
4809
4810 /**
4811 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4812 * technology. The bitfield should mirror the bitfield defined by
4813 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4814 */
4815 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4816 String key = getMmTelProvisioningKey(subId, tech);
4817 // Default is no capabilities are provisioned.
4818 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4819 }
4820
4821 /**
4822 * Sets the MmTel capability provisioning bitfield (defined by
4823 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4824 * technology specified.
4825 *
4826 * Note: This is a synchronous command and should not be called on UI thread.
4827 */
4828 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4829 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4830 String key = getMmTelProvisioningKey(subId, tech);
4831 editor.putInt(key, newField);
4832 editor.commit();
4833 }
4834
4835 private static String getMmTelProvisioningKey(int subId, int tech) {
4836 // resulting key is provision_ims_mmtel_{subId}_{tech}
4837 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4838 }
4839
4840 /**
4841 * Query CarrierConfig to see if the specified capability requires provisioning for the
4842 * carrier associated with the subscription id.
4843 */
4844 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4845 int capability) {
4846 CarrierConfigManager configManager = new CarrierConfigManager(context);
4847 PersistableBundle c = configManager.getConfigForSubId(subId);
4848 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004849 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4851 false);
4852 boolean requireVoiceVtProvisioning = c.getBoolean(
4853 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4854
4855 // First check to make sure that the capability requires provisioning.
4856 switch (capability) {
4857 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4858 // intentional fallthrough
4859 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4860 if (requireVoiceVtProvisioning) {
4861 // Voice and Video requires provisioning
4862 return true;
4863 }
4864 break;
4865 }
4866 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4867 if (requireUtProvisioning) {
4868 // UT requires provisioning
4869 return true;
4870 }
4871 break;
4872 }
4873 }
4874 return false;
4875 }
4876
allenwtsu99c623b2020-01-03 18:24:23 +08004877 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4878 int capability) {
4879 CarrierConfigManager configManager = new CarrierConfigManager(context);
4880 PersistableBundle c = configManager.getConfigForSubId(subId);
4881
4882 boolean requireRcsProvisioning = c.getBoolean(
4883 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4884
4885 // First check to make sure that the capability requires provisioning.
4886 switch (capability) {
4887 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4888 // intentional fallthrough
4889 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4890 if (requireRcsProvisioning) {
4891 // OPTION or PRESENCE requires provisioning
4892 return true;
4893 }
4894 break;
4895 }
4896 }
4897 return false;
4898 }
4899
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004901 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4903 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4904 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004905 enforceReadPrivilegedPermission("getImsProvisioningInt");
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909 int slotId = getSlotIndex(subId);
4910 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4911 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4912 + subId + "' for key:" + key);
4913 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4914 }
calvinpanb5a34062021-02-08 19:59:36 +08004915 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004916 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4918 + subId + "' for key:" + key);
4919 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
4925 @Override
4926 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4928 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4929 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004930 enforceReadPrivilegedPermission("getImsProvisioningString");
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004934 int slotId = getSlotIndex(subId);
4935 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4936 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4937 + subId + "' for key:" + key);
4938 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4939 }
calvinpanb5a34062021-02-08 19:59:36 +08004940 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004941 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004942 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4943 + subId + "' for key:" + key);
4944 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
4948 }
4949
4950 @Override
4951 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4953 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4954 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4956 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 int slotId = getSlotIndex(subId);
4961 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4962 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4963 + subId + "' for key:" + key);
4964 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4965 }
calvinpanb5a34062021-02-08 19:59:36 +08004966 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4967 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004969 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
4974 }
4975
4976 @Override
4977 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004978 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4979 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4980 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4982 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004986 int slotId = getSlotIndex(subId);
4987 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4988 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4989 + subId + "' for key:" + key);
4990 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4991 }
calvinpanb5a34062021-02-08 19:59:36 +08004992 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4993 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004994 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004995 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
5000 }
5001
Brad Ebinger919631e2021-06-02 17:46:35 -07005002 /**
5003 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5004 * for the given slot ID or no ImsResolver instance has been created.
5005 * @param slotId The slot ID that the IMS service is created for.
5006 * @throws ImsException If there is no ImsService configured for this slot.
5007 */
5008 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5009 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5010 ImsFeature.FEATURE_MMTEL)) {
5011 throw new ImsException("This subscription does not support MMTEL over IMS",
5012 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5013 }
5014 }
5015
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005016 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005017 int slotId = SubscriptionManager.getSlotIndex(subId);
5018 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005019 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5020 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005021 }
5022 return slotId;
5023 }
5024
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 private int getSlotIndex(int subId) {
5026 int slotId = SubscriptionManager.getSlotIndex(subId);
5027 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5028 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5029 }
5030 return slotId;
5031 }
5032
Wink Saville36469e72014-06-11 15:17:00 -07005033 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005034 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005035 */
5036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005037 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5038 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005039 try {
5040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5041 } catch (SecurityException se) {
5042 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5043 throw new SecurityException("Package " + callingPackage + " does not belong to "
5044 + Binder.getCallingUid());
5045 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005046 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005047 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005048 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005049 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005050 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005051 mApp, subId, callingPackage, callingFeatureId,
5052 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005053 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5054 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 final Phone phone = getPhone(subId);
5059 if (phone != null) {
5060 return phone.getServiceState().getDataNetworkType();
5061 } else {
5062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005067 }
5068
5069 /**
5070 * Returns the data network type
5071 */
5072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005073 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005074 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5075 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005076 }
5077
5078 /**
5079 * Returns the data network type for a subId
5080 */
5081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005082 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5083 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005085 mApp, subId, callingPackage, callingFeatureId,
5086 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5088 }
5089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 final Phone phone = getPhone(subId);
5093 if (phone != null) {
5094 return phone.getServiceState().getDataNetworkType();
5095 } else {
5096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005101 }
5102
5103 /**
Wink Saville36469e72014-06-11 15:17:00 -07005104 * Returns the Voice network type for a subId
5105 */
5106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005107 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5108 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005110 mApp, subId, callingPackage, callingFeatureId,
5111 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5113 }
5114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 final Phone phone = getPhone(subId);
5118 if (phone != null) {
5119 return phone.getServiceState().getVoiceNetworkType();
5120 } else {
5121 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5122 }
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005126 }
5127
5128 /**
5129 * @return true if a ICC card is present
5130 */
5131 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005132 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005133 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5134 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005135 }
5136
5137 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005138 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005139 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005140 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005141 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 final Phone phone = PhoneFactory.getPhone(slotIndex);
5145 if (phone != null) {
5146 return phone.getIccCard().hasIccCard();
5147 } else {
5148 return false;
5149 }
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005153 }
5154
5155 /**
5156 * Return if the current radio is LTE on CDMA. This
5157 * is a tri-state return value as for a period of time
5158 * the mode may be unknown.
5159 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005160 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005162 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005163 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005165 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5166 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5167 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005168 }
5169
Sanket Padawe356d7632015-06-22 14:03:32 -07005170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005171 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5172 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005173 try {
5174 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5175 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005176 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5177 }
5178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 final Phone phone = getPhone(subId);
5182 if (phone == null) {
5183 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5184 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005185 return TelephonyProperties.lte_on_cdma_device()
5186 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 }
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005190 }
Wink Saville36469e72014-06-11 15:17:00 -07005191 }
5192
Wink Saville36469e72014-06-11 15:17:00 -07005193 /**
5194 * {@hide}
5195 * Returns Default subId, 0 in the case of single standby.
5196 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005197 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005198 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005199 }
5200
Shishir Agrawala9f32182016-04-12 12:00:16 -07005201 private int getSlotForDefaultSubscription() {
5202 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5203 }
5204
Wink Savilleb564aae2014-10-23 10:18:09 -07005205 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005206 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005207 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005208
Pengquan Menge92a50d2018-09-21 15:54:48 -07005209 private boolean isActiveSubscription(int subId) {
5210 return mSubscriptionController.isActiveSubId(subId);
5211 }
5212
Ihab Awadf2177b72013-11-25 13:33:23 -08005213 /**
5214 * @see android.telephony.TelephonyManager.WifiCallingChoices
5215 */
5216 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 final long identity = Binder.clearCallingIdentity();
5218 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5221 getWhenToMakeWifiCallsDefaultPreference());
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005225 }
5226
5227 /**
5228 * @see android.telephony.TelephonyManager.WifiCallingChoices
5229 */
5230 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005239 }
5240
Sailesh Nepald1e68152013-12-12 19:08:02 -08005241 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005242 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005243 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005244 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005245
Jordan Liu4c733742019-02-28 12:03:40 -08005246 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5247 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5248 if (phoneId == -1) {
5249 throw new IllegalArgumentException("Given slot index: " + slotIndex
5250 + " does not correspond to an active phone");
5251 }
5252 return PhoneFactory.getPhone(phoneId);
5253 }
5254
Shishir Agrawal566b7612013-10-28 14:41:00 -07005255 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005256 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5257 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5259 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005261 if (DBG) {
5262 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5263 }
5264 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5265 p2);
5266 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005267
Jordan Liu4c733742019-02-28 12:03:40 -08005268
5269 @Override
5270 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5271 int slotIndex, String callingPackage, String aid, int p2) {
5272 enforceModifyPermission();
5273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5274 if (DBG) {
5275 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5276 }
5277 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5278 callingPackage, aid, p2);
5279 }
5280
5281 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5282 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 if (TextUtils.equals(ISDR_AID, aid)) {
5286 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005287 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5288 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 if (bestComponent == null
5290 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5291 loge("The calling package is not allowed to access ISD-R.");
5292 throw new SecurityException(
5293 "The calling package is not allowed to access ISD-R.");
5294 }
Derek Tan740e1672017-06-27 14:56:27 -07005295 }
Derek Tan740e1672017-06-27 14:56:27 -07005296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005298 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5299 null /* workSource */);
5300 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 return response;
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005305 }
5306
5307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005308 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005311 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5312 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5313 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005314
Jordan Liu4c733742019-02-28 12:03:40 -08005315 @Override
5316 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5317 enforceModifyPermission();
5318 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5319 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5320 channel);
5321 }
5322
5323 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 if (channel < 0) {
5327 return false;
5328 }
Jordan Liu4c733742019-02-28 12:03:40 -08005329 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5330 null /* workSource */);
5331 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 return success;
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005335 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005336 }
5337
5338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005339 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005340 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5342 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005343 if (DBG) {
5344 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5345 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5346 + p3 + " data=" + data);
5347 }
5348 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5349 command, p1, p2, p3, data);
5350 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005351
Jordan Liu4c733742019-02-28 12:03:40 -08005352 @Override
5353 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5354 int command, int p1, int p2, int p3, String data) {
5355 enforceModifyPermission();
5356 if (DBG) {
5357 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5358 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5359 + p3 + " data=" + data);
5360 }
5361 return iccTransmitApduLogicalChannelWithPermission(
5362 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5363 data);
5364 }
5365
5366 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5367 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 final long identity = Binder.clearCallingIdentity();
5369 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005370 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 return "";
5372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005375 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5376 null /* workSource */);
5377 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 // Append the returned status code to the end of the response payload.
5380 String s = Integer.toHexString(
5381 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5382 if (response.payload != null) {
5383 s = IccUtils.bytesToHexString(response.payload) + s;
5384 }
5385 return s;
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005388 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005389 }
Jake Hambye994d462014-02-03 13:10:13 -08005390
Evan Charltonc66da362014-05-16 14:06:40 -07005391 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005392 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5393 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5395 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005397 if (DBG) {
5398 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5399 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5400 }
5401 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5402 cla, command, p1, p2, p3, data);
5403 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005404
Jordan Liu4c733742019-02-28 12:03:40 -08005405 @Override
5406 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5407 int command, int p1, int p2, int p3, String data) {
5408 enforceModifyPermission();
5409 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5410 if (DBG) {
5411 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5412 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5413 + " data=" + data);
5414 }
5415
5416 return iccTransmitApduBasicChannelWithPermission(
5417 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5418 p2, p3, data);
5419 }
5420
5421 // open APDU basic channel assuming the caller has sufficient permissions
5422 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5423 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5427 && TextUtils.equals(ISDR_AID, data)) {
5428 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005429 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5430 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 if (bestComponent == null
5432 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5433 loge("The calling package is not allowed to select ISD-R.");
5434 throw new SecurityException(
5435 "The calling package is not allowed to select ISD-R.");
5436 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005437 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005440 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5441 null /* workSource */);
5442 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 // Append the returned status code to the end of the response payload.
5445 String s = Integer.toHexString(
5446 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5447 if (response.payload != null) {
5448 s = IccUtils.bytesToHexString(response.payload) + s;
5449 }
5450 return s;
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005453 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005454 }
5455
5456 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005457 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005458 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5460 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 if (DBG) {
5465 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5466 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5467 }
5468
5469 IccIoResult response =
5470 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5471 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5472 subId);
5473
5474 if (DBG) {
5475 log("Exchange SIM_IO [R]" + response);
5476 }
5477
5478 byte[] result = null;
5479 int length = 2;
5480 if (response.payload != null) {
5481 length = 2 + response.payload.length;
5482 result = new byte[length];
5483 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5484 } else {
5485 result = new byte[length];
5486 }
5487
5488 result[length - 1] = (byte) response.sw2;
5489 result[length - 2] = (byte) response.sw1;
5490 return result;
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005493 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005494 }
5495
Nathan Haroldb3014052017-01-25 15:57:32 -08005496 /**
5497 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5498 * on a particular subscription
5499 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005500 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5501 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005503 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005504 return null;
5505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 if (appType != TelephonyManager.APPTYPE_USIM
5510 && appType != TelephonyManager.APPTYPE_SIM) {
5511 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5512 return null;
5513 }
5514 Object response = sendRequest(
5515 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5516 if (response instanceof String[]) {
5517 return (String[]) response;
5518 }
yincheng zhao2737e882019-09-06 17:06:54 -07005519 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005521 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 } finally {
5523 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005524 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005525 }
5526
yincheng zhao2737e882019-09-06 17:06:54 -07005527 /**
5528 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5529 * subscription.
5530 *
5531 * @param subId the id of the subscription.
5532 * @param appType the uicc app type, must be USIM or SIM.
5533 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5534 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005535 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005536 * @return number of fplmns that is successfully written to the SIM.
5537 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005538 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5539 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5541 mApp, subId, "setForbiddenPlmns");
5542
yincheng zhao2737e882019-09-06 17:06:54 -07005543 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5544 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5545 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5546 }
5547 if (fplmns == null) {
5548 throw new IllegalArgumentException("Fplmn List provided is null");
5549 }
5550 for (String fplmn : fplmns) {
5551 if (!CellIdentity.isValidPlmn(fplmn)) {
5552 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5553 }
5554 }
5555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 Object response = sendRequest(
5558 CMD_SET_FORBIDDEN_PLMNS,
5559 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5560 subId);
5561 return (int) response;
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
5564 }
5565 }
5566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005567 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005568 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5570 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 final long identity = Binder.clearCallingIdentity();
5573 try {
5574 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5575 if (response.payload == null) {
5576 return "";
5577 }
Evan Charltonc66da362014-05-16 14:06:40 -07005578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 // Append the returned status code to the end of the response payload.
5580 String s = Integer.toHexString(
5581 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5582 s = IccUtils.bytesToHexString(response.payload) + s;
5583 return s;
5584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Evan Charltonc66da362014-05-16 14:06:40 -07005587 }
5588
Jake Hambye994d462014-02-03 13:10:13 -08005589 /**
5590 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5591 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5592 *
5593 * @param itemID the ID of the item to read
5594 * @return the NV item as a String, or null on error.
5595 */
5596 @Override
5597 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5600 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601
5602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005605 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5607 return value;
5608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Jake Hambye994d462014-02-03 13:10:13 -08005611 }
5612
5613 /**
5614 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5615 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5616 *
5617 * @param itemID the ID of the item to read
5618 * @param itemValue the value to write, as a String
5619 * @return true on success; false on any failure
5620 */
5621 @Override
5622 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005623 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5625 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626
5627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5630 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005631 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5633 return success;
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Jake Hambye994d462014-02-03 13:10:13 -08005637 }
5638
5639 /**
5640 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5641 * Used for device configuration by some CDMA operators.
5642 *
5643 * @param preferredRoamingList byte array containing the new PRL
5644 * @return true on success; false on any failure
5645 */
5646 @Override
5647 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5649 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650
5651 final long identity = Binder.clearCallingIdentity();
5652 try {
5653 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5654 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5655 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5656 return success;
5657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Jake Hambye994d462014-02-03 13:10:13 -08005660 }
5661
5662 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005663 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005664 * Used for device configuration by some CDMA operators.
5665 *
chen xu6dac5ab2018-10-26 17:39:23 -07005666 * @param slotIndex - device slot.
5667 *
Jake Hambye994d462014-02-03 13:10:13 -08005668 * @return true on success; false on any failure
5669 */
5670 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005671 public boolean resetModemConfig(int slotIndex) {
5672 Phone phone = PhoneFactory.getPhone(slotIndex);
5673 if (phone != null) {
5674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5675 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676
chen xu6dac5ab2018-10-26 17:39:23 -07005677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5680 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5681 return success;
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 }
chen xu6dac5ab2018-10-26 17:39:23 -07005686 return false;
5687 }
5688
5689 /**
5690 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5691 *
5692 * @param slotIndex - device slot.
5693 *
5694 * @return true on success; false on any failure
5695 */
5696 @Override
5697 public boolean rebootModem(int slotIndex) {
5698 Phone phone = PhoneFactory.getPhone(slotIndex);
5699 if (phone != null) {
5700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5701 mApp, phone.getSubId(), "rebootModem");
5702
5703 final long identity = Binder.clearCallingIdentity();
5704 try {
5705 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5706 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5707 return success;
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
5711 }
5712 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005713 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005714
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 public String[] getPcscfAddress(String apnType, String callingPackage,
5716 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005717 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5719 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005720 return new String[0];
5721 }
5722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 final long identity = Binder.clearCallingIdentity();
5724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Wink Saville36469e72014-06-11 15:17:00 -07005729 }
5730
Brad Ebinger51f743a2017-01-23 13:50:20 -08005731 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005732 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5733 * {@link #disableIms(int)}.
5734 * @param slotIndex device slot.
5735 */
5736 public void resetIms(int slotIndex) {
5737 enforceModifyPermission();
5738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 if (mImsResolver == null) {
5742 // may happen if the does not support IMS.
5743 return;
5744 }
5745 mImsResolver.disableIms(slotIndex);
5746 mImsResolver.enableIms(slotIndex);
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
5750 }
5751
5752 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005753 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5754 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005755 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005756 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005761 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005762 // may happen if the device does not support IMS.
5763 return;
5764 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005765 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005769 }
5770
5771 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005772 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5773 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005774 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005775 public void disableIms(int slotId) {
5776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777
5778 final long identity = Binder.clearCallingIdentity();
5779 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005780 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005781 // may happen if the device does not support IMS.
5782 return;
5783 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005784 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005788 }
5789
5790 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005791 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5792 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005793 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005794 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005795 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797
5798 final long identity = Binder.clearCallingIdentity();
5799 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005800 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005801 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5802 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005803 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005804 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005808 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005809 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005810 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5811 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005812 @Override
5813 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005814 enforceModifyPermission();
5815
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005819 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
5823 }
5824
5825 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005826 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005827 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005828 */
5829 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5830 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831
5832 final long identity = Binder.clearCallingIdentity();
5833 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005835 // may happen if the device does not support IMS.
5836 return null;
5837 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005838 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005842 }
5843
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005844 /**
5845 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005846 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005847 */
5848 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5849 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850
5851 final long identity = Binder.clearCallingIdentity();
5852 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005853 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005854 // may happen if the device does not support IMS.
5855 return null;
5856 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005861 }
5862
Brad Ebinger884c07b2018-02-15 16:17:40 -08005863 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005864 * Sets the ImsService Package Name that Telephony will bind to.
5865 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 * @param slotIndex the slot ID that the ImsService should bind for.
5867 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005868 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 * @param featureTypes An integer array of feature types associated with a packageName.
5870 * @param packageName The name of the package that the current configuration will be replaced
5871 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005872 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5875 int[] featureTypes, String packageName) {
5876 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5879 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005884 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005885 // may happen if the device does not support IMS.
5886 return false;
5887 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005888 Map<Integer, String> featureConfig = new HashMap<>();
5889 for (int featureType : featureTypes) {
5890 featureConfig.put(featureType, packageName);
5891 }
5892 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5893 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005897 }
5898
5899 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005900 * Clears any carrier ImsService overrides for the slot index specified that were previously
5901 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5902 *
5903 * This should only be used for testing.
5904 *
5905 * @param slotIndex the slot ID that the ImsService should bind for.
5906 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5907 */
5908 @Override
5909 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5910 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5912 "clearCarrierImsServiceOverride");
5913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5914 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5915 "clearCarrierImsServiceOverride");
5916
5917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 if (mImsResolver == null) {
5920 // may happen if the device does not support IMS.
5921 return false;
5922 }
5923 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
5927 }
5928
5929 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005931 *
5932 * @param slotId The slot that the ImsService is associated with.
5933 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5934 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005936 * @return the package name of the ImsService configuration.
5937 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5939 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005940 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005942 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005943 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5944 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 final long identity = Binder.clearCallingIdentity();
5947 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005948 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005949 // may happen if the device does not support IMS.
5950 return "";
5951 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005952 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005953 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5954 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005958 }
5959
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005960 /**
5961 * Get the MmTelFeature state associated with the requested subscription id.
5962 * @param subId The subscription that the MmTelFeature is associated with.
5963 * @param callback A callback with an integer containing the
5964 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5965 */
5966 @Override
5967 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5968 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5969 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5970 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5971 "IMS not available on device.");
5972 }
5973 final long token = Binder.clearCallingIdentity();
5974 try {
5975 int slotId = getSlotIndex(subId);
5976 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5977 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5978 + subId + "'");
5979 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5980 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005981 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005982 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5983 try {
5984 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5985 } catch (RemoteException e) {
5986 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5987 + "Ignore");
5988 }
5989 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005990 } catch (ImsException e) {
5991 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005992 } finally {
5993 Binder.restoreCallingIdentity(token);
5994 }
5995 }
5996
Daniel Brightbb5840b2021-01-12 15:48:18 -08005997 /**
5998 * Sets the ims registration state on all valid {@link Phone}s.
5999 */
6000 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002
6003 final long identity = Binder.clearCallingIdentity();
6004 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006005 // NOTE: Before S, this method only set the default phone.
6006 for (final Phone phone : PhoneFactory.getPhones()) {
6007 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6008 phone.setImsRegistrationState(registered);
6009 }
6010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
Wink Saville36469e72014-06-11 15:17:00 -07006014 }
6015
6016 /**
Stuart Scott54788802015-03-30 13:18:01 -07006017 * Set the network selection mode to automatic.
6018 *
6019 */
6020 @Override
6021 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6023 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024
6025 final long identity = Binder.clearCallingIdentity();
6026 try {
shilufc958392020-01-20 11:36:01 -08006027 if (!isActiveSubscription(subId)) {
6028 return;
6029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006031 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6032 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
Stuart Scott54788802015-03-30 13:18:01 -07006036 }
6037
Jack Yud10cdd42020-09-28 20:28:01 -07006038 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006039 * Ask the radio to connect to the input network and change selection mode to manual.
6040 *
6041 * @param subId the id of the subscription.
6042 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6043 * the operator to attach to.
6044 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6045 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6046 * normal network selection next time.
6047 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006048 */
6049 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006050 public boolean setNetworkSelectionModeManual(
6051 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6053 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006054
6055 if (!isActiveSubscription(subId)) {
6056 return false;
6057 }
6058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 final long identity = Binder.clearCallingIdentity();
6060 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006061 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006063 if (DBG) {
6064 log("setNetworkSelectionModeManual: subId: " + subId
6065 + " operator: " + operatorInfo);
6066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006071 }
shilu84f6e8b2019-12-19 13:58:01 -08006072 /**
6073 * Get the manual network selection
6074 *
6075 * @param subId the id of the subscription.
6076 *
6077 * @return the previously saved user selected PLMN
6078 */
6079 @Override
6080 public String getManualNetworkSelectionPlmn(int subId) {
6081 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006082 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006083 mApp, subId, "getManualNetworkSelectionPlmn");
6084
6085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006088 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006089 }
6090
6091 final Phone phone = getPhone(subId);
6092 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006093 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006094 }
6095 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6096 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6097 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
6100 }
6101 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006102
6103 /**
6104 * Scans for available networks.
6105 */
6106 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006107 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6108 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6110 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006111 LocationAccessPolicy.LocationPermissionResult locationResult =
6112 LocationAccessPolicy.checkLocationPermission(mApp,
6113 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6114 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006115 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006116 .setCallingPid(Binder.getCallingPid())
6117 .setCallingUid(Binder.getCallingUid())
6118 .setMethod("getCellNetworkScanResults")
6119 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006120 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6121 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006122 .build());
6123 switch (locationResult) {
6124 case DENIED_HARD:
6125 throw new SecurityException("Not allowed to access scan results -- location");
6126 case DENIED_SOFT:
6127 return null;
6128 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129
Pengquan Menga1bb6272018-09-06 09:59:22 -07006130 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 try {
6132 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006133 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006138 }
6139
6140 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006141 * Get the call forwarding info, given the call forwarding reason.
6142 */
6143 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006144 public void getCallForwarding(int subId, int callForwardingReason,
6145 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006146 enforceReadPrivilegedPermission("getCallForwarding");
6147 long identity = Binder.clearCallingIdentity();
6148 try {
6149 if (DBG) {
6150 log("getCallForwarding: subId " + subId
6151 + " callForwardingReason" + callForwardingReason);
6152 }
Hall Liu27d24262020-09-18 19:04:59 -07006153
6154 Phone phone = getPhone(subId);
6155 if (phone == null) {
6156 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006157 callback.onError(
6158 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006159 } catch (RemoteException e) {
6160 // ignore
6161 }
6162 return;
6163 }
6164
6165 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6166 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6167 @Override
6168 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6169 try {
6170 callback.onCallForwardingInfoAvailable(info);
6171 } catch (RemoteException e) {
6172 // ignore
6173 }
6174 }
6175
6176 @Override
6177 public void onError(int error) {
6178 try {
6179 callback.onError(error);
6180 } catch (RemoteException e) {
6181 // ignore
6182 }
6183 }
6184 });
6185 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
6189 }
6190
6191 /**
6192 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6193 * reason, the number to forward, and the timeout before the forwarding is attempted.
6194 */
6195 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006196 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6197 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006198 enforceModifyPermission();
6199 long identity = Binder.clearCallingIdentity();
6200 try {
6201 if (DBG) {
6202 log("setCallForwarding: subId " + subId
6203 + " callForwardingInfo" + callForwardingInfo);
6204 }
Hall Liu27d24262020-09-18 19:04:59 -07006205
6206 Phone phone = getPhone(subId);
6207 if (phone == null) {
6208 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006209 callback.accept(
6210 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006211 } catch (RemoteException e) {
6212 // ignore
6213 }
6214 return;
6215 }
6216
6217 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6218 FunctionalUtils.ignoreRemoteException(callback::accept));
6219
6220 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006221 } finally {
6222 Binder.restoreCallingIdentity(identity);
6223 }
6224 }
6225
6226 /**
Hall Liu27d24262020-09-18 19:04:59 -07006227 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006228 */
6229 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006230 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006231 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006232 long identity = Binder.clearCallingIdentity();
6233 try {
Hall Liu27d24262020-09-18 19:04:59 -07006234 Phone phone = getPhone(subId);
6235 if (phone == null) {
6236 try {
6237 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6238 } catch (RemoteException e) {
6239 // ignore
6240 }
6241 return;
6242 }
SongFerngWang0e767992021-03-31 22:08:45 +08006243 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6244 PersistableBundle c = configManager.getConfigForSubId(subId);
6245 boolean requireUssd = c.getBoolean(
6246 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006247
Shuo Qian4a594052020-01-23 11:59:30 -08006248 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006249 if (requireUssd) {
6250 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6251 getSubscriptionCarrierId(subId));
6252 String newUssdCommand = "";
6253 try {
6254 newUssdCommand = carrierXmlParser.getFeature(
6255 CarrierXmlParser.FEATURE_CALL_WAITING)
6256 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6257 } catch (NullPointerException e) {
6258 loge("Failed to generate USSD number" + e);
6259 }
6260 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6261 mMainThreadHandler, callback, carrierXmlParser,
6262 CarrierXmlParser.SsEntry.SSAction.QUERY);
6263 final String ussdCommand = newUssdCommand;
6264 Executors.newSingleThreadExecutor().execute(() -> {
6265 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6266 });
6267 } else {
6268 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6269 callback::accept);
6270 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6271 }
Shuo Qian4a594052020-01-23 11:59:30 -08006272 } finally {
6273 Binder.restoreCallingIdentity(identity);
6274 }
6275 }
6276
6277 /**
Hall Liu27d24262020-09-18 19:04:59 -07006278 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006279 */
6280 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006281 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006282 enforceModifyPermission();
6283 long identity = Binder.clearCallingIdentity();
6284 try {
Hall Liu27d24262020-09-18 19:04:59 -07006285 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6286
6287 Phone phone = getPhone(subId);
6288 if (phone == null) {
6289 try {
6290 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6291 } catch (RemoteException e) {
6292 // ignore
6293 }
6294 return;
6295 }
6296
SongFerngWang0e767992021-03-31 22:08:45 +08006297 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6298 PersistableBundle c = configManager.getConfigForSubId(subId);
6299 boolean requireUssd = c.getBoolean(
6300 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006301
SongFerngWang0e767992021-03-31 22:08:45 +08006302 if (DBG) log("getCallWaitingStatus: subId " + subId);
6303 if (requireUssd) {
6304 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6305 getSubscriptionCarrierId(subId));
6306 CarrierXmlParser.SsEntry.SSAction ssAction =
6307 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6308 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6309 String newUssdCommand = "";
6310 try {
6311 newUssdCommand = carrierXmlParser.getFeature(
6312 CarrierXmlParser.FEATURE_CALL_WAITING)
6313 .makeCommand(ssAction, null);
6314 } catch (NullPointerException e) {
6315 loge("Failed to generate USSD number" + e);
6316 }
6317 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6318 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6319 final String ussdCommand = newUssdCommand;
6320 Executors.newSingleThreadExecutor().execute(() -> {
6321 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6322 });
6323 } else {
6324 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6325 FunctionalUtils.ignoreRemoteException(callback::accept));
6326
6327 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6328 }
Shuo Qian4a594052020-01-23 11:59:30 -08006329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 }
6333
6334 /**
yinxub1bed742017-04-17 11:45:04 -07006335 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006336 *
yinxub1bed742017-04-17 11:45:04 -07006337 * @param subId id of the subscription
6338 * @param request contains the radio access networks with bands/channels to scan
6339 * @param messenger callback messenger for scan results or errors
6340 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006341 * @return the id of the requested scan which can be used to stop the scan.
6342 */
6343 @Override
6344 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006345 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6347 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006348 LocationAccessPolicy.LocationPermissionResult locationResult =
6349 LocationAccessPolicy.checkLocationPermission(mApp,
6350 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6351 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006352 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006353 .setCallingPid(Binder.getCallingPid())
6354 .setCallingUid(Binder.getCallingUid())
6355 .setMethod("requestNetworkScan")
6356 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006357 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6358 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006359 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006360 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006361 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6362 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006363 if (e != null) {
6364 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6365 throw e;
6366 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006367 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006368 return TelephonyScanManager.INVALID_SCAN_ID;
6369 }
6370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 }
Hall Liu912dfd32019-04-25 14:02:26 -07006372 int callingUid = Binder.getCallingUid();
6373 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 return mNetworkScanRequestTracker.startNetworkScan(
6377 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006378 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
yinxu504e1392017-04-12 16:03:22 -07006382 }
6383
Hall Liub2ac8ef2019-02-28 15:56:23 -08006384 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006385 NetworkScanRequest request, int subId, String callingPackage) {
6386 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006387 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6388 boolean hasNetworkScanPermission =
6389 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6390 == PERMISSION_GRANTED;
6391
6392 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6393 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6394 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006395 }
6396
6397 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6398 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006399 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6400 return new SecurityException("Specific channels must not be"
6401 + " scanned without location access.");
6402 }
6403 }
6404 }
6405
Hall Liub2ac8ef2019-02-28 15:56:23 -08006406 return null;
6407 }
6408
yinxu504e1392017-04-12 16:03:22 -07006409 /**
6410 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006411 *
6412 * @param subId id of the subscription
6413 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006414 */
6415 @Override
6416 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6418 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419
Hall Liu912dfd32019-04-25 14:02:26 -07006420 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 final long identity = Binder.clearCallingIdentity();
6422 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006423 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
yinxu504e1392017-04-12 16:03:22 -07006427 }
6428
6429 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006430 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006431 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006432 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006433 */
6434 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006435 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006436 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006437 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006438 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439
6440 final long identity = Binder.clearCallingIdentity();
6441 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006442 if (DBG) log("getAllowedNetworkTypesBitmask");
6443 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6444 int networkTypesBitmask = (result != null ? result[0] : -1);
6445 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6446 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006450 }
6451
6452 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006453 * Get the allowed network types for certain reason.
6454 *
6455 * @param subId the id of the subscription.
6456 * @param reason the reason the allowed network type change is taking place
6457 * @return the allowed network types.
6458 */
6459 @Override
6460 public long getAllowedNetworkTypesForReason(int subId,
6461 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006462 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006463 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006473 * Enable/Disable E-UTRA-NR Dual Connectivity
6474 * @param subId subscription id of the sim card
6475 * @param nrDualConnectivityState expected NR dual connectivity state
6476 * This can be passed following states
6477 * <ol>
6478 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6479 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6480 * <li>Disable NR dual connectivity and force secondary cell to be released
6481 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6482 * </ol>
6483 * @return operation result.
6484 */
6485 @Override
6486 public int setNrDualConnectivityState(int subId,
6487 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6489 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006490 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006491 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6492 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6493 }
6494
Sooraj Sasindran37444802020-08-11 10:40:43 -07006495 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6499 nrDualConnectivityState, subId,
6500 workSource);
6501 if (DBG) log("enableNRDualConnectivity result: " + result);
6502 return result;
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 /**
6509 * Is E-UTRA-NR Dual Connectivity enabled
6510 * @return true if dual connectivity is enabled else false
6511 */
6512 @Override
6513 public boolean isNrDualConnectivityEnabled(int subId) {
6514 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006515 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006516 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006517 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006518 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6519 return false;
6520 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6522 final long identity = Binder.clearCallingIdentity();
6523 try {
6524 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6525 null, subId, workSource);
6526 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6527 return isEnabled;
6528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
6531 }
6532
6533 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006534 * Set the allowed network types of the device and
6535 * provide the reason triggering the allowed network change.
6536 *
6537 * @param subId the id of the subscription.
6538 * @param reason the reason the allowed network type change is taking place
6539 * @param allowedNetworkTypes the allowed network types.
6540 * @return true on success; false on any failure.
6541 */
6542 @Override
6543 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006544 @TelephonyManager.AllowedNetworkTypesReason int reason,
6545 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6547 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006548 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006549 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6550 return false;
6551 }
6552 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6553 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 return false;
6555 }
6556
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006557 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6558 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6559
6560
6561 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6562 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6563 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006564 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006565
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006566 final long identity = Binder.clearCallingIdentity();
6567 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006568 Boolean success = (Boolean) sendRequest(
6569 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6570 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6571
6572 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6573 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
6577 }
6578
6579 /**
Miaoa84611c2019-03-15 09:21:10 +08006580 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006581 *
Miaoa84611c2019-03-15 09:21:10 +08006582 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006583 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006584 * @hide
6585 */
6586 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006587 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006590 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 try {
Miaoa84611c2019-03-15 09:21:10 +08006592 if (phone != null) {
6593 return phone.hasMatchedTetherApnSetting();
6594 } else {
6595 return false;
6596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 } finally {
6598 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006599 }
Junda Liu475951f2014-11-07 16:45:03 -08006600 }
6601
6602 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006603 * Get the user enabled state of Mobile Data.
6604 *
6605 * TODO: remove and use isUserDataEnabled.
6606 * This can't be removed now because some vendor codes
6607 * calls through ITelephony directly while they should
6608 * use TelephonyManager.
6609 *
6610 * @return true on enabled
6611 */
6612 @Override
6613 public boolean getDataEnabled(int subId) {
6614 return isUserDataEnabled(subId);
6615 }
6616
6617 /**
6618 * Get whether mobile data is enabled per user setting.
6619 *
6620 * There are other factors deciding whether mobile data is actually enabled, but they are
6621 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006622 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006623 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006624 *
6625 * @return {@code true} if data is enabled else {@code false}
6626 */
6627 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006628 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006629 try {
6630 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6631 null);
6632 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6634 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 int phoneId = mSubscriptionController.getPhoneId(subId);
6640 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6641 Phone phone = PhoneFactory.getPhone(phoneId);
6642 if (phone != null) {
6643 boolean retVal = phone.isUserDataEnabled();
6644 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6645 return retVal;
6646 } else {
6647 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6648 return false;
6649 }
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006652 }
6653 }
6654
6655 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006656 * Checks if the device is capable of mobile data by considering whether whether the
6657 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6658 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006659 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006660 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006661 */
6662 @Override
6663 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006664 try {
6665 try {
6666 mApp.enforceCallingOrSelfPermission(
6667 android.Manifest.permission.ACCESS_NETWORK_STATE,
6668 null);
6669 } catch (Exception e) {
6670 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6671 "isDataEnabled");
6672 }
6673 } catch (Exception e) {
6674 enforceReadPrivilegedPermission("isDataEnabled");
6675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676
6677 final long identity = Binder.clearCallingIdentity();
6678 try {
6679 int phoneId = mSubscriptionController.getPhoneId(subId);
6680 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6681 Phone phone = PhoneFactory.getPhone(phoneId);
6682 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006683 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6685 return retVal;
6686 } else {
6687 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6688 return false;
6689 }
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006692 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006693 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006694
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006695 /**
6696 * Check if data is enabled for a specific reason
6697 * @param subId Subscription index
6698 * @param reason the reason the data enable change is taking place
6699 * @return {@code true} if the overall data is enabled; {@code false} if not.
6700 */
6701 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006702 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006703 @TelephonyManager.DataEnabledReason int reason) {
6704 try {
6705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6706 null);
6707 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006708 try {
6709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6710 "isDataEnabledForReason");
6711 } catch (Exception e2) {
6712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6713 mApp, subId, "isDataEnabledForReason");
6714 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 }
6716
6717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 int phoneId = mSubscriptionController.getPhoneId(subId);
6721 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006722 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 + " reason=" + reason);
6724 }
6725 Phone phone = PhoneFactory.getPhone(phoneId);
6726 if (phone != null) {
6727 boolean retVal;
6728 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6729 retVal = phone.isUserDataEnabled();
6730 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006731 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006732 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006733 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 return retVal;
6735 } else {
6736 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006737 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 + subId + " retVal=false");
6739 }
6740 return false;
6741 }
6742 } finally {
6743 Binder.restoreCallingIdentity(identity);
6744 }
6745 }
6746
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006747 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006748 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006749 if (uid == Process.PHONE_UID) {
6750 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6751 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6753 }
6754
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006755 //load access rules from carrier configs, and check those as well: b/139133814
6756 SubscriptionController subController = SubscriptionController.getInstance();
6757 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6758 || subController == null) return privilegeFromSim;
6759
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006760 PackageManager pkgMgr = phone.getContext().getPackageManager();
6761 String[] packages = pkgMgr.getPackagesForUid(uid);
6762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006765 int subId = phone.getSubId();
6766 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6767 // A test override is in place for the privileges for this subId, so don't try to
6768 // read the subscription privileges.
6769 return privilegeFromSim;
6770 }
6771 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006772 SubscriptionManager subManager = (SubscriptionManager)
6773 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6774 for (String pkg : packages) {
6775 if (subManager.canManageSubscription(subInfo, pkg)) {
6776 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6777 }
6778 }
6779 return privilegeFromSim;
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
6783 }
6784
6785 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6786 String pkgName) {
6787 //load access rules from carrier configs, and check those as well: b/139133814
6788 SubscriptionController subController = SubscriptionController.getInstance();
6789 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6790 || subController == null) return privilegeFromSim;
6791
6792 final long identity = Binder.clearCallingIdentity();
6793 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006794 int subId = phone.getSubId();
6795 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6796 // A test override is in place for the privileges for this subId, so don't try to
6797 // read the subscription privileges.
6798 return privilegeFromSim;
6799 }
6800 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006801 SubscriptionManager subManager = (SubscriptionManager)
6802 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6803 return subManager.canManageSubscription(subInfo, pkgName)
6804 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
6807 }
6808 }
6809
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006810 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006811 public int getCarrierPrivilegeStatus(int subId) {
6812 final Phone phone = getPhone(subId);
6813 if (phone == null) {
6814 loge("getCarrierPrivilegeStatus: Invalid subId");
6815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6816 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006817 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6818 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006819 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006820 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6821 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006822
6823 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006824 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006825 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006826 }
Junda Liu29340342014-07-10 15:23:27 -07006827
6828 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006829 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006830 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006831 final Phone phone = getPhone(subId);
6832 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006833 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6835 }
6836 UiccProfile profile =
6837 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6838 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006839 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6841 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006842 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006843 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006844 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 }
6846
6847 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006848 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006849 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006850 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006852 }
6853
6854 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006855 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6856 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006857 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006858 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6859 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006860 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006861 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006862 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006863 }
6864
6865 @Override
6866 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006867 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006868 if (TextUtils.isEmpty(pkgName))
6869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006870 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6871 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006872 UiccPort port = UiccController.getInstance().getUiccPort(i);
6873 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006874 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006875 continue;
6876 }
6877
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006878 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006879 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006880 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006881 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6882 break;
6883 }
6884 }
6885
6886 return result;
Junda Liu29340342014-07-10 15:23:27 -07006887 }
Derek Tan89e89d42014-07-08 17:00:10 -07006888
6889 @Override
Junda Liue64de782015-04-16 17:19:16 -07006890 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006891 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006892 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6893 loge("phoneId " + phoneId + " is not valid.");
6894 return null;
6895 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006896 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6897 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006898 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006899 return null ;
6900 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006901 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006902 }
6903
Amith Yamasani6e118872016-02-19 12:53:51 -08006904 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006905 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006906 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006907 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006908 List<String> privilegedPackages = new ArrayList<>();
6909 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006910 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006911 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006912 if (port != null) {
6913 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006914 if (packages == null) {
6915 // Only check packages in user 0 for now
6916 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006917 PackageManager.MATCH_DISABLED_COMPONENTS
6918 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006919 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006920 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006921 }
6922 for (int p = packages.size() - 1; p >= 0; p--) {
6923 PackageInfo pkgInfo = packages.get(p);
6924 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006925 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6926 port.getCarrierPrivilegeStatus(pkgInfo),
6927 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006928 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006929 privilegedPackages.add(pkgInfo.packageName);
6930 }
6931 }
6932 }
6933 }
6934 return privilegedPackages;
6935 }
6936
chen xuf7e9fe82019-05-09 19:31:02 -07006937 @Override
6938 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006939 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6940
6941 final long identity = Binder.clearCallingIdentity();
6942
chen xuf7e9fe82019-05-09 19:31:02 -07006943 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006944 try {
6945 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6946 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6947 }
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006950 }
6951 return privilegedPackages;
6952 }
6953
Wink Savilleb564aae2014-10-23 10:18:09 -07006954 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006955 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006956 UiccPort port = phone == null ? null : phone.getUiccPort();
6957 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006958 return null;
6959 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006960 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006961 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006962 return null;
6963 }
6964 return iccId;
6965 }
6966
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006967 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006968 public void setCallComposerStatus(int subId, int status) {
6969 enforceModifyPermission();
6970
6971 final long identity = Binder.clearCallingIdentity();
6972 try {
6973 Phone phone = getPhone(subId);
6974 if (phone != null) {
6975 Phone defaultPhone = phone.getImsPhone();
6976 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6977 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6978 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6980 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006981 }
6982 }
Shuo Qian284ae752020-12-22 19:10:14 -08006983 } catch (ImsException e) {
6984 throw new ServiceSpecificException(e.getCode());
6985 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006986 Binder.restoreCallingIdentity(identity);
6987 }
6988 }
6989
6990 @Override
6991 public int getCallComposerStatus(int subId) {
6992 enforceReadPrivilegedPermission("getCallComposerStatus");
6993
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
6996 Phone phone = getPhone(subId);
6997 if (phone != null) {
6998 Phone defaultPhone = phone.getImsPhone();
6999 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7000 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7001 return imsPhone.getCallComposerStatus();
7002 }
7003 }
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
7007 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7008 }
7009
7010 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007011 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7012 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007013 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007014 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 final long identity = Binder.clearCallingIdentity();
7017 try {
7018 final String iccId = getIccId(subId);
7019 final Phone phone = getPhone(subId);
7020 if (phone == null) {
7021 return false;
7022 }
7023 final String subscriberId = phone.getSubscriberId();
7024
7025 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007026 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 + subscriberId + " to " + number);
7028 }
7029
7030 if (TextUtils.isEmpty(iccId)) {
7031 return false;
7032 }
7033
7034 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7035
7036 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7037 if (alphaTag == null) {
7038 editor.remove(alphaTagPrefKey);
7039 } else {
7040 editor.putString(alphaTagPrefKey, alphaTag);
7041 }
7042
7043 // Record both the line number and IMSI for this ICCID, since we need to
7044 // track all merged IMSIs based on line number
7045 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7046 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7047 if (number == null) {
7048 editor.remove(numberPrefKey);
7049 editor.remove(subscriberPrefKey);
7050 } else {
7051 editor.putString(numberPrefKey, number);
7052 editor.putString(subscriberPrefKey, subscriberId);
7053 }
7054
7055 editor.commit();
7056 return true;
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007059 }
Derek Tan7226c842014-07-02 17:42:23 -07007060 }
7061
7062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007063 public String getLine1NumberForDisplay(int subId, String callingPackage,
7064 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007065 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007067 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007068 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007069 return null;
7070 }
Derek Tan97ebb422014-09-05 16:55:38 -07007071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 String iccId = getIccId(subId);
7075 if (iccId != null) {
7076 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7077 if (DBG_MERGE) {
7078 log("getLine1NumberForDisplay returning "
7079 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7080 }
7081 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7084 return null;
7085 } finally {
7086 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007087 }
Derek Tan7226c842014-07-02 17:42:23 -07007088 }
7089
7090 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7092 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007094 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007095 return null;
7096 }
Derek Tan97ebb422014-09-05 16:55:38 -07007097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 String iccId = getIccId(subId);
7101 if (iccId != null) {
7102 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7103 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7104 }
7105 return null;
7106 } finally {
7107 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007108 }
Derek Tan7226c842014-07-02 17:42:23 -07007109 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007110
7111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007112 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7113 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007114 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7115 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007117 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007119 return null;
7120 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007121
Jordan Liub49b04b2019-05-06 14:45:15 -07007122 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7123 // the process, where TelephonyManager was instantiated.
7124 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007125 final long identity = Binder.clearCallingIdentity();
7126 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007127 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final TelephonyManager tele = TelephonyManager.from(context);
7129 final SubscriptionManager sub = SubscriptionManager.from(context);
7130
7131 // Figure out what subscribers are currently active
7132 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133
Jordan Liub49b04b2019-05-06 14:45:15 -07007134 // Only consider subs which match the current subId
7135 // This logic can be simplified. See b/131189269 for progress.
7136 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007137 activeSubscriberIds.add(tele.getSubscriberId(subId));
7138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
7140 // First pass, find a number override for an active subscriber
7141 String mergeNumber = null;
7142 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7143 for (String key : prefs.keySet()) {
7144 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7145 final String subscriberId = (String) prefs.get(key);
7146 if (activeSubscriberIds.contains(subscriberId)) {
7147 final String iccId = key.substring(
7148 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7149 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7150 mergeNumber = (String) prefs.get(numberKey);
7151 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007152 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153 + " for active subscriber " + subscriberId);
7154 }
7155 if (!TextUtils.isEmpty(mergeNumber)) {
7156 break;
7157 }
7158 }
7159 }
7160 }
7161
7162 // Shortcut when no active merged subscribers
7163 if (TextUtils.isEmpty(mergeNumber)) {
7164 return null;
7165 }
7166
7167 // Second pass, find all subscribers under that line override
7168 final ArraySet<String> result = new ArraySet<>();
7169 for (String key : prefs.keySet()) {
7170 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7171 final String number = (String) prefs.get(key);
7172 if (mergeNumber.equals(number)) {
7173 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7174 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7175 final String subscriberId = (String) prefs.get(subscriberKey);
7176 if (!TextUtils.isEmpty(subscriberId)) {
7177 result.add(subscriberId);
7178 }
7179 }
7180 }
7181 }
7182
7183 final String[] resultArray = result.toArray(new String[result.size()]);
7184 Arrays.sort(resultArray);
7185 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007186 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7188 }
7189 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007190 } finally {
7191 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007192 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007193 }
7194
7195 @Override
zoey chen38003472019-12-13 17:16:31 +08007196 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7197 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 final TelephonyManager telephonyManager = mApp.getSystemService(
7202 TelephonyManager.class);
7203 String subscriberId = telephonyManager.getSubscriberId(subId);
7204 if (subscriberId == null) {
7205 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007206 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007207 + subId);
7208 }
7209 return null;
7210 }
7211
7212 final SubscriptionInfo info = SubscriptionController.getInstance()
7213 .getSubscriptionInfo(subId);
7214 final ParcelUuid groupUuid = info.getGroupUuid();
7215 // If it doesn't belong to any group, return just subscriberId of itself.
7216 if (groupUuid == null) {
7217 return new String[]{subscriberId};
7218 }
7219
7220 // Get all subscriberIds from the group.
7221 final List<String> mergedSubscriberIds = new ArrayList<>();
7222 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007223 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007224 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007225 for (SubscriptionInfo subInfo : groupInfos) {
7226 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7227 if (subscriberId != null) {
7228 mergedSubscriberIds.add(subscriberId);
7229 }
7230 }
7231
7232 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235
7236 }
7237 }
7238
7239 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007240 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007241 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007242 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243
7244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 final Phone phone = getPhone(subId);
7247 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7248 } finally {
7249 Binder.restoreCallingIdentity(identity);
7250 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007251 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007252
7253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007254 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007255 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7256 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007257 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7258 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259
7260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 final Phone phone = getPhone(subId);
7263 if (phone == null) {
7264 return false;
7265 }
7266 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7267 cdmaNonRoamingList);
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007270 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007271 }
7272
7273 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007274 @Deprecated
7275 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7276 enforceModifyPermission();
7277
7278 int returnValue = 0;
7279 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007280 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007281 if(result.exception == null) {
7282 if (result.result != null) {
7283 byte[] responseData = (byte[])(result.result);
7284 if(responseData.length > oemResp.length) {
7285 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7286 responseData.length + "bytes. Buffer Size is " +
7287 oemResp.length + "bytes.");
7288 }
7289 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7290 returnValue = responseData.length;
7291 }
7292 } else {
7293 CommandException ex = (CommandException) result.exception;
7294 returnValue = ex.getCommandError().ordinal();
7295 if(returnValue > 0) returnValue *= -1;
7296 }
7297 } catch (RuntimeException e) {
7298 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7299 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7300 if(returnValue > 0) returnValue *= -1;
7301 }
7302
7303 return returnValue;
7304 }
7305
7306 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007307 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007308 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007309 try {
7310 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007311 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007312 mApp, phone.getSubId(), "getRadioAccessFamily");
7313 } catch (SecurityException e) {
7314 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7315 throw e;
7316 }
chen xub97461a2018-10-26 14:17:57 -07007317 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007318 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007319 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 final long identity = Binder.clearCallingIdentity();
7322 try {
chen xub97461a2018-10-26 14:17:57 -07007323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007325 mApp, phone.getSubId(), "getRadioAccessFamily");
7326 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
chen xub97461a2018-10-26 14:17:57 -07007330 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007331 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007332
7333 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007334 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007335 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007336 try {
7337 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7338 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007339 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007340 }
7341 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007342 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007343 }
7344 RoleManager rm = mApp.getSystemService(RoleManager.class);
7345 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7346 if (!dialerRoleHolders.contains(callingPackage)) {
7347 throw new SecurityException("App must be the dialer role holder to"
7348 + " upload a call composer pic");
7349 }
7350
7351 Executors.newSingleThreadExecutor().execute(() -> {
7352 ByteArrayOutputStream output = new ByteArrayOutputStream(
7353 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7354 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7355 boolean readUntilEnd = false;
7356 int totalBytesRead = 0;
7357 byte[] buffer = new byte[16 * 1024];
7358 while (true) {
7359 int numRead;
7360 try {
7361 numRead = input.read(buffer);
7362 } catch (IOException e) {
7363 try {
7364 fd.checkError();
7365 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7366 null);
7367 } catch (IOException e1) {
7368 // This means that the other side closed explicitly with an error. If this
7369 // happens, log and ignore.
7370 loge("Remote end of call composer picture pipe closed: " + e1);
7371 }
7372 break;
7373 }
7374 if (numRead == -1) {
7375 readUntilEnd = true;
7376 break;
7377 }
7378 totalBytesRead += numRead;
7379 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7380 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7381 try {
7382 input.close();
7383 } catch (IOException e) {
7384 // ignore
7385 }
7386 break;
7387 }
7388 output.write(buffer, 0, numRead);
7389 }
7390 // Generally, the remote end will close the file descriptors. The only case where we
7391 // close is above, where the picture size is too big.
7392
7393 try {
7394 fd.checkError();
7395 } catch (IOException e) {
7396 loge("Remote end for call composer closed with an error: " + e);
7397 return;
7398 }
7399
Hall Liuaa4211e2021-01-20 15:43:39 -08007400 if (!readUntilEnd) {
7401 loge("Did not finish reading entire image; aborting");
7402 return;
7403 }
Hall Liu82694d52020-12-11 18:22:04 -08007404
Hall Liuaa4211e2021-01-20 15:43:39 -08007405 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7406 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7407 new CallComposerPictureTransfer.Factory() {},
7408 imageData,
7409 (result) -> {
7410 if (result.first != null) {
7411 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7412 Bundle outputResult = new Bundle();
7413 outputResult.putParcelable(
7414 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7415 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7416 outputResult);
7417 } else {
7418 callback.send(result.second, null);
7419 }
7420 }
7421 );
Hall Liu82694d52020-12-11 18:22:04 -08007422 });
7423 }
7424
7425 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007426 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429
7430 final long identity = Binder.clearCallingIdentity();
7431 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007432 ImsManager.getInstance(defaultPhone.getContext(),
7433 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 } finally {
7435 Binder.restoreCallingIdentity(identity);
7436 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007437 }
7438
7439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007440 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7443 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007444 return false;
7445 }
Svet Ganovb320e182015-04-16 12:30:10 -07007446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 // Check the user preference and the system-level IMS setting. Even if the user has
7450 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7451 // In the long run, we may instead need to check if there exists a connection service
7452 // which can support video calling.
7453 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007454 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455 return imsManager.isVtEnabledByPlatform()
7456 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7457 && imsManager.isVtEnabledByUser();
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
7460 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007461 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007462
Andrew Leea1239f22015-03-02 17:44:07 -08007463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007464 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7465 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007467 mApp, subId, callingPackage, callingFeatureId,
7468 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 return false;
7470 }
7471
7472 final long identity = Binder.clearCallingIdentity();
7473 try {
7474 CarrierConfigManager configManager =
7475 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007476 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
Andrew Leea1239f22015-03-02 17:44:07 -08007481 }
7482
7483 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007484 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007486 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 return false;
7488 }
7489
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 CarrierConfigManager configManager =
7493 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007494 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7496 } finally {
7497 Binder.restoreCallingIdentity(identity);
7498 }
Andrew Leea1239f22015-03-02 17:44:07 -08007499 }
7500
Andrew Lee9431b832015-03-09 18:46:45 -07007501 @Override
7502 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007503 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007504 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007505 }
7506
7507 @Override
7508 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 final long identity = Binder.clearCallingIdentity();
7510 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
Andrew Lee9431b832015-03-09 18:46:45 -07007515 }
7516
Hall Liuf6668912018-10-31 17:05:23 -07007517 /**
7518 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7519 * support for the feature and device firmware support.
7520 *
7521 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7522 */
7523 @Override
7524 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007526 final Phone phone = getPhone(subscriptionId);
7527 if (phone == null) {
7528 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7529 return false;
7530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7534 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 return isCarrierSupported && isDeviceSupported;
7537 } finally {
7538 Binder.restoreCallingIdentity(identity);
7539 }
Hall Liu98187582018-01-22 19:15:32 -08007540 }
7541
Hall Liuf6668912018-10-31 17:05:23 -07007542 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007543 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7544 * RTT setting, will return true if the device and carrier both support RTT.
7545 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007546 */
7547 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 final long identity = Binder.clearCallingIdentity();
7549 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007550 boolean isRttSupported = isRttSupported(subscriptionId);
7551 boolean isUserRttSettingOn = Settings.Secure.getInt(
7552 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7553 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7554 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7555 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007559 }
7560
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007561 @Deprecated
7562 @Override
7563 public String getDeviceId(String callingPackage) {
7564 return getDeviceIdWithFeature(callingPackage, null);
7565 }
7566
Sanket Padawe7310cc72015-01-14 09:53:20 -08007567 /**
7568 * Returns the unique device ID of phone, for example, the IMEI for
7569 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7570 *
7571 * <p>Requires Permission:
7572 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7573 */
7574 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007576 try {
7577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7578 } catch (SecurityException se) {
7579 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7580 throw new SecurityException("Package " + callingPackage + " does not belong to "
7581 + Binder.getCallingUid());
7582 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007583 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007584 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007585 return null;
7586 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007587 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007588 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007589 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007590 return null;
7591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592
7593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 return phone.getDeviceId();
7596 } finally {
7597 Binder.restoreCallingIdentity(identity);
7598 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007599 }
7600
Ping Sunc67b7c22016-03-02 19:16:45 +08007601 /**
7602 * {@hide}
7603 * Returns the IMS Registration Status on a particular subid
7604 *
7605 * @param subId
7606 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007607 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007608 Phone phone = getPhone(subId);
7609 if (phone != null) {
7610 return phone.isImsRegistered();
7611 } else {
7612 return false;
7613 }
7614 }
7615
Santos Cordon7a1885b2015-02-03 11:15:19 -08007616 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007617 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007618 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007620 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007621 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7622 }
7623 final long identity = Binder.clearCallingIdentity();
7624 try {
7625 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
7629 }
7630
7631 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007632 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007633 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007634 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007635 mApp,
7636 subscriptionId,
7637 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007638 final long identity = Binder.clearCallingIdentity();
7639 try {
7640 Phone phone = getPhone(subscriptionId);
7641 if (phone == null) {
7642 return null;
7643 }
7644 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7645 } finally {
7646 Binder.restoreCallingIdentity(identity);
7647 }
7648 }
7649
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007650 /**
7651 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007652 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007653 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 final long identity = Binder.clearCallingIdentity();
7655 try {
7656 Phone phone = getPhone(subId);
7657 if (phone != null) {
7658 return phone.isWifiCallingEnabled();
7659 } else {
7660 return false;
7661 }
7662 } finally {
7663 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007664 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007665 }
7666
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007667 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007668 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007669 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007670 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 final long identity = Binder.clearCallingIdentity();
7672 try {
7673 Phone phone = getPhone(subId);
7674 if (phone != null) {
7675 return phone.isVideoEnabled();
7676 } else {
7677 return false;
7678 }
7679 } finally {
7680 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007681 }
7682 }
7683
7684 /**
7685 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7686 * defined in {@link ImsRegistrationImplBase}.
7687 */
7688 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 Phone phone = getPhone(subId);
7692 if (phone != null) {
7693 return phone.getImsRegistrationTech();
7694 } else {
7695 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7696 }
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007699 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007700 }
7701
Stuart Scott8eef64f2015-04-08 15:13:54 -07007702 @Override
7703 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007704 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007705 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7706 return;
7707 }
Kai Shif70f46f2021-03-03 13:59:46 -08007708 Phone defaultPhone = getDefaultPhone();
7709 if (defaultPhone != null) {
7710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7711 mApp, getDefaultPhone().getSubId(), "factoryReset");
7712 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007713 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007714
Svet Ganovcc087f82015-05-12 20:35:54 -07007715 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007716 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7717 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007718 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007719 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007720 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007721 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007722 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007723 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007724 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007725 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007726 // There has been issues when Sms raw table somehow stores orphan
7727 // fragments. They lead to garbled message when new fragments come
7728 // in and combined with those stale ones. In case this happens again,
7729 // user can reset all network settings which will clean up this table.
7730 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007731 // Clean up IMS settings as well here.
7732 int slotId = getSlotIndex(subId);
7733 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7734 ImsManager.getInstance(mApp, slotId).factoryReset();
7735 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007736
Kai Shif70f46f2021-03-03 13:59:46 -08007737 if (defaultPhone == null) {
7738 return;
7739 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007740 // Erase modem config if erase modem on network setting is enabled.
7741 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7742 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7743 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007744 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007745 }
Kai Shif70f46f2021-03-03 13:59:46 -08007746
7747 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007748 } finally {
7749 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007750 }
7751 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007752
SongFerngWangfd89b102021-05-27 22:44:54 +08007753 @VisibleForTesting
7754 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7755 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7756 return;
7757 }
7758 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7759 RILConstants.PREFERRED_NETWORK_MODE);
7760 SubscriptionManager.setSubscriptionProperty(subId,
7761 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7762 "user=" + defaultNetworkType);
7763 phone.loadAllowedNetworksFromSubscriptionDatabase();
7764 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7765 defaultNetworkType, null);
7766 }
7767
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007768 private void cleanUpSmsRawTable(Context context) {
7769 ContentResolver resolver = context.getContentResolver();
7770 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7771 resolver.delete(uri, null, null);
7772 }
7773
Narayan Kamath1c496c22015-04-16 14:40:19 +01007774 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007775 public String getSimLocaleForSubscriber(int subId) {
7776 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7777 final Phone phone = getPhone(subId);
7778 if (phone == null) {
7779 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007780 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 final long identity = Binder.clearCallingIdentity();
7783 try {
chen xu5d3637b2019-01-21 23:31:38 -08007784 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007785 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007786 if (info == null) {
7787 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7788 return null;
7789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 // Try and fetch the locale from the carrier properties or from the SIM language
7791 // preferences (EF-PL and EF-LI)...
7792 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007794 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7795 if (localeFromDefaultSim != null) {
7796 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7797 if (DBG) log("Using locale from subId: " + subId + " locale: "
7798 + localeFromDefaultSim);
7799 return localeFromDefaultSim.toLanguageTag();
7800 } else {
7801 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 }
7803 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 // The SIM language preferences only store a language (e.g. fr = French), not an
7806 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7807 // the SIM and carrier preferences does not include a country we add the country
7808 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007809 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007811 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 return mccLocale.toLanguageTag();
7813 }
7814
7815 if (DBG) log("No locale found - returning null");
7816 return null;
7817 } finally {
7818 Binder.restoreCallingIdentity(identity);
7819 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007820 }
7821
7822 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007824 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007825 }
7826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827 /**
7828 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7829 */
7830 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007831 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007832 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007833 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007834
Chenjie Yu1ba97252018-01-11 18:16:20 -08007835 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007836 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007837
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007838 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007839 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7840 * representing the state of the modem.
7841 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007842 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7843 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007844 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007845 */
7846 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007847 public void requestModemActivityInfo(ResultReceiver result) {
7848 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007849 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850
7851 final long identity = Binder.clearCallingIdentity();
7852 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007853 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 } finally {
7855 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007856 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007857 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007858
Siddharth Rayb8114062018-06-17 15:02:38 -07007859 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7860 // less than total activity duration.
7861 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7862 if (info == null) {
7863 return false;
7864 }
7865 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007866 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7867 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7868
Siddharth Rayb8114062018-06-17 15:02:38 -07007869 return (info.isValid()
7870 && (info.getSleepTimeMillis() <= activityDurationMs)
7871 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007872 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007873 && (totalTxTimeMs <= activityDurationMs));
7874 }
7875
Jack Yu85bd38a2015-11-09 11:34:32 -08007876 /**
7877 * {@hide}
7878 * Returns the service state information on specified subscription.
7879 */
7880 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007881 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7882 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007884 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007885 return null;
7886 }
7887
Hall Liuf19c44f2018-11-27 14:38:17 -08007888 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7889 LocationAccessPolicy.checkLocationPermission(mApp,
7890 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7891 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007892 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007893 .setCallingPid(Binder.getCallingPid())
7894 .setCallingUid(Binder.getCallingUid())
7895 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007896 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007897 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007898 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7899 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007900 .build());
7901
7902 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7903 LocationAccessPolicy.checkLocationPermission(mApp,
7904 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7905 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007906 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007907 .setCallingPid(Binder.getCallingPid())
7908 .setCallingUid(Binder.getCallingUid())
7909 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007910 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007911 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007912 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7913 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007914 .build());
7915 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7916 boolean hasFinePermission =
7917 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7918 boolean hasCoarsePermission =
7919 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7920
Jack Yu479f40e2020-10-27 21:29:25 -07007921 final Phone phone = getPhone(subId);
7922 if (phone == null) {
7923 return null;
7924 }
7925
Jordan Liu0f2bc442020-11-18 16:47:37 -08007926 final long identity = Binder.clearCallingIdentity();
7927
Jack Yu479f40e2020-10-27 21:29:25 -07007928 boolean isCallingPackageDataService = phone.getDataServicePackages()
7929 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007931 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7932 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7933 Rlog.d(LOG_TAG,
7934 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7935 return null;
7936 }
7937
Hall Liuf19c44f2018-11-27 14:38:17 -08007938 ServiceState ss = phone.getServiceState();
7939
7940 // Scrub out the location info in ServiceState depending on what level of access
7941 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007942 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007943 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7944 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007945 } finally {
7946 Binder.restoreCallingIdentity(identity);
7947 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007948 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007949
7950 /**
7951 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7952 *
7953 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7954 * voicemail ringtone.
7955 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7956 * PhoneAccount.
7957 */
7958 @Override
7959 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007960 final long identity = Binder.clearCallingIdentity();
7961 try {
7962 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7963 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007964 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7968 } finally {
7969 Binder.restoreCallingIdentity(identity);
7970 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007971 }
7972
7973 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007974 * Sets the per-account voicemail ringtone.
7975 *
7976 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7977 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7978 *
7979 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7980 * voicemail ringtone.
7981 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7982 * PhoneAccount.
7983 */
7984 @Override
7985 public void setVoicemailRingtoneUri(String callingPackage,
7986 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007987 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007989 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7990 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7992 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7993 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995
7996 final long identity = Binder.clearCallingIdentity();
7997 try {
7998 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7999 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 }
8002 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8003 } finally {
8004 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008005 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 }
8007
8008 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008009 * Returns whether vibration is set for voicemail notification in Phone settings.
8010 *
8011 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8012 * voicemail vibration setting.
8013 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8014 */
8015 @Override
8016 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8020 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008021 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008028 }
8029
Youhan Wange64578a2016-05-02 15:32:42 -07008030 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008031 * Sets the per-account voicemail vibration.
8032 *
8033 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8034 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8035 *
8036 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8037 * voicemail vibration setting.
8038 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8039 * specific PhoneAccount.
8040 */
8041 @Override
8042 public void setVoicemailVibrationEnabled(String callingPackage,
8043 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008044 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008046 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8047 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8049 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8050 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008051 }
8052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 final long identity = Binder.clearCallingIdentity();
8054 try {
8055 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8056 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008057 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 }
8059 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8060 } finally {
8061 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008062 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 }
8064
8065 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008066 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8067 *
8068 * @throws SecurityException if the caller does not have the required permission
8069 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008070 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008071 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008072 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008073 }
8074
8075 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008076 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8077 * permission.
8078 *
8079 * @throws SecurityException if the caller does not have the required permission
8080 */
8081 private void enforceSendSmsPermission() {
8082 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8083 }
8084
8085 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008086 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008087 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008088 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008089 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008090 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 final long identity = Binder.clearCallingIdentity();
8092 try {
8093 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008094 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 if (componentName == null) {
8096 throw new SecurityException(
8097 "Caller not current active visual voicemail package[null]");
8098 }
8099 String vvmPackage = componentName.getPackageName();
8100 if (!callingPackage.equals(vvmPackage)) {
8101 throw new SecurityException("Caller not current active visual voicemail package["
8102 + vvmPackage + "]");
8103 }
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008106 }
8107 }
8108
8109 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008110 * Return the application ID for the app type.
8111 *
8112 * @param subId the subscription ID that this request applies to.
8113 * @param appType the uicc app type.
8114 * @return Application ID for specificied app type, or null if no uicc.
8115 */
8116 @Override
8117 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008118 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008119 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120
8121 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008122 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 if (phone == null) {
8124 return null;
8125 }
8126 String aid = null;
8127 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008128 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129 .getApplicationByType(appType).getAid();
8130 } catch (Exception e) {
8131 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8132 }
8133 return aid;
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008136 }
Youhan Wange64578a2016-05-02 15:32:42 -07008137 }
8138
Youhan Wang4001d252016-05-11 10:29:41 -07008139 /**
8140 * Return the Electronic Serial Number.
8141 *
8142 * @param subId the subscription ID that this request applies to.
8143 * @return ESN or null if error.
8144 */
8145 @Override
8146 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008147 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008148 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149
8150 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008151 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152 if (phone == null) {
8153 return null;
8154 }
8155 String esn = null;
8156 try {
8157 esn = phone.getEsn();
8158 } catch (Exception e) {
8159 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8160 }
8161 return esn;
8162 } finally {
8163 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008164 }
Youhan Wang4001d252016-05-11 10:29:41 -07008165 }
8166
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008167 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008168 * Return the Preferred Roaming List Version.
8169 *
8170 * @param subId the subscription ID that this request applies to.
8171 * @return PRLVersion or null if error.
8172 */
8173 @Override
8174 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008175 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008176 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177
8178 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008179 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 if (phone == null) {
8181 return null;
8182 }
8183 String cdmaPrlVersion = null;
8184 try {
8185 cdmaPrlVersion = phone.getCdmaPrlVersion();
8186 } catch (Exception e) {
8187 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8188 }
8189 return cdmaPrlVersion;
8190 } finally {
8191 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008192 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008193 }
8194
8195 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008196 * Get snapshot of Telephony histograms
8197 * @return List of Telephony histograms
8198 * @hide
8199 */
8200 @Override
8201 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8203 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204
8205 final long identity = Binder.clearCallingIdentity();
8206 try {
8207 return RIL.getTelephonyRILTimingHistograms();
8208 } finally {
8209 Binder.restoreCallingIdentity(identity);
8210 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008211 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008212
8213 /**
8214 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008215 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8216 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008217 * Require system privileges. In the future we may add this to carrier APIs.
8218 *
Michele Berionne482f8202018-11-27 18:57:59 -08008219 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008220 */
8221 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008222 @TelephonyManager.SetCarrierRestrictionResult
8223 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008224 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008226
Michele Berionne482f8202018-11-27 18:57:59 -08008227 if (carrierRestrictionRules == null) {
8228 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008229 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 final long identity = Binder.clearCallingIdentity();
8232 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008233 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008234 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 } finally {
8236 Binder.restoreCallingIdentity(identity);
8237 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008238 }
8239
8240 /**
8241 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008242 * Get the allowed carrier list and the excluded carrier list, including the priority between
8243 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008244 * Require system privileges. In the future we may add this to carrier APIs.
8245 *
Michele Berionne482f8202018-11-27 18:57:59 -08008246 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008247 */
8248 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008249 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008250 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008251 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252
8253 final long identity = Binder.clearCallingIdentity();
8254 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008255 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8256 if (response instanceof CarrierRestrictionRules) {
8257 return (CarrierRestrictionRules) response;
8258 }
8259 // Response is an Exception of some kind,
8260 // which is signalled to the user as a NULL retval
8261 return null;
8262 } catch (Exception e) {
8263 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8264 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008268 }
8269
fionaxu59545b42016-05-25 15:53:37 -07008270 /**
fionaxu59545b42016-05-25 15:53:37 -07008271 * Action set from carrier signalling broadcast receivers to enable/disable radio
8272 * @param subId the subscription ID that this action applies to.
8273 * @param enabled control enable or disable radio.
8274 * {@hide}
8275 */
8276 @Override
8277 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8278 enforceModifyPermission();
8279 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280
8281 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008282 if (phone == null) {
8283 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8284 return;
8285 }
8286 try {
8287 phone.carrierActionSetRadioEnabled(enabled);
8288 } catch (Exception e) {
8289 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290 } finally {
8291 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008292 }
8293 }
8294
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008295 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008296 * Enable or disable Voice over NR (VoNR)
8297 * @param subId the subscription ID that this action applies to.
8298 * @param enabled enable or disable VoNR.
8299 * @return operation result.
8300 */
8301 @Override
8302 public int setVoNrEnabled(int subId, boolean enabled) {
8303 enforceModifyPermission();
8304 final Phone phone = getPhone(subId);
8305
8306 final long identity = Binder.clearCallingIdentity();
8307 if (phone == null) {
8308 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8309 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8310 }
8311
8312 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8313 try {
8314 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8315 workSource);
8316 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008317
8318 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8319 if (DBG) {
8320 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8321 }
8322 SubscriptionManager.setSubscriptionProperty(
8323 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8324 (enabled ? "1" : "0"));
8325 }
8326
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008327 return result;
8328 } finally {
8329 Binder.restoreCallingIdentity(identity);
8330 }
8331 }
8332
8333 /**
8334 * Is voice over NR enabled
8335 * @return true if VoNR is enabled else false
8336 */
8337 @Override
8338 public boolean isVoNrEnabled(int subId) {
8339 enforceReadPrivilegedPermission("isVoNrEnabled");
8340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8341 final long identity = Binder.clearCallingIdentity();
8342 try {
8343 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8344 null, subId, workSource);
8345 if (DBG) log("isVoNrEnabled: " + isEnabled);
8346 return isEnabled;
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
8349 }
8350 }
8351
8352 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008353 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8354 * network status based on which carrier apps could apply actions accordingly,
8355 * enable/disable default url handler for example.
8356 *
8357 * @param subId the subscription ID that this action applies to.
8358 * @param report control start/stop reporting the default network status.
8359 * {@hide}
8360 */
8361 @Override
8362 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8363 enforceModifyPermission();
8364 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365
8366 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008367 if (phone == null) {
8368 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8369 return;
8370 }
8371 try {
8372 phone.carrierActionReportDefaultNetworkStatus(report);
8373 } catch (Exception e) {
8374 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 } finally {
8376 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008377 }
8378 }
8379
8380 /**
fionaxud9622282017-07-17 17:51:30 -07008381 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8382 * @param subId the subscription ID that this action applies to.
8383 * {@hide}
8384 */
8385 @Override
8386 public void carrierActionResetAll(int subId) {
8387 enforceModifyPermission();
8388 final Phone phone = getPhone(subId);
8389 if (phone == null) {
8390 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8391 return;
8392 }
8393 try {
8394 phone.carrierActionResetAll();
8395 } catch (Exception e) {
8396 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8397 }
8398 }
8399
8400 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008401 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8402 * bug report is being generated.
8403 */
8404 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008405 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008406 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8407 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008408 writer.println("Permission Denial: can't dump Phone from pid="
8409 + Binder.getCallingPid()
8410 + ", uid=" + Binder.getCallingUid()
8411 + "without permission "
8412 + android.Manifest.permission.DUMP);
8413 return;
8414 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008415 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008416 }
Jack Yueb89b242016-06-22 13:27:47 -07008417
Brad Ebingerdac2f002018-04-03 15:17:52 -07008418 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008419 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8420 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8421 @NonNull String[] args) {
8422 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8423 this, in.getFileDescriptor(), out.getFileDescriptor(),
8424 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008425 }
8426
Jack Yueb89b242016-06-22 13:27:47 -07008427 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008428 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008429 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008430 * @param reason the reason the data enable change is taking place
8431 * @param enabled True if enabling the data, otherwise disabling.
8432 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008433 */
8434 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008435 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008436 boolean enabled) {
8437 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8438 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8439 try {
8440 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008441 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008442 } catch (SecurityException se) {
8443 enforceModifyPermission();
8444 }
8445 } else {
8446 enforceModifyPermission();
8447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008448
8449 final long identity = Binder.clearCallingIdentity();
8450 try {
8451 Phone phone = getPhone(subId);
8452 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008453 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8454 phone.carrierActionSetMeteredApnsEnabled(enabled);
8455 } else {
8456 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458 }
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008461 }
8462 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008463
8464 /**
8465 * Get Client request stats
8466 * @return List of Client Request Stats
8467 * @hide
8468 */
8469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008470 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8471 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008473 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008474 return null;
8475 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008476 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 if (phone != null) {
8481 return phone.getClientRequestStats();
8482 }
8483
8484 return null;
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
8487 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008488 }
8489
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008490 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008491 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008492 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008493 }
Jack Yueb4124c2017-02-16 15:32:43 -08008494
8495 /**
Grace Chen70990072017-03-24 17:21:30 -07008496 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008497 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008498 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008499 * @param state State of SIM (power down, power up, pass through)
8500 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8501 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8502 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008503 *
8504 **/
8505 @Override
Grace Chen70990072017-03-24 17:21:30 -07008506 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008507 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008508 Phone phone = PhoneFactory.getPhone(slotIndex);
8509
vagdeviaf9a5b92018-08-15 16:01:53 -07008510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008515 phone.setSimPowerState(state, null, workSource);
8516 }
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
8522 /**
8523 * Set SIM card power state.
8524 *
8525 * @param slotIndex SIM slot id.
8526 * @param state State of SIM (power down, power up, pass through)
8527 * @param callback callback to trigger after success or failure
8528 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8529 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8531 *
8532 **/
8533 @Override
8534 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8535 IIntegerConsumer callback) {
8536 enforceModifyPermission();
8537 Phone phone = PhoneFactory.getPhone(slotIndex);
8538
8539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8540
8541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 if (phone != null) {
8544 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8545 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 }
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008549 }
8550 }
Shuo Qiandd210312017-04-12 22:11:33 +00008551
Tyler Gunn65d45c22017-06-05 11:22:26 -07008552 private boolean isUssdApiAllowed(int subId) {
8553 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008554 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008555 if (configManager == null) {
8556 return false;
8557 }
8558 PersistableBundle pb = configManager.getConfigForSubId(subId);
8559 if (pb == null) {
8560 return false;
8561 }
8562 return pb.getBoolean(
8563 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8564 }
8565
Shuo Qiandd210312017-04-12 22:11:33 +00008566 /**
8567 * Check if phone is in emergency callback mode
8568 * @return true if phone is in emergency callback mode
8569 * @param subId sub id
8570 */
goneil9c5f4872017-12-05 14:07:56 -08008571 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008572 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008573 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008574 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575
8576 final long identity = Binder.clearCallingIdentity();
8577 try {
8578 if (phone != null) {
8579 return phone.isInEcm();
8580 } else {
8581 return false;
8582 }
8583 } finally {
8584 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008585 }
8586 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008587
8588 /**
8589 * Get the current signal strength information for the given subscription.
8590 * Because this information is not updated when the device is in a low power state
8591 * it should not be relied-upon to be current.
8592 * @param subId Subscription index
8593 * @return the most recent cached signal strength info from the modem
8594 */
8595 @Override
8596 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 final long identity = Binder.clearCallingIdentity();
8598 try {
8599 Phone p = getPhone(subId);
8600 if (p == null) {
8601 return null;
8602 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008604 return p.getSignalStrength();
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
8607 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008608 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008609
Pengquan Meng77b7f132018-08-22 14:49:57 -07008610 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008611 * Get the current modem radio state for the given slot.
8612 * @param slotIndex slot index.
8613 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008614 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008615 * @return the current radio power state from the modem
8616 */
8617 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008619 Phone phone = PhoneFactory.getPhone(slotIndex);
8620 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8622 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008623 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8624 }
8625
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 return phone.getRadioPowerState();
8629 } finally {
8630 Binder.restoreCallingIdentity(identity);
8631 }
8632 }
8633 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8634 }
8635
8636 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008637 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8638 *
8639 * <p>Requires one of the following permissions:
8640 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8641 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8642 * privileges.
8643 *
8644 * @param subId subscription id
8645 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8646 * {@code false}.
8647 */
8648 @Override
8649 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008650 try {
8651 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8652 null);
8653 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008654 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008655 mApp, subId, "isDataRoamingEnabled");
8656 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008657
Pengquan Menga1bb6272018-09-06 09:59:22 -07008658 boolean isEnabled = false;
8659 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008660 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008661 Phone phone = getPhone(subId);
8662 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008663 } finally {
8664 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008665 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008666 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008667 }
8668
8669
8670 /**
8671 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8672 *
8673 * <p> Requires permission:
8674 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8675 * privileges.
8676 *
8677 * @param subId subscription id
8678 * @param isEnabled {@code true} means enable, {@code false} means disable.
8679 */
8680 @Override
8681 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8683 mApp, subId, "setDataRoamingEnabled");
8684
Pengquan Menga1bb6272018-09-06 09:59:22 -07008685 final long identity = Binder.clearCallingIdentity();
8686 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008687 Phone phone = getPhone(subId);
8688 if (phone != null) {
8689 phone.setDataRoamingEnabled(isEnabled);
8690 }
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008693 }
8694 }
8695
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008696 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008697 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008698 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008699 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008700 mApp, subId, "isManualNetworkSelectionAllowed");
8701
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008702 boolean isAllowed = true;
8703 final long identity = Binder.clearCallingIdentity();
8704 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008705 Phone phone = getPhone(subId);
8706 if (phone != null) {
8707 isAllowed = phone.isCspPlmnEnabled();
8708 }
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 return isAllowed;
8713 }
8714
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008715 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8716 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8717 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8718 // Update each UiccPort object based on privilege access
8719 UiccPort[] uiccPorts = card.getUiccPortList();
8720 for (UiccPort port : uiccPorts) {
8721 UiccProfile profile = port.getUiccProfile();
8722 if (profile == null ||
8723 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8724 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8725 return false;
8726 }
8727 }
8728 return true;
8729 }
8730
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008731 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008732 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008733 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008734 mApp.getSystemService(AppOpsManager.class)
8735 .checkPackage(Binder.getCallingUid(), callingPackage);
8736
Jordan Liu1e142fc2019-04-22 15:10:43 -07008737 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008738 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008739 try {
8740 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008741 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008742 } catch (SecurityException e) {
8743 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8744 // has carrier privileges on an active UICC
8745 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8746 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008747 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008748 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008749 }
sandeepjsb6c87872021-09-27 15:34:44 +00008750 // checking compatibility, if calling app's target SDK is T and beyond.
8751 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8752 Binder.getCallingUid())) {
8753 isIccIdAccessRestricted = true;
8754 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008755 final long identity = Binder.clearCallingIdentity();
8756 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008757 UiccController uiccController = UiccController.getInstance();
8758 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008759 if (hasReadPermission) {
8760 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008761 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008762
8763 // Remove private info if the caller doesn't have access
8764 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8765 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008766 //setting the value after compatibility check
8767 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008768 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8769 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008770 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008771 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8772 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8773 if (card == null || card.getUiccPortList().length == 0) {
8774 // assume no access if the card or ports are unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008775 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008776 continue;
8777 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008778 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008779 filteredInfos.add(cardInfo);
8780 } else {
sandeepjsb6c87872021-09-27 15:34:44 +00008781 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008782 }
8783 }
8784 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008785 } finally {
8786 Binder.restoreCallingIdentity(identity);
8787 }
8788 }
8789
sandeepjsb6c87872021-09-27 15:34:44 +00008790 /**
8791 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8792 * generally private and require carrier privileges to view.
8793 *
8794 * @hide
8795 */
8796 @NonNull
8797 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8798 List<UiccPortInfo> portinfo = new ArrayList<>();
8799 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8800 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8801 }
8802 return new UiccCardInfo(
8803 cardInfo.isEuicc(),
8804 cardInfo.getCardId(),
8805 null,
8806 cardInfo.getPhysicalSlotIndex(),
8807 cardInfo.isRemovable(),
8808 cardInfo.isMultipleEnabledProfilesSupported(),
8809 portinfo
8810 );
8811 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008812
sandeepjsb6c87872021-09-27 15:34:44 +00008813 /**
8814 * @hide
8815 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8816 * These values are generally private and require carrier privileges to view.
8817 */
8818 @NonNull
8819 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8820 return new UiccPortInfo(
8821 UiccPortInfo.ICCID_REDACTED,
8822 portInfo.getPortIndex(),
8823 portInfo.getLogicalSlotIndex(),
8824 portInfo.isActive()
8825 );
8826 }
8827 @Override
8828 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008829 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008830 mApp.getSystemService(AppOpsManager.class)
8831 .checkPackage(Binder.getCallingUid(), callingPackage);
8832
8833 boolean hasReadPermission = false;
8834 boolean isLogicalSlotAccessRestricted = false;
8835 String iccId;
8836
8837 try {
8838 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8839 hasReadPermission = true;
8840 } catch (SecurityException e) {
8841 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8842 // has carrier privileges on an active UICC
8843 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8844 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8845 hasReadPermission = true;
8846 }
8847 }
8848
8849 // checking compatibility, if calling app's target SDK is T and beyond.
8850 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8851 Binder.getCallingUid())) {
8852 isLogicalSlotAccessRestricted = true;
8853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8857 if (slots == null) {
8858 Rlog.i(LOG_TAG, "slots is null.");
8859 return null;
8860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8862 for (int i = 0; i < slots.length; i++) {
8863 UiccSlot slot = slots[i];
8864 if (slot == null) {
8865 continue;
8866 }
8867
Jordan Liu7be7e652019-05-06 18:55:02 +00008868 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008869 UiccCard card = slot.getUiccCard();
sandeepjsb6c87872021-09-27 15:34:44 +00008870 //if has read permission
8871 if (hasReadPermission) {
8872 iccId = slot.getIccId();
8873 } else {
sandeepjsa208e3b2021-11-17 04:05:58 +00008874 if (card != null) {
8875 // if no read permission checking carrier
8876 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
8877 iccId = slot.getIccId();
8878 } else {
8879 //if no carrier permission redact ICCID
8880 iccId = IccUtils.TEST_ICCID;
8881 }
sandeepjsb6c87872021-09-27 15:34:44 +00008882 } else {
sandeepjsa208e3b2021-11-17 04:05:58 +00008883 iccId = null;
sandeepjsb6c87872021-09-27 15:34:44 +00008884 }
8885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886 if (card != null) {
8887 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008888 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008889 cardId = slot.getEid();
8890 if (TextUtils.isEmpty(cardId)) {
sandeepjsb6c87872021-09-27 15:34:44 +00008891 cardId = iccId;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008893 }
8894
Jordan Liu857451f2019-05-09 16:35:35 -07008895 if (cardId != null) {
8896 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8897 // if cardId is an EID, it's all digits so this is fine
8898 cardId = IccUtils.stripTrailingFs(cardId);
8899 }
8900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008901 int cardState = 0;
8902 switch (slot.getCardState()) {
8903 case CARDSTATE_ABSENT:
8904 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8905 break;
8906 case CARDSTATE_PRESENT:
8907 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8908 break;
8909 case CARDSTATE_ERROR:
8910 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8911 break;
8912 case CARDSTATE_RESTRICTED:
8913 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8914 break;
8915 default:
8916 break;
8917
8918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920 slot.isEuicc(),
8921 cardId,
8922 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008923 slot.isExtendedApduSupported(),
sandeepjsb6c87872021-09-27 15:34:44 +00008924 slot.isRemovable(), Collections.singletonList(
8925 new UiccPortInfo(
8926 iccId,
8927 0 /* TODO: to use portList from UiccSlots */,
8928 slot.getPhoneId(),
8929 slot.isActive())));
8930 //setting the value after compatibility check
8931 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008932 }
8933 return infos;
8934 } finally {
8935 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008936 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008937 }
8938
8939 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008940 @Deprecated
8941 //TODO : once integrating with HAL Changes we can clean up this Internal API.
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008942 public boolean switchSlots(int[] physicalSlots) {
8943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008944
8945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008951 }
Jack Yu4c988042018-02-27 15:30:01 -08008952
8953 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008954 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8955 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8956 enforceModifyPermission();
8957
8958 final long identity = Binder.clearCallingIdentity();
8959 try {
8960 //TODO: once integrating the HAL changes we can proceed with to work on the parsing side
8961 int[] physicalSlots = new int[slotMapping.size()];
8962 for (int i = 0; i < physicalSlots.length; i++) {
8963 physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex();
8964 }
8965 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8966 } finally {
8967 Binder.restoreCallingIdentity(identity);
8968 }
8969 }
8970
8971 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008972 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008973 final long identity = Binder.clearCallingIdentity();
8974 try {
8975 return UiccController.getInstance().getCardIdForDefaultEuicc();
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
8979 }
8980
Pengquan Meng85728fb2018-03-12 16:31:21 -07008981 /**
goneil47ffb6e2018-04-06 15:40:58 -07008982 * A test API to reload the UICC profile.
8983 *
8984 * <p>Requires that the calling app has permission
8985 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8986 * @hide
8987 */
8988 @Override
8989 public void refreshUiccProfile(int subId) {
8990 enforceModifyPermission();
8991
8992 final long identity = Binder.clearCallingIdentity();
8993 try {
8994 Phone phone = getPhone(subId);
8995 if (phone == null) {
8996 return;
8997 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008998 UiccPort uiccPort = phone.getUiccPort();
8999 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009000 return;
9001 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009002 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009003 if (uiccProfile == null) {
9004 return;
9005 }
9006 uiccProfile.refresh();
9007 } finally {
9008 Binder.restoreCallingIdentity(identity);
9009 }
9010 }
9011
9012 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009013 * Returns false if the mobile data is disabled by default, otherwise return true.
9014 */
9015 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009016 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009017 }
9018
9019 /**
9020 * Returns true if the data roaming is enabled by default, i.e the system property
9021 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9022 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9023 */
9024 private boolean getDefaultDataRoamingEnabled(int subId) {
9025 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009026 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009027 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009028 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9029 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9030 return isDataRoamingEnabled;
9031 }
9032
9033 /**
9034 * Returns the default network type for the given {@code subId}, if the default network type is
9035 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9036 */
9037 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009038 List<Integer> list = TelephonyProperties.default_network();
9039 int phoneId = mSubscriptionController.getPhoneId(subId);
9040 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9041 return list.get(phoneId);
9042 }
9043 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009044 }
fionaxua13278b2018-03-21 00:08:13 -07009045
9046 @Override
9047 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009048 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009050
9051 final long identity = Binder.clearCallingIdentity();
9052 try {
9053 final Phone phone = getPhone(subId);
9054 if (phone == null) {
9055 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9056 return;
9057 }
chen xueaba88a2019-03-15 13:15:10 -07009058 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9059 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009060 if (carrierPrivilegeRules == null) {
9061 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9062 } else {
9063 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065 } finally {
9066 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009067 }
fionaxua13278b2018-03-21 00:08:13 -07009068 }
9069
9070 @Override
9071 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009072 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009073
9074 final long identity = Binder.clearCallingIdentity();
9075 try {
9076 final Phone phone = getPhone(subId);
9077 if (phone == null) {
9078 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9079 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9080 }
9081 return phone.getCarrierIdListVersion();
9082 } finally {
9083 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009084 }
fionaxua13278b2018-03-21 00:08:13 -07009085 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009086
9087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009088 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9089 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009091 mApp, subId, callingPackage, callingFeatureId,
9092 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009093 return -1;
9094 }
9095
9096 final long identity = Binder.clearCallingIdentity();
9097 try {
9098 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9099 } finally {
9100 Binder.restoreCallingIdentity(identity);
9101 }
9102 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009103
9104 @Override
9105 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009106 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009107 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009108 mApp, subId, "getCdmaRoamingMode");
9109
9110 final long identity = Binder.clearCallingIdentity();
9111 try {
9112 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9113 } finally {
9114 Binder.restoreCallingIdentity(identity);
9115 }
9116 }
9117
9118 @Override
9119 public boolean setCdmaRoamingMode(int subId, int mode) {
9120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9121 mApp, subId, "setCdmaRoamingMode");
9122
9123 final long identity = Binder.clearCallingIdentity();
9124 try {
9125 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9126 } finally {
9127 Binder.restoreCallingIdentity(identity);
9128 }
9129 }
9130
9131 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009132 public int getCdmaSubscriptionMode(int subId) {
9133 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009134 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009135 mApp, subId, "getCdmaSubscriptionMode");
9136
9137 final long identity = Binder.clearCallingIdentity();
9138 try {
9139 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9140 } finally {
9141 Binder.restoreCallingIdentity(identity);
9142 }
9143 }
9144
9145 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009146 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9148 mApp, subId, "setCdmaSubscriptionMode");
9149
9150 final long identity = Binder.clearCallingIdentity();
9151 try {
9152 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9153 } finally {
9154 Binder.restoreCallingIdentity(identity);
9155 }
9156 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009157
sqianc5eccab2018-10-19 18:46:41 -07009158 @Override
sqian8c685422019-02-22 15:55:18 -08009159 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009160 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009162 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9163 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009164 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9165 }
9166 final long identity = Binder.clearCallingIdentity();
9167 try {
sqian854d44b2018-12-12 16:48:18 -08009168 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9169 for (Phone phone: PhoneFactory.getPhones()) {
9170 if (phone.getEmergencyNumberTracker() != null
9171 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9172 emergencyNumberListInternal.put(
9173 phone.getSubId(),
9174 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9175 }
sqian11b7a0e2018-12-05 18:48:28 -08009176 }
sqian854d44b2018-12-12 16:48:18 -08009177 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
sqianc5eccab2018-10-19 18:46:41 -07009181 }
9182
9183 @Override
sqian8c685422019-02-22 15:55:18 -08009184 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009185 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009186 if (!exactMatch) {
9187 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009188 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009189 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009190 }
9191 final long identity = Binder.clearCallingIdentity();
9192 try {
sqian854d44b2018-12-12 16:48:18 -08009193 for (Phone phone: PhoneFactory.getPhones()) {
9194 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009195 && phone.getEmergencyNumberTracker()
9196 .isEmergencyNumber(number, exactMatch)) {
9197 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009198 }
sqian11b7a0e2018-12-05 18:48:28 -08009199 }
9200 return false;
9201 } finally {
9202 Binder.restoreCallingIdentity(identity);
9203 }
9204 }
9205
sqianf4ca7ed2019-01-15 18:32:07 -08009206 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009207 * Start emergency callback mode for GsmCdmaPhone for testing.
9208 */
9209 @Override
9210 public void startEmergencyCallbackMode() {
9211 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9212 "startEmergencyCallbackMode");
9213 enforceModifyPermission();
9214 final long identity = Binder.clearCallingIdentity();
9215 try {
9216 for (Phone phone : PhoneFactory.getPhones()) {
9217 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9218 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9219 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9220 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9221 gsmCdmaPhone.obtainMessage(
9222 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9223 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9224 }
9225 }
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
9229 }
9230
9231 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009232 * Update emergency number list for test mode.
9233 */
9234 @Override
9235 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9237 "updateEmergencyNumberListTestMode");
9238
9239 final long identity = Binder.clearCallingIdentity();
9240 try {
9241 for (Phone phone: PhoneFactory.getPhones()) {
9242 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9243 if (tracker != null) {
9244 tracker.executeEmergencyNumberTestModeCommand(action, num);
9245 }
9246 }
9247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
9250 }
9251
9252 /**
9253 * Get the full emergency number list for test mode.
9254 */
9255 @Override
9256 public List<String> getEmergencyNumberListTestMode() {
9257 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9258 "getEmergencyNumberListTestMode");
9259
9260 final long identity = Binder.clearCallingIdentity();
9261 try {
9262 Set<String> emergencyNumbers = new HashSet<>();
9263 for (Phone phone: PhoneFactory.getPhones()) {
9264 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9265 if (tracker != null) {
9266 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9267 emergencyNumbers.add(num.getNumber());
9268 }
9269 }
9270 }
9271 return new ArrayList<>(emergencyNumbers);
9272 } finally {
9273 Binder.restoreCallingIdentity(identity);
9274 }
9275 }
9276
chen xud6b45bd2018-10-30 22:27:10 -07009277 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009278 public int getEmergencyNumberDbVersion(int subId) {
9279 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9280
9281 final long identity = Binder.clearCallingIdentity();
9282 try {
9283 final Phone phone = getPhone(subId);
9284 if (phone == null) {
9285 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9286 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9287 }
9288 return phone.getEmergencyNumberDbVersion();
9289 } finally {
9290 Binder.restoreCallingIdentity(identity);
9291 }
9292 }
9293
9294 @Override
9295 public void notifyOtaEmergencyNumberDbInstalled() {
9296 enforceModifyPermission();
9297
9298 final long identity = Binder.clearCallingIdentity();
9299 try {
9300 for (Phone phone: PhoneFactory.getPhones()) {
9301 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9302 if (tracker != null) {
9303 tracker.updateOtaEmergencyNumberDatabase();
9304 }
9305 }
9306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 }
9310
9311 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009312 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009313 enforceActiveEmergencySessionPermission();
9314
9315 final long identity = Binder.clearCallingIdentity();
9316 try {
9317 for (Phone phone: PhoneFactory.getPhones()) {
9318 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9319 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009320 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9321 }
9322 }
9323 } finally {
9324 Binder.restoreCallingIdentity(identity);
9325 }
9326 }
9327
9328 @Override
9329 public void resetOtaEmergencyNumberDbFilePath() {
9330 enforceActiveEmergencySessionPermission();
9331
9332 final long identity = Binder.clearCallingIdentity();
9333 try {
9334 for (Phone phone: PhoneFactory.getPhones()) {
9335 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9336 if (tracker != null) {
9337 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009338 }
9339 }
9340 } finally {
9341 Binder.restoreCallingIdentity(identity);
9342 }
9343 }
9344
9345 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009346 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9347 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9348 Phone phone = getPhone(subId);
9349 if (phone == null) {
9350 return null;
9351 }
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
9354 UiccProfile profile = UiccController.getInstance()
9355 .getUiccProfileForPhone(phone.getPhoneId());
9356 if (profile != null) {
9357 return profile.getCertsFromCarrierPrivilegeAccessRules();
9358 }
9359 } finally {
9360 Binder.restoreCallingIdentity(identity);
9361 }
9362 return null;
9363 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009364
9365 /**
9366 * Enable or disable a modem stack.
9367 */
9368 @Override
9369 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9370 enforceModifyPermission();
9371
9372 final long identity = Binder.clearCallingIdentity();
9373 try {
9374 Phone phone = PhoneFactory.getPhone(slotIndex);
9375 if (phone == null) {
9376 return false;
9377 } else {
9378 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9379 }
9380 } finally {
9381 Binder.restoreCallingIdentity(identity);
9382 }
9383 }
Michelecea4cf22018-12-21 15:00:11 -08009384
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009385 /**
9386 * Whether a modem stack is enabled or not.
9387 */
9388 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009389 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9390 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009391 Phone phone = PhoneFactory.getPhone(slotIndex);
9392 if (phone == null) return false;
9393
9394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009395 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9396 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009397 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9398 }
9399
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009402 try {
9403 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9404 } catch (NoSuchElementException ex) {
9405 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9406 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009407 } finally {
9408 Binder.restoreCallingIdentity(identity);
9409 }
9410 }
9411
Michelecea4cf22018-12-21 15:00:11 -08009412 @Override
Michele0ea7d782019-03-19 14:58:42 -07009413 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009414 enforceModifyPermission();
9415
9416 final long identity = Binder.clearCallingIdentity();
9417 try {
9418 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009419 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009420 .commit();
9421 } finally {
9422 Binder.restoreCallingIdentity(identity);
9423 }
9424 }
9425
9426 @Override
Michele0ea7d782019-03-19 14:58:42 -07009427 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009428 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009430 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9431 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009432 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009433 }
Michelecea4cf22018-12-21 15:00:11 -08009434
9435 final long identity = Binder.clearCallingIdentity();
9436 try {
Michele0ea7d782019-03-19 14:58:42 -07009437 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009442
Michele0ea7d782019-03-19 14:58:42 -07009443 @TelephonyManager.IsMultiSimSupportedResult
9444 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009445 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9446 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9447 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009448 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9449 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009450 }
9451 // Check if the hardware supports multisim functionality. If usage of multisim is not
9452 // supported by the modem, indicate that it is restricted.
9453 PhoneCapability staticCapability =
9454 mPhoneConfigurationManager.getStaticPhoneCapability();
9455 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009456 loge("isMultiSimSupportedInternal: no static configuration available");
9457 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009458 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009459 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009460 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9461 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009462 }
9463 // Check if support of multiple SIMs is restricted by carrier
9464 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009465 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009466 }
9467
Michele0ea7d782019-03-19 14:58:42 -07009468 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009469 }
9470
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009471 /**
9472 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009473 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9474 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9475 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009476 * @param numOfSims number of active sims we want to switch to
9477 */
9478 @Override
9479 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009480 if (numOfSims == 1) {
9481 enforceModifyPermission();
9482 } else {
9483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9484 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9485 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009486 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009487
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009488 try {
Michele30b57b22019-03-01 12:01:14 -08009489 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009490 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009491 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9492 return;
9493 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009494 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9495 } finally {
9496 Binder.restoreCallingIdentity(identity);
9497 }
9498 }
9499
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009500 @Override
9501 public boolean isApplicationOnUicc(int subId, int appType) {
9502 enforceReadPrivilegedPermission("isApplicationOnUicc");
9503 Phone phone = getPhone(subId);
9504 if (phone == null) {
9505 return false;
9506 }
9507 final long identity = Binder.clearCallingIdentity();
9508 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009509 UiccPort uiccPort = phone.getUiccPort();
9510 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009511 return false;
9512 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009513 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009514 if (uiccProfile == null) {
9515 return false;
9516 }
9517 if (TelephonyManager.APPTYPE_SIM <= appType
9518 && appType <= TelephonyManager.APPTYPE_ISIM) {
9519 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9520 }
9521 return false;
9522 } finally {
9523 Binder.restoreCallingIdentity(identity);
9524 }
9525 }
9526
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009527 /**
chen xub4baa772019-04-03 10:23:41 -07009528 * Get whether making changes to modem configurations will trigger reboot.
9529 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009530 */
9531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009532 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9533 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009535 mApp, subId, callingPackage, callingFeatureId,
9536 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009537 return false;
9538 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009539 final long identity = Binder.clearCallingIdentity();
9540 try {
9541 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9542 } finally {
9543 Binder.restoreCallingIdentity(identity);
9544 }
9545 }
9546
Nathan Harold29f5f052019-02-15 13:41:57 -08009547 private void updateModemStateMetrics() {
9548 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9549 // TODO: check the state for each modem if the api is ready.
9550 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9551 }
9552
Pengquan Meng3889a572019-01-23 11:16:29 -08009553 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009554 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009555 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009556 // Verify that the callingPackage belongs to the calling UID
9557 mApp.getSystemService(AppOpsManager.class)
9558 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009559 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009560 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009561 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009562 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9563 if (slotInfos != null) {
9564 for (int i = 0; i < slotInfos.length; i++) {
9565 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9566 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9567 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9568 portInfo.getLogicalSlotIndex()));
9569 }
9570 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009571 }
9572 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009573 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009574 } finally {
9575 Binder.restoreCallingIdentity(identity);
9576 }
9577 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009578
9579 /**
9580 * Get the IRadio HAL Version
9581 */
9582 @Override
9583 public int getRadioHalVersion() {
9584 Phone phone = getDefaultPhone();
9585 if (phone == null) return -1;
9586 HalVersion hv = phone.getHalVersion();
9587 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9588 return hv.major * 100 + hv.minor;
9589 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009590
9591 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009592 * Get the current calling package name.
9593 * @return the current calling package name
9594 */
9595 @Override
9596 public String getCurrentPackageName() {
9597 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9598 }
9599
9600 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009601 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9602 * corresponding network requests on a subId.
9603 *
9604 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009605 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009606 * 2) APN is un-metered for this subscription, or
9607 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009608 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009609 *
9610 * @return whether data is allowed for a apn type.
9611 *
9612 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009613 */
9614 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009615 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009616 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9617 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009618
9619 // Now that all security checks passes, perform the operation as ourselves.
9620 final long identity = Binder.clearCallingIdentity();
9621 try {
9622 Phone phone = getPhone(subId);
9623 if (phone == null) return false;
9624
Jack Yu41407ee2019-05-13 16:54:09 -07009625 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009626 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9627 } finally {
9628 Binder.restoreCallingIdentity(identity);
9629 }
9630 }
9631
9632 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009633 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009634 enforceReadPrivilegedPermission("isApnMetered");
9635
9636 // Now that all security checks passes, perform the operation as ourselves.
9637 final long identity = Binder.clearCallingIdentity();
9638 try {
9639 Phone phone = getPhone(subId);
9640 if (phone == null) return true; // By default return true.
9641
Jack Yu41407ee2019-05-13 16:54:09 -07009642 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009647
9648 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009649 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9650 int subscriptionId, IBooleanConsumer resultCallback) {
9651 enforceModifyPermission();
9652 long token = Binder.clearCallingIdentity();
9653 try {
9654 Phone phone = getPhone(subscriptionId);
9655 if (phone == null) {
9656 try {
9657 if (resultCallback != null) {
9658 resultCallback.accept(false);
9659 }
9660 } catch (RemoteException e) {
9661 // ignore
9662 }
9663 return;
9664 }
9665 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9666 Pair.create(specifiers, (x) -> {
9667 try {
9668 if (resultCallback != null) {
9669 resultCallback.accept(x);
9670 }
9671 } catch (RemoteException e) {
9672 // ignore
9673 }
9674 });
9675 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9676 } finally {
9677 Binder.restoreCallingIdentity(token);
9678 }
9679 }
9680
9681 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009682 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9683 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009684 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009685 mApp, subId, "getSystemSelectionChannels");
9686 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9687 final long identity = Binder.clearCallingIdentity();
9688 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009689 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9690 if (result instanceof IllegalStateException) {
9691 throw (IllegalStateException) result;
9692 }
9693 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009694 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9695 return specifiers;
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
9698 }
9699 }
9700
9701 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009702 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009703 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009704 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9705 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9706 if (iccRecords == null) {
9707 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9708 return false;
9709 }
9710 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9711 }
9712
9713 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009714 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9715 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009716 if (callingPackage == null) {
9717 callingPackage = getCurrentPackageName();
9718 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009719 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9720 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009721 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9722 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009723 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9724 }
9725 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9726 Intent intent = new Intent();
9727 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9728 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9729 // Bring up choose default SMS subscription dialog right now
9730 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9731 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9732 mApp.startActivity(intent);
9733 }
chen xud5ca2d52019-05-28 15:20:57 -07009734
9735 @Override
9736 public String getMmsUAProfUrl(int subId) {
9737 //TODO investigate if this API should require proper permission check in R b/133791609
9738 final long identity = Binder.clearCallingIdentity();
9739 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009740 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9741 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9742 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9743 return carrierUAProfUrl;
9744 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009745 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9746 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009747 } finally {
9748 Binder.restoreCallingIdentity(identity);
9749 }
9750 }
9751
9752 @Override
9753 public String getMmsUserAgent(int subId) {
9754 //TODO investigate if this API should require proper permission check in R b/133791609
9755 final long identity = Binder.clearCallingIdentity();
9756 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009757 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9758 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9759 if (!TextUtils.isEmpty(carrierUserAgent)) {
9760 return carrierUserAgent;
9761 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009762 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9763 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009764 } finally {
9765 Binder.restoreCallingIdentity(identity);
9766 }
9767 }
Jack Yub07d4972019-05-28 16:12:25 -07009768
9769 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009770 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9771 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009772
Jack Yub07d4972019-05-28 16:12:25 -07009773 final long identity = Binder.clearCallingIdentity();
9774 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009775 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009776 if (phone == null) return false;
9777
Hall Liua62f5da2020-09-25 10:42:19 -07009778 switch (policy) {
9779 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9780 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9781 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9782 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9783 default:
9784 throw new IllegalArgumentException(policy + " is not a valid policy");
9785 }
Jack Yub07d4972019-05-28 16:12:25 -07009786 } finally {
9787 Binder.restoreCallingIdentity(identity);
9788 }
9789 }
9790
9791 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009792 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009793 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009794 enforceModifyPermission();
9795
changbettyd5c246e2019-12-24 15:40:37 +08009796 final long identity = Binder.clearCallingIdentity();
9797 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009798 Phone phone = getPhone(subscriptionId);
9799 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009800
Hall Liua62f5da2020-09-25 10:42:19 -07009801 switch (policy) {
9802 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9803 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9804 break;
9805 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9806 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9807 break;
9808 default:
9809 throw new IllegalArgumentException(policy + " is not a valid policy");
9810 }
changbettyd5c246e2019-12-24 15:40:37 +08009811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 }
9815
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009816 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009817 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009818 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9819 * otherwise.
9820 */
9821 @Override
9822 public void setCepEnabled(boolean isCepEnabled) {
9823 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9824
9825 final long identity = Binder.clearCallingIdentity();
9826 try {
9827 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9828 for (Phone phone : PhoneFactory.getPhones()) {
9829 Phone defaultPhone = phone.getImsPhone();
9830 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9831 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9832 ImsPhoneCallTracker imsPhoneCallTracker =
9833 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9834 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9835 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9836 + imsPhone.getMsisdn());
9837 }
9838 }
9839 } finally {
9840 Binder.restoreCallingIdentity(identity);
9841 }
9842 }
allenwtsu46dcc572020-01-08 18:24:03 +08009843
9844 /**
9845 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9846 *
9847 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9848 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9849 * before being read.
9850 */
9851 @Override
9852 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9853 isCompressed) {
9854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9855 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9857 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9858 }
9859 if (!isImsAvailableOnDevice()) {
9860 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9861 "IMS not available on device.");
9862 }
9863
9864 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009865 try {
Hui Wang761a6682020-10-31 05:12:53 +00009866 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9867 } finally {
9868 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009869 }
9870 }
zoey chene02881a2019-12-30 16:11:23 +08009871
9872 @Override
9873 public boolean isIccLockEnabled(int subId) {
9874 enforceReadPrivilegedPermission("isIccLockEnabled");
9875
9876 // Now that all security checks passes, perform the operation as ourselves.
9877 final long identity = Binder.clearCallingIdentity();
9878 try {
9879 Phone phone = getPhone(subId);
9880 if (phone != null && phone.getIccCard() != null) {
9881 return phone.getIccCard().getIccLockEnabled();
9882 } else {
9883 return false;
9884 }
9885 } finally {
9886 Binder.restoreCallingIdentity(identity);
9887 }
9888 }
9889
9890 /**
9891 * Set the ICC pin lock enabled or disabled.
9892 *
9893 * @return an integer representing the status of IccLock enabled or disabled in the following
9894 * three cases:
9895 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9896 * successfully.
9897 * - Positive number and zero for remaining password attempts.
9898 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9899 *
9900 */
9901 @Override
9902 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9903 enforceModifyPermission();
9904
9905 Phone phone = getPhone(subId);
9906 if (phone == null) {
9907 return 0;
9908 }
9909 // Now that all security checks passes, perform the operation as ourselves.
9910 final long identity = Binder.clearCallingIdentity();
9911 try {
9912 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9913 new Pair<Boolean, String>(enabled, password), phone, null);
9914 return attemptsRemaining;
9915
9916 } catch (Exception e) {
9917 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9918 } finally {
9919 Binder.restoreCallingIdentity(identity);
9920 }
9921 return 0;
9922 }
9923
9924 /**
9925 * Change the ICC password used in ICC pin lock.
9926 *
9927 * @return an integer representing the status of IccLock changed in the following three cases:
9928 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9929 * - Positive number and zero for remaining password attempts.
9930 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9931 *
9932 */
9933 @Override
9934 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9935 enforceModifyPermission();
9936
9937 Phone phone = getPhone(subId);
9938 if (phone == null) {
9939 return 0;
9940 }
9941 // Now that all security checks passes, perform the operation as ourselves.
9942 final long identity = Binder.clearCallingIdentity();
9943 try {
9944 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9945 new Pair<String, String>(oldPassword, newPassword), phone, null);
9946 return attemptsRemaining;
9947
9948 } catch (Exception e) {
9949 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 return 0;
9954 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009955
9956 /**
9957 * Request for receiving user activity notification
9958 */
9959 @Override
9960 public void requestUserActivityNotification() {
9961 if (!mNotifyUserActivity.get()
9962 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9963 mNotifyUserActivity.set(true);
9964 }
9965 }
9966
9967 /**
9968 * Called when userActivity is signalled in the power manager.
9969 * This is safe to call from any thread, with any window manager locks held or not.
9970 */
9971 @Override
9972 public void userActivity() {
9973 // ***************************************
9974 // * Inherited from PhoneWindowManager *
9975 // ***************************************
9976 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9977 // WITH ITS LOCKS HELD.
9978 //
9979 // This code must be VERY careful about the locks
9980 // it acquires.
9981 // In fact, the current code acquires way too many,
9982 // and probably has lurking deadlocks.
9983
9984 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9985 throw new SecurityException("Only the OS may call notifyUserActivity()");
9986 }
9987
9988 if (mNotifyUserActivity.getAndSet(false)) {
9989 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9990 USER_ACTIVITY_NOTIFICATION_DELAY);
9991 }
9992 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009993
9994 @Override
9995 public boolean canConnectTo5GInDsdsMode() {
9996 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9997 }
Jack Yud10cdd42020-09-28 20:28:01 -07009998
9999 @Override
10000 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10001 String callingFeatureId) {
10002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10003 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10004 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10005 }
10006
10007 Phone phone = getPhone(subId);
10008 if (phone == null) {
10009 throw new RuntimeException("phone is not available");
10010 }
10011 // Now that all security checks passes, perform the operation as ourselves.
10012 final long identity = Binder.clearCallingIdentity();
10013 try {
10014 return phone.getEquivalentHomePlmns();
10015 } finally {
10016 Binder.restoreCallingIdentity(identity);
10017 }
10018 }
Daniel Bright59e67312020-11-13 11:49:37 -080010019
10020 @Override
10021 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010022 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10023 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010024 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010025 if (radioInterfaceCapabilities == null) {
10026 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010027 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010028 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010029 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010030
Hui Wang641e81c2020-10-12 12:14:23 -070010031 @Override
10032 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10033 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010034 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10035 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10036 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10037 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10038 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010039 if (DBG) {
10040 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10041 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10042 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10043 }
10044
10045 if (!SubscriptionManager.isValidSubscriptionId(subId)
10046 || appType < TelephonyManager.APPTYPE_UNKNOWN
10047 || appType > TelephonyManager.APPTYPE_ISIM
10048 || nafUrl == null || securityProtocol == null || callback == null) {
10049 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10050 if (callback != null) {
10051 try {
10052 callback.onAuthenticationFailure(
10053 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10054 } catch (RemoteException exception) {
10055 log("Fail to notify onAuthenticationFailure due to " + exception);
10056 }
10057 return;
10058 }
10059 }
10060
10061 final long token = Binder.clearCallingIdentity();
10062 try {
10063 getGbaManager(subId).bootstrapAuthenticationRequest(
10064 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10065 forceBootStrapping, callback));
10066 } finally {
10067 Binder.restoreCallingIdentity(token);
10068 }
10069 }
10070
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010071 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010072 * Attempts to set the radio power state for all phones for thermal reason.
10073 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010074 * requested radio power state will actually be set. See {@link
10075 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10076 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 * @param enable {@code true} if trying to turn radio on.
10078 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10079 * false}.
10080 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010081 private boolean setRadioPowerForThermal(boolean enable) {
10082 boolean isPhoneAvailable = false;
10083 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10084 Phone phone = PhoneFactory.getPhone(i);
10085 if (phone != null) {
10086 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10087 isPhoneAvailable = true;
10088 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010089 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010090
10091 // return true if successfully informed the phone object about the thermal radio power
10092 // request.
10093 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010094 }
10095
10096 private int handleDataThrottlingRequest(int subId,
10097 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010098 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10099 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10100 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10101 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10102 throw new IllegalArgumentException("modem does not support data throttling");
10103 }
10104
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010105 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10106 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010107 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010108 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10109 }
10110
10111 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10112
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010113 if (isDataThrottlingSupported) {
10114 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010115 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010116 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10117 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10118 } else if (thermalMitigationResult
10119 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010120 log("Modem likely does not support data throttling on secondary carrier. Data " +
10121 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10122 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010123 }
10124 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010125 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010126
10127 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010128 }
10129
Jack Nudelman644b91a2021-03-12 14:09:48 -080010130 private static List<String> getThermalMitigationAllowlist(Context context) {
10131 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10132 for (String pckg : context.getResources()
10133 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10134 sThermalMitigationAllowlistedPackages.add(pckg);
10135 }
10136 }
10137
10138 return sThermalMitigationAllowlistedPackages;
10139 }
10140
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010141 private boolean isAnyPhoneInEmergencyState() {
10142 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10143 if (tm.isInEmergencyCall()) {
10144 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10145 return true;
10146 }
10147 for (Phone phone : PhoneFactory.getPhones()) {
10148 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10149 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10150 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10151 + phone.isInEcm());
10152 return true;
10153 }
10154 }
10155
10156 return false;
10157 }
10158
Jack Nudelman644b91a2021-03-12 14:09:48 -080010159 /**
10160 * Used by shell commands to add an authorized package name for thermal mitigation.
10161 * @param packageName name of package to be allowlisted
10162 * @param context
10163 */
10164 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10165 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10166 sThermalMitigationAllowlistedPackages.add(packageName);
10167 }
10168
10169 /**
10170 * Used by shell commands to remove an authorized package name for thermal mitigation.
10171 * @param packageName name of package to remove from allowlist
10172 * @param context
10173 */
10174 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10175 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10176 sThermalMitigationAllowlistedPackages.remove(packageName);
10177 }
10178
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010179 /**
10180 * Thermal mitigation request to control functionalities at modem.
10181 *
10182 * @param subId the id of the subscription.
10183 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010184 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010185 *
10186 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10187 */
10188 @Override
10189 @ThermalMitigationResult
10190 public int sendThermalMitigationRequest(
10191 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010192 ThermalMitigationRequest thermalMitigationRequest,
10193 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010194 enforceModifyPermission();
10195
Jack Nudelman644b91a2021-03-12 14:09:48 -080010196 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10197 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10198 .contains(callingPackage)) {
10199 throw new SecurityException("Calling package must be configured in the device config. "
10200 + "calling package: " + callingPackage);
10201 }
10202
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010203 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10204 final long identity = Binder.clearCallingIdentity();
10205
10206 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10207 try {
10208 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10209 switch (thermalMitigationAction) {
10210 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10211 thermalMitigationResult =
10212 handleDataThrottlingRequest(subId,
10213 thermalMitigationRequest.getDataThrottlingRequest());
10214 break;
10215 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10216 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10217 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10218 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10219 }
10220
10221 // Ensure that radio is on. If not able to power on due to phone being
10222 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010223 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010224 thermalMitigationResult =
10225 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10226 break;
10227 }
10228
10229 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10230 false);
10231 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10232 break;
10233 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10234 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10235 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10236 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10237 }
10238
10239 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10240 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010241 Phone phone = getPhone(subId);
10242 if (phone == null) {
10243 thermalMitigationResult =
10244 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10245 break;
10246 }
10247
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010248 TelephonyConnectionService service =
10249 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010250 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010251 Log.e(LOG_TAG, "An emergency call is pending");
10252 thermalMitigationResult =
10253 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10254 break;
10255 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010256 thermalMitigationResult =
10257 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10258 break;
10259 }
10260 } else {
10261 thermalMitigationResult =
10262 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10263 break;
10264 }
10265
10266 // Turn radio off. If not able to power off due to phone being unavailable,
10267 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010268 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010269 thermalMitigationResult =
10270 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10271 break;
10272 }
10273 thermalMitigationResult =
10274 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10275 break;
10276 default:
10277 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10278 + "not exist. Requested action: " + thermalMitigationAction);
10279 }
10280 } catch (IllegalArgumentException e) {
10281 throw e;
10282 } catch (Exception e) {
10283 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10284 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288
10289 if (DBG) {
10290 log("thermalMitigationRequest returning with thermalMitigationResult: "
10291 + thermalMitigationResult);
10292 }
10293
10294 return thermalMitigationResult;
10295 }
Hui Wang641e81c2020-10-12 12:14:23 -070010296
10297 /**
10298 * Set the GbaService Package Name that Telephony will bind to.
10299 *
10300 * @param subId The sim that the GbaService is associated with.
10301 * @param packageName The name of the package to be replaced with.
10302 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10303 */
10304 @Override
10305 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10306 enforceModifyPermission();
10307
10308 final long identity = Binder.clearCallingIdentity();
10309 try {
10310 return getGbaManager(subId).overrideServicePackage(packageName);
10311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
10314 }
10315
10316 /**
10317 * Return the package name of the currently bound GbaService.
10318 *
10319 * @param subId The sim that the GbaService is associated with.
10320 * @return the package name of the GbaService configuration, null if GBA is not supported.
10321 */
10322 @Override
10323 public String getBoundGbaService(int subId) {
10324 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10325
10326 final long identity = Binder.clearCallingIdentity();
10327 try {
10328 return getGbaManager(subId).getServicePackage();
10329 } finally {
10330 Binder.restoreCallingIdentity(identity);
10331 }
10332 }
10333
10334 /**
10335 * Set the release time for telephony to unbind GbaService.
10336 *
10337 * @param subId The sim that the GbaService is associated with.
10338 * @param interval The release time to unbind GbaService by millisecond.
10339 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10340 */
10341 @Override
10342 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10343 enforceModifyPermission();
10344
10345 final long identity = Binder.clearCallingIdentity();
10346 try {
10347 return getGbaManager(subId).overrideReleaseTime(interval);
10348 } finally {
10349 Binder.restoreCallingIdentity(identity);
10350 }
10351 }
10352
10353 /**
10354 * Return the release time for telephony to unbind GbaService.
10355 *
10356 * @param subId The sim that the GbaService is associated with.
10357 * @return The release time to unbind GbaService by millisecond.
10358 */
10359 @Override
10360 public int getGbaReleaseTime(int subId) {
10361 enforceReadPrivilegedPermission("getGbaReleaseTime");
10362
10363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 return getGbaManager(subId).getReleaseTime();
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
10371 private GbaManager getGbaManager(int subId) {
10372 GbaManager instance = GbaManager.getInstance(subId);
10373 if (instance == null) {
10374 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10375 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10376 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10377 }
10378 return instance;
10379 }
Hui Wang761a6682020-10-31 05:12:53 +000010380
10381 /**
10382 * indicate whether the device and the carrier can support
10383 * RCS VoLTE single registration.
10384 */
10385 @Override
10386 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010387 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10388 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10389 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10390 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010391
10392 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10393 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10394 }
10395
10396 final long identity = Binder.clearCallingIdentity();
10397 try {
10398 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10399 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010400 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10401 if (isCapable != null) {
10402 return isCapable;
10403 }
Hui Wang761a6682020-10-31 05:12:53 +000010404 }
Hui Wang67af90e2021-06-04 16:57:15 -070010405 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10406 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010407 } finally {
10408 Binder.restoreCallingIdentity(identity);
10409 }
10410 }
10411
10412 /**
10413 * Register RCS provisioning callback.
10414 */
10415 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010416 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010417 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010418 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010419 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010420 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10421 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010422
10423 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10424 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10425 }
10426 if (!isImsAvailableOnDevice()) {
10427 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10428 "IMS not available on device.");
10429 }
10430
10431 final long identity = Binder.clearCallingIdentity();
10432 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010433 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010434 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010435 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10436 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010437 }
Hui Wang761a6682020-10-31 05:12:53 +000010438 } finally {
10439 Binder.restoreCallingIdentity(identity);
10440 }
10441 }
10442
10443 /**
10444 * Unregister RCS provisioning callback.
10445 */
10446 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010447 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010448 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010449 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010450 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010451 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10452 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010453
10454 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10455 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10456 }
10457 if (!isImsAvailableOnDevice()) {
10458 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10459 "IMS not available on device.");
10460 }
10461
10462 final long identity = Binder.clearCallingIdentity();
10463 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010464 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010465 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010466 } finally {
10467 Binder.restoreCallingIdentity(identity);
10468 }
10469 }
10470
10471 /**
10472 * trigger RCS reconfiguration.
10473 */
10474 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010475 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10476 "triggerRcsReconfiguration",
10477 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010478
10479 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10480 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10481 }
10482 if (!isImsAvailableOnDevice()) {
10483 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10484 "IMS not available on device.");
10485 }
10486
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
10489 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
10494
10495 /**
10496 * Provide the client configuration parameters of the RCS application.
10497 */
10498 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010499 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10500 "setRcsClientConfiguration",
10501 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010502
10503 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10504 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10505 }
10506 if (!isImsAvailableOnDevice()) {
10507 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10508 "IMS not available on device.");
10509 }
10510
10511 final long identity = Binder.clearCallingIdentity();
10512
10513 try {
10514 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10515 if (configBinder == null) {
10516 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010517 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10518 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010519 } else {
10520 configBinder.setRcsClientConfiguration(rcc);
10521 }
joonhunshin3e154242021-09-17 06:33:39 +000010522
10523 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10524 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010525 } catch (RemoteException e) {
10526 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010527 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10528 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010529 } finally {
10530 Binder.restoreCallingIdentity(identity);
10531 }
10532 }
10533
10534 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010535 * Enables or disables the test mode for RCS VoLTE single registration.
10536 */
10537 @Override
10538 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10539 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10540 "setRcsSingleRegistrationTestModeEnabled");
10541
10542 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10543 }
10544
10545 /**
10546 * Gets the test mode for RCS VoLTE single registration.
10547 */
10548 @Override
10549 public boolean getRcsSingleRegistrationTestModeEnabled() {
10550 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10551 "getRcsSingleRegistrationTestModeEnabled");
10552
10553 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10554 }
10555
10556 /**
Hui Wang761a6682020-10-31 05:12:53 +000010557 * Overrides the config of RCS VoLTE single registration enabled for the device.
10558 */
10559 @Override
10560 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10561 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10562 "setDeviceSingleRegistrationEnabledOverride");
10563 enforceModifyPermission();
10564
10565 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10566 : Boolean.parseBoolean(enabledStr);
10567 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010568 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010569 }
10570
10571 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010572 * Sends a device to device communication message. Only usable via shell.
10573 * @param message message to send.
10574 * @param value message value.
10575 */
10576 @Override
10577 public void sendDeviceToDeviceMessage(int message, int value) {
10578 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010579 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010580 enforceModifyPermission();
10581
10582 final long identity = Binder.clearCallingIdentity();
10583 try {
10584 TelephonyConnectionService service =
10585 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10586 if (service == null) {
10587 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10588 return;
10589 }
10590 service.sendTestDeviceToDeviceMessage(message, value);
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
10595
Tyler Gunnbabbda02021-02-10 11:05:02 -080010596 /**
10597 * Sets the specified device to device transport active.
10598 * @param transport The transport to set active.
10599 */
10600 @Override
10601 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10602 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10603 "setActiveDeviceToDeviceTransport");
10604 enforceModifyPermission();
10605
10606 final long identity = Binder.clearCallingIdentity();
10607 try {
10608 TelephonyConnectionService service =
10609 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10610 if (service == null) {
10611 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10612 return;
10613 }
10614 service.setActiveDeviceToDeviceTransport(transport);
10615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
Tyler Gunn92479152021-01-20 16:30:10 -080010619
Tyler Gunnd4339262021-05-03 14:46:49 -070010620 @Override
10621 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10623 "setDeviceToDeviceForceEnabled");
10624
10625 final long identity = Binder.clearCallingIdentity();
10626 try {
10627 Arrays.stream(PhoneFactory.getPhones()).forEach(
10628 p -> {
10629 Phone thePhone = p.getImsPhone();
10630 if (thePhone != null && thePhone instanceof ImsPhone) {
10631 ImsPhone imsPhone = (ImsPhone) thePhone;
10632 CallTracker tracker = imsPhone.getCallTracker();
10633 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10634 ImsPhoneCallTracker imsPhoneCallTracker =
10635 (ImsPhoneCallTracker) tracker;
10636 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10637 }
10638 }
10639 }
10640 );
10641 } finally {
10642 Binder.restoreCallingIdentity(identity);
10643 }
10644 }
10645
Tyler Gunn92479152021-01-20 16:30:10 -080010646 /**
Hui Wang761a6682020-10-31 05:12:53 +000010647 * Gets the config of RCS VoLTE single registration enabled for the device.
10648 */
10649 @Override
10650 public boolean getDeviceSingleRegistrationEnabled() {
10651 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10652 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10653 }
10654
10655 /**
10656 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10657 */
10658 @Override
10659 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10660 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10661 "setCarrierSingleRegistrationEnabledOverride");
10662 enforceModifyPermission();
10663
10664 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10665 : Boolean.parseBoolean(enabledStr);
10666 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10667 subId, enabled);
10668 }
10669
10670 /**
10671 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10672 */
10673 @Override
10674 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10675 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10676 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10677 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010678
10679 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010680 * Overrides the ims feature validation result
10681 */
10682 @Override
10683 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10685 "setImsFeatureValidationOverride");
10686
10687 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10688 : Boolean.parseBoolean(enabledStr);
10689 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10690 subId, enabled);
10691 }
10692
10693 /**
10694 * Gets the ims feature validation override value
10695 */
10696 @Override
10697 public boolean getImsFeatureValidationOverride(int subId) {
10698 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10699 "getImsFeatureValidationOverride");
10700 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10701 }
10702
10703 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010704 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10705 * their mobile plan.
10706 */
10707 @Override
10708 public String getMobileProvisioningUrl() {
10709 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10710 final long identity = Binder.clearCallingIdentity();
10711 try {
10712 return getDefaultPhone().getMobileProvisioningUrl();
10713 } finally {
10714 Binder.restoreCallingIdentity(identity);
10715 }
10716 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010717
James.cf Linbcdf8b32021-01-14 16:44:13 +080010718 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010719 * Get the EAB contact from the EAB database.
10720 */
10721 @Override
10722 public String getContactFromEab(String contact) {
10723 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10724 enforceModifyPermission();
10725 final long identity = Binder.clearCallingIdentity();
10726 try {
10727 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10728 } finally {
10729 Binder.restoreCallingIdentity(identity);
10730 }
10731 }
10732
10733 /**
Calvin Pana1434322021-07-01 19:27:01 +080010734 * Get the EAB capability from the EAB database.
10735 */
10736 @Override
10737 public String getCapabilityFromEab(String contact) {
10738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10739 enforceModifyPermission();
10740 final long identity = Binder.clearCallingIdentity();
10741 try {
10742 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10743 } finally {
10744 Binder.restoreCallingIdentity(identity);
10745 }
10746 }
10747
10748 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010749 * Remove the EAB contacts from the EAB database.
10750 */
10751 @Override
10752 public int removeContactFromEab(int subId, String contacts) {
10753 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10754 enforceModifyPermission();
10755 final long identity = Binder.clearCallingIdentity();
10756 try {
10757 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10758 } finally {
10759 Binder.restoreCallingIdentity(identity);
10760 }
10761 }
10762
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010763 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010764 public boolean getDeviceUceEnabled() {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10766 final long identity = Binder.clearCallingIdentity();
10767 try {
10768 return mApp.getDeviceUceEnabled();
10769 } finally {
10770 Binder.restoreCallingIdentity(identity);
10771 }
10772 }
10773
10774 @Override
10775 public void setDeviceUceEnabled(boolean isEnabled) {
10776 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10777 final long identity = Binder.clearCallingIdentity();
10778 try {
10779 mApp.setDeviceUceEnabled(isEnabled);
10780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
10784
Brad Ebinger14d467f2021-02-12 06:18:28 +000010785 /**
10786 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10787 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10788 */
10789 // Used for SHELL command only right now.
10790 @Override
10791 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10792 List<String> featureTags) {
10793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10794 "addUceRegistrationOverrideShell");
10795 final long identity = Binder.clearCallingIdentity();
10796 try {
10797 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10798 new ArraySet<>(featureTags));
10799 } catch (ImsException e) {
10800 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10801 } finally {
10802 Binder.restoreCallingIdentity(identity);
10803 }
10804 }
10805
10806 /**
10807 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10808 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10809 */
10810 // Used for SHELL command only right now.
10811 @Override
10812 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10813 List<String> featureTags) {
10814 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10815 "removeUceRegistrationOverrideShell");
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10819 new ArraySet<>(featureTags));
10820 } catch (ImsException e) {
10821 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
10827 /**
10828 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10829 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10830 */
10831 // Used for SHELL command only right now.
10832 @Override
10833 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10834 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10835 "clearUceRegistrationOverrideShell");
10836 final long identity = Binder.clearCallingIdentity();
10837 try {
10838 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10839 } catch (ImsException e) {
10840 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10841 } finally {
10842 Binder.restoreCallingIdentity(identity);
10843 }
10844 }
10845
10846 /**
10847 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10848 */
10849 // Used for SHELL command only right now.
10850 @Override
10851 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10853 "getLatestRcsContactUceCapabilityShell");
10854 final long identity = Binder.clearCallingIdentity();
10855 try {
10856 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10857 } catch (ImsException e) {
10858 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10859 } finally {
10860 Binder.restoreCallingIdentity(identity);
10861 }
10862 }
10863
10864 /**
10865 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10866 * device does not have an active PUBLISH.
10867 */
10868 // Used for SHELL command only right now.
10869 @Override
10870 public String getLastUcePidfXmlShell(int subId) {
10871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10872 final long identity = Binder.clearCallingIdentity();
10873 try {
10874 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10875 } catch (ImsException e) {
10876 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10877 } finally {
10878 Binder.restoreCallingIdentity(identity);
10879 }
10880 }
10881
James.cf Line8713a42021-04-29 16:04:26 +080010882 /**
10883 * Remove UCE requests cannot be sent to the network status.
10884 */
10885 // Used for SHELL command only right now.
10886 @Override
10887 public boolean removeUceRequestDisallowedStatus(int subId) {
10888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10892 } catch (ImsException e) {
10893 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
10898
James.cf Lin18bb9002021-05-25 01:37:38 +080010899 /**
10900 * Remove UCE requests cannot be sent to the network status.
10901 */
10902 // Used for SHELL command only.
10903 @Override
10904 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10909 } catch (ImsException e) {
10910 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010915
James.cf Lin4b784aa2021-01-31 03:25:15 +080010916 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010917 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10918 String callingPackage) {
10919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10920 mApp, subId, "setSignalStrengthUpdateRequest");
10921
10922 final int callingUid = Binder.getCallingUid();
10923 // Verify that tha callingPackage belongs to the calling UID
10924 mApp.getSystemService(AppOpsManager.class)
10925 .checkPackage(callingUid, callingPackage);
10926
Rambo Wang3607f502021-02-01 21:51:40 -080010927 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010928
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
10931 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10932 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10933
10934 if (result instanceof IllegalStateException) {
10935 throw (IllegalStateException) result;
10936 }
10937 } finally {
10938 Binder.restoreCallingIdentity(identity);
10939 }
10940 }
10941
10942 @Override
10943 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10944 String callingPackage) {
10945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10946 mApp, subId, "clearSignalStrengthUpdateRequest");
10947
10948 final int callingUid = Binder.getCallingUid();
10949 // Verify that tha callingPackage belongs to the calling UID
10950 mApp.getSystemService(AppOpsManager.class)
10951 .checkPackage(callingUid, callingPackage);
10952
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
10955 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10956 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10957
10958 if (result instanceof IllegalStateException) {
10959 throw (IllegalStateException) result;
10960 }
10961 } finally {
10962 Binder.restoreCallingIdentity(identity);
10963 }
10964 }
10965
Rambo Wang3607f502021-02-01 21:51:40 -080010966 private static void validateSignalStrengthUpdateRequest(Context context,
10967 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010968 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10969 // phone/system process do not have further restriction on request
10970 return;
10971 }
10972
10973 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010974 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010975 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010976 context.enforceCallingOrSelfPermission(
10977 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10978 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010979 }
10980
10981 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10982 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10983 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10984 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10985 || info.isEnabled()) {
10986 throw new IllegalArgumentException(
10987 "Only system can set hide fields in SignalThresholdInfo");
10988 }
10989
10990 // Thresholds length for each RAN need in range. This has been validated in
10991 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10992 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10993 final int[] thresholds = info.getThresholds();
10994 Objects.requireNonNull(thresholds);
10995 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10996 || thresholds.length
10997 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10998 throw new IllegalArgumentException(
10999 "thresholds length is out of range: " + thresholds.length);
11000 }
11001 }
11002 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011003
11004 /**
11005 * Gets the current phone capability.
11006 *
11007 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11008 * @return the PhoneCapability which describes the data connection capability of modem.
11009 * It's used to evaluate possible phone config change, for example from single
11010 * SIM device to multi-SIM device.
11011 */
11012 @Override
11013 public PhoneCapability getPhoneCapability() {
11014 enforceReadPrivilegedPermission("getPhoneCapability");
11015 final long identity = Binder.clearCallingIdentity();
11016 try {
11017 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
Michele Berionne5e411512020-11-13 02:36:59 +000011022
11023 /**
11024 * Prepare TelephonyManager for an unattended reboot. The reboot is
11025 * required to be done shortly after the API is invoked.
11026 */
11027 @Override
11028 @TelephonyManager.PrepareUnattendedRebootResult
11029 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011031 enforceRebootPermission();
11032
11033 final long identity = Binder.clearCallingIdentity();
11034 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011035 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011036 } finally {
11037 Binder.restoreCallingIdentity(identity);
11038 }
11039 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011040
11041 /**
11042 * Request to get the current slicing configuration including URSP rules and
11043 * NSSAIs (configured, allowed and rejected).
11044 *
11045 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11046 */
11047 @Override
11048 public void getSlicingConfig(ResultReceiver callback) {
11049 enforceReadPrivilegedPermission("getSlicingConfig");
11050
11051 final long identity = Binder.clearCallingIdentity();
11052 try {
11053 Phone phone = getDefaultPhone();
11054 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11055 } finally {
11056 Binder.restoreCallingIdentity(identity);
11057 }
11058 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011059
11060 /**
11061 * Register an IMS connection state callback
11062 */
11063 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011064 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11065 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011066 if (feature == ImsFeature.FEATURE_MMTEL) {
11067 // ImsMmTelManager
11068 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11069 TelephonyPermissions
11070 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11071 mApp, subId, "registerImsStateCallback");
11072 } else if (feature == ImsFeature.FEATURE_RCS) {
11073 // ImsRcsManager or SipDelegateManager
11074 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11075 Binder.getCallingUid(), "registerImsStateCallback",
11076 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11077 Manifest.permission.READ_PRECISE_PHONE_STATE,
11078 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11079 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11080 }
11081
11082 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11083 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11084 "IMS not available on device.");
11085 }
11086
11087 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11088 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11089 }
11090
11091 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11092 if (controller == null) {
11093 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11094 "IMS not available on device.");
11095 }
11096
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011097 if (callingPackage == null) {
11098 callingPackage = getCurrentPackageName();
11099 }
11100
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011101 final long token = Binder.clearCallingIdentity();
11102 try {
11103 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011104 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011105 } catch (ImsException e) {
11106 throw new ServiceSpecificException(e.getCode());
11107 } finally {
11108 Binder.restoreCallingIdentity(token);
11109 }
11110 }
11111
11112 /**
11113 * Unregister an IMS connection state callback
11114 */
11115 @Override
11116 public void unregisterImsStateCallback(IImsStateCallback cb) {
11117 final long token = Binder.clearCallingIdentity();
11118 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11119 if (controller == null) {
11120 return;
11121 }
11122 try {
11123 controller.unregisterImsStateCallback(cb);
11124 } finally {
11125 Binder.restoreCallingIdentity(token);
11126 }
11127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011128}