blob: 765ee77623b451c0a18ea858dbecf90d60147bf2 [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) {
2942 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2943 } else {
2944 return PhoneConstantConversions.convertDataState(
2945 PhoneConstants.DataState.DISCONNECTED);
2946 }
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002950 }
2951
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002953 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002954 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2955 }
2956
2957 @Override
2958 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959 final long identity = Binder.clearCallingIdentity();
2960 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002961 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 if (phone != null) {
2963 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2964 } else {
2965 return TelephonyManager.DATA_ACTIVITY_NONE;
2966 }
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002970 }
2971
2972 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002973 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002974 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002975 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002976
2977 LocationAccessPolicy.LocationPermissionResult locationResult =
2978 LocationAccessPolicy.checkLocationPermission(mApp,
2979 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2980 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002981 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002982 .setCallingPid(Binder.getCallingPid())
2983 .setCallingUid(Binder.getCallingUid())
2984 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002985 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002986 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2987 .build());
2988 switch (locationResult) {
2989 case DENIED_HARD:
2990 throw new SecurityException("Not allowed to access cell location");
2991 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002992 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2993 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002994 }
2995
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002996 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003000 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003001 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
Svetoslav64fad262015-04-14 14:35:21 -07003005 }
3006
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003008 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003009 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3010 // registered cell info, so return a NULL country instead.
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003013 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3014 // Get default phone in this case.
3015 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3016 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003017 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003019 if (phone == null) return "";
3020 ServiceStateTracker sst = phone.getServiceStateTracker();
3021 if (sst == null) return "";
3022 LocaleTracker lt = sst.getLocaleTracker();
3023 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003024 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003028 }
3029
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003030 /**
3031 * This method was removed due to potential issues caused by performing partial
3032 * updates of service state, and lack of a credible use case.
3033 *
3034 * This has the ability to break the telephony implementation by disabling notification of
3035 * changes in device connectivity. DO NOT USE THIS!
3036 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003037 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 public void enableLocationUpdates() {
3039 mApp.enforceCallingOrSelfPermission(
3040 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 }
3042
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003043 /**
3044 * This method was removed due to potential issues caused by performing partial
3045 * updates of service state, and lack of a credible use case.
3046 *
3047 * This has the ability to break the telephony implementation by disabling notification of
3048 * changes in device connectivity. DO NOT USE THIS!
3049 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003050 @Override
3051 public void disableLocationUpdates() {
3052 mApp.enforceCallingOrSelfPermission(
3053 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 }
3055
3056 @Override
3057 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003058 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3059 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003060 try {
3061 mApp.getSystemService(AppOpsManager.class)
3062 .checkPackage(Binder.getCallingUid(), callingPackage);
3063 } catch (SecurityException e) {
3064 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3065 throw e;
3066 }
3067
Nathan Haroldf096d982020-11-18 17:18:06 -08003068 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003069 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3070 throw new SecurityException(
3071 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3072 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003073
Jordan Liu1617b712019-07-10 15:06:26 -07003074 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3076 return null;
3077 }
Svetoslav64fad262015-04-14 14:35:21 -07003078
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003079 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003081 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003082 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003083
Nathan Haroldf180aac2018-06-01 18:43:55 -07003084 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3085 for (CellInfo ci : info) {
3086 if (ci instanceof CellInfoGsm) {
3087 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3088 } else if (ci instanceof CellInfoWcdma) {
3089 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003092 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 }
3094
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003095 private List<CellInfo> getCachedCellInfo() {
3096 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3097 for (Phone phone : PhoneFactory.getPhones()) {
3098 List<CellInfo> info = phone.getAllCellInfo();
3099 if (info != null) cellInfos.addAll(info);
3100 }
3101 return cellInfos;
3102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103
3104 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003105 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003106 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003107 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003108
3109 LocationAccessPolicy.LocationPermissionResult locationResult =
3110 LocationAccessPolicy.checkLocationPermission(mApp,
3111 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3112 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003113 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003114 .setCallingPid(Binder.getCallingPid())
3115 .setCallingUid(Binder.getCallingUid())
3116 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003117 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003118 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3119 .build());
3120 switch (locationResult) {
3121 case DENIED_HARD:
3122 throw new SecurityException("Not allowed to access cell info");
3123 case DENIED_SOFT:
3124 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 }
3126
Nathan Haroldf096d982020-11-18 17:18:06 -08003127 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003128 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3129 return getCachedCellInfo();
3130 }
3131
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003132 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003133 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3137 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003138 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003139 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140 if (info != null) cellInfos.addAll(info);
3141 }
3142 return cellInfos;
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 }
3146 }
3147
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003148 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003149 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3150 String callingFeatureId) {
3151 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3152 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003153 }
3154
3155 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003156 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3157 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003158 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003159 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003160 }
3161
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003162 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3163 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003164 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003165 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003166
3167 LocationAccessPolicy.LocationPermissionResult locationResult =
3168 LocationAccessPolicy.checkLocationPermission(mApp,
3169 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3170 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003171 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003172 .setCallingPid(Binder.getCallingPid())
3173 .setCallingUid(Binder.getCallingUid())
3174 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003175 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3176 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003177 .build());
3178 switch (locationResult) {
3179 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003180 if (TelephonyPermissions
3181 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003182 // Safetynet logging for b/154934934
3183 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3184 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 throw new SecurityException("Not allowed to access cell info");
3186 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003187 if (TelephonyPermissions
3188 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003189 // Safetynet logging for b/154934934
3190 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3191 }
Nathan Harold5320c422019-05-09 10:26:08 -07003192 try {
3193 cb.onCellInfo(new ArrayList<CellInfo>());
3194 } catch (RemoteException re) {
3195 // Drop without consequences
3196 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003197 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003198 }
3199
Nathan Harolda939a962019-05-09 10:13:47 -07003200
3201 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003202 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3203
3204 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3205 }
3206
3207 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003209 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003210 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211
3212 final long identity = Binder.clearCallingIdentity();
3213 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003218 }
3219
Shishir Agrawala9f32182016-04-12 12:00:16 -07003220 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003221 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003222 Phone phone = PhoneFactory.getPhone(slotIndex);
3223 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003224 return null;
3225 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003226 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003227 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003228 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003229 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003230 return null;
3231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 return phone.getImei();
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003239 }
3240
3241 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003242 public String getTypeAllocationCodeForSlot(int slotIndex) {
3243 Phone phone = PhoneFactory.getPhone(slotIndex);
3244 String tac = null;
3245 if (phone != null) {
3246 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003247 try {
3248 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3249 } catch (IndexOutOfBoundsException e) {
3250 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3251 return null;
3252 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003253 }
3254 return tac;
3255 }
3256
3257 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003258 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003259 try {
3260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3261 } catch (SecurityException se) {
3262 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3263 throw new SecurityException("Package " + callingPackage + " does not belong to "
3264 + Binder.getCallingUid());
3265 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003266 Phone phone = PhoneFactory.getPhone(slotIndex);
3267 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003268 return null;
3269 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003270
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003272 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003273 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003274 return null;
3275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276
3277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 return phone.getMeid();
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
Jack Yu2af8d712017-03-15 17:14:14 -07003283 }
3284
3285 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003286 public String getManufacturerCodeForSlot(int slotIndex) {
3287 Phone phone = PhoneFactory.getPhone(slotIndex);
3288 String manufacturerCode = null;
3289 if (phone != null) {
3290 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003291 try {
3292 manufacturerCode =
3293 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3294 } catch (IndexOutOfBoundsException e) {
3295 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3296 return null;
3297 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003298 }
3299 return manufacturerCode;
3300 }
3301
3302 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003303 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3304 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003305 Phone phone = PhoneFactory.getPhone(slotIndex);
3306 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003307 return null;
3308 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003309 int subId = phone.getSubId();
3310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003311 mApp, subId, callingPackage, callingFeatureId,
3312 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003313 return null;
3314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315
3316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 return phone.getDeviceSvn();
3319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003322 }
3323
fionaxu43304da2017-11-27 22:51:16 -08003324 @Override
3325 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 final Phone phone = getPhone(subId);
3329 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
fionaxu43304da2017-11-27 22:51:16 -08003333 }
3334
3335 @Override
3336 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 final Phone phone = getPhone(subId);
3340 return phone == null ? null : phone.getCarrierName();
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
fionaxu43304da2017-11-27 22:51:16 -08003344 }
3345
calvinpanffe225e2018-11-01 19:43:06 +08003346 @Override
chen xu0026ca62019-03-06 15:28:50 -08003347 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 final Phone phone = getPhone(subId);
3351 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003352 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
3356 }
3357
3358 @Override
chen xu0026ca62019-03-06 15:28:50 -08003359 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003363 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
3367 }
3368
chen xu651eec72018-11-11 19:03:44 -08003369 @Override
chen xu864e11c2018-12-06 22:10:03 -08003370 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3371 if (!isSubscriptionMccMnc) {
3372 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3373 }
chen xu651eec72018-11-11 19:03:44 -08003374 final Phone phone = PhoneFactory.getPhone(slotIndex);
3375 if (phone == null) {
3376 return TelephonyManager.UNKNOWN_CARRIER_ID;
3377 }
3378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386 //
3387 // Internal helper methods.
3388 //
3389
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003390 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003391 * Make sure the caller is the calling package itself
3392 *
3393 * @throws SecurityException if the caller is not the calling package
3394 */
3395 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3396 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003397 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3398 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003399 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003400 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003401 } catch (PackageManager.NameNotFoundException e) {
3402 // packageUid is -1
3403 }
3404 if (packageUid != callingUid) {
3405 throw new SecurityException(message + ": Package " + callingPackage
3406 + " does not belong to " + callingUid);
3407 }
3408 }
3409
3410 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003411 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3412 *
3413 * @throws SecurityException if the caller does not have the required permission
3414 */
3415 private void enforceModifyPermission() {
3416 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3417 }
3418
Shuo Qian3b6ee772019-11-13 17:43:31 -08003419 private void enforceActiveEmergencySessionPermission() {
3420 mApp.enforceCallingOrSelfPermission(
3421 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3422 }
3423
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003424 /**
3425 * Make sure the caller has the CALL_PHONE permission.
3426 *
3427 * @throws SecurityException if the caller does not have the required permission
3428 */
3429 private void enforceCallPermission() {
3430 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3431 }
3432
paulhu5a773602019-08-23 19:17:33 +08003433 private void enforceSettingsPermission() {
3434 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003435 }
3436
Michele Berionne5e411512020-11-13 02:36:59 +00003437 private void enforceRebootPermission() {
3438 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3439 }
3440
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003441 private String createTelUrl(String number) {
3442 if (TextUtils.isEmpty(number)) {
3443 return null;
3444 }
3445
Jake Hambye994d462014-02-03 13:10:13 -08003446 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 }
3448
Ihab Awadf9e92732013-12-05 18:02:52 -08003449 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3451 }
3452
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003453 private static void logv(String msg) {
3454 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3455 }
3456
Ihab Awadf9e92732013-12-05 18:02:52 -08003457 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003458 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3459 }
3460
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003461 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003462 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003463 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003464 }
3465
Sanket Padawe356d7632015-06-22 14:03:32 -07003466 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003467 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003468 final long identity = Binder.clearCallingIdentity();
3469 try {
3470 final Phone phone = PhoneFactory.getPhone(slotIndex);
3471 if (phone == null) {
3472 return PhoneConstants.PHONE_TYPE_NONE;
3473 } else {
3474 return phone.getPhoneType();
3475 }
3476 } finally {
3477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003479 }
3480
3481 /**
3482 * Returns the CDMA ERI icon index to display
3483 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003485 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3486 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3487 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003488 }
3489
Sanket Padawe356d7632015-06-22 14:03:32 -07003490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003491 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3492 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003494 mApp, subId, callingPackage, callingFeatureId,
3495 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003496 return -1;
3497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 final Phone phone = getPhone(subId);
3502 if (phone != null) {
3503 return phone.getCdmaEriIconIndex();
3504 } else {
3505 return -1;
3506 }
3507 } finally {
3508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510 }
3511
3512 /**
3513 * Returns the CDMA ERI icon mode,
3514 * 0 - ON
3515 * 1 - FLASHING
3516 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003517 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003518 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3519 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3520 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003521 }
3522
Sanket Padawe356d7632015-06-22 14:03:32 -07003523 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003524 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3525 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003527 mApp, subId, callingPackage, callingFeatureId,
3528 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003529 return -1;
3530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 final Phone phone = getPhone(subId);
3535 if (phone != null) {
3536 return phone.getCdmaEriIconMode();
3537 } else {
3538 return -1;
3539 }
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543 }
3544
3545 /**
3546 * Returns the CDMA ERI text,
3547 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003548 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003549 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3550 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3551 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003552 }
3553
Sanket Padawe356d7632015-06-22 14:03:32 -07003554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003555 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3556 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 mApp, subId, callingPackage, callingFeatureId,
3559 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003560 return null;
3561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 final Phone phone = getPhone(subId);
3566 if (phone != null) {
3567 return phone.getCdmaEriText();
3568 } else {
3569 return null;
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 }
3575
3576 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003577 * Returns the CDMA MDN.
3578 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003579 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003580 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3582 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583
3584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003587 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588 return phone.getLine1Number();
3589 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591 return null;
3592 }
3593 } finally {
3594 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003595 }
3596 }
3597
3598 /**
3599 * Returns the CDMA MIN.
3600 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003601 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003602 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3604 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 final Phone phone = getPhone(subId);
3609 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3610 return phone.getCdmaMin();
3611 } else {
3612 return null;
3613 }
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003616 }
3617 }
3618
Hall Liud892bec2018-11-30 14:51:45 -08003619 @Override
3620 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3621 INumberVerificationCallback callback, String callingPackage) {
3622 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3623 != PERMISSION_GRANTED) {
3624 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3625 }
3626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3627
3628 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3629 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003630 throw new SecurityException("Calling package must be configured in the device config: "
3631 + "calling package: " + callingPackage
3632 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003633 }
3634
3635 if (range == null) {
3636 throw new NullPointerException("Range must be non-null");
3637 }
3638
3639 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003640 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003641
3642 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3643 }
3644
Junda Liuca05d5d2014-08-14 22:36:34 -07003645 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 * Returns true if CDMA provisioning needs to run.
3647 */
3648 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003655 }
3656
3657 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003658 * Sets the voice mail number of a given subId.
3659 */
3660 @Override
3661 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003662 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3663 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3668 new Pair<String, String>(alphaTag, number), new Integer(subId));
3669 return success;
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
3672 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003673 }
3674
Ta-wei Yen87c49842016-05-13 21:19:52 -07003675 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003676 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3677 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003678 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3679 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003680 if (!TextUtils.equals(callingPackage, systemDialer)) {
3681 throw new SecurityException("caller must be system dialer");
3682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3687 if (phoneAccountHandle == null) {
3688 return null;
3689 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003690 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003693 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003694 }
3695
3696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003697 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3698 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003701 mApp, subId, callingPackage, callingFeatureId,
3702 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003703 return null;
3704 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003706 final long identity = Binder.clearCallingIdentity();
3707 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003712 }
3713
3714 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003715 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3716 VisualVoicemailSmsFilterSettings settings) {
3717 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003726 }
3727
3728 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003729 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3730 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003735 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003739 }
3740
3741 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003742 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3743 String callingPackage, int subId) {
3744 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745
3746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003749 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003753 }
3754
3755 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003756 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758
3759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003762 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003766 }
3767
3768 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003769 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3770 String callingAttributionTag, int subId, String number, int port, String text,
3771 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003772 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003773 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003774 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003775 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003776 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3777 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003778 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003779
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003780 /**
fionaxu0152e512016-11-14 13:36:14 -08003781 * Sets the voice activation state of a given subId.
3782 */
3783 @Override
3784 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3786 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003787
3788 final long identity = Binder.clearCallingIdentity();
3789 try {
3790 final Phone phone = getPhone(subId);
3791 if (phone != null) {
3792 phone.setVoiceActivationState(activationState);
3793 } else {
3794 loge("setVoiceActivationState fails with invalid subId: " + subId);
3795 }
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003798 }
3799 }
3800
3801 /**
3802 * Sets the data activation state of a given subId.
3803 */
3804 @Override
3805 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3807 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808
3809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 final Phone phone = getPhone(subId);
3812 if (phone != null) {
3813 phone.setDataActivationState(activationState);
3814 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003815 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 }
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003819 }
3820 }
3821
3822 /**
3823 * Returns the voice activation state of a given subId.
3824 */
3825 @Override
3826 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828
fionaxu0152e512016-11-14 13:36:14 -08003829 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 if (phone != null) {
3833 return phone.getVoiceActivationState();
3834 } else {
3835 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003839 }
3840 }
3841
3842 /**
3843 * Returns the data activation state of a given subId.
3844 */
3845 @Override
3846 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848
fionaxu0152e512016-11-14 13:36:14 -08003849 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 if (phone != null) {
3853 return phone.getDataActivationState();
3854 } else {
3855 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3856 }
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003859 }
3860 }
3861
3862 /**
Wink Saville36469e72014-06-11 15:17:00 -07003863 * Returns the unread count of voicemails for a subId
3864 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003865 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003866 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3867 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003868 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003869 mApp, subId, callingPackage, callingFeatureId,
3870 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003871 return 0;
3872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 final Phone phone = getPhone(subId);
3876 if (phone != null) {
3877 return phone.getVoiceMessageCount();
3878 } else {
3879 return 0;
3880 }
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003884 }
3885
3886 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003887 * returns true, if the device is in a state where both voice and data
3888 * are supported simultaneously. This can change based on location or network condition.
3889 */
3890 @Override
3891 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 final Phone phone = getPhone(subId);
3895 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3896 } finally {
3897 Binder.restoreCallingIdentity(identity);
3898 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003899 }
3900
3901 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003902 * Send the dialer code if called from the current default dialer or the caller has
3903 * carrier privilege.
3904 * @param inputCode The dialer code to send
3905 */
3906 @Override
3907 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003908 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003910 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3911 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003912 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003913 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003914 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003916
3917 final long identity = Binder.clearCallingIdentity();
3918 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003919 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 } finally {
3921 Binder.restoreCallingIdentity(identity);
3922 }
fionaxu235cc5e2017-03-06 22:25:57 -08003923 }
3924
Pengquan Menga1bb6272018-09-06 09:59:22 -07003925 @Override
3926 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003927 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003928 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003929 mApp, subId, "getNetworkSelectionMode");
3930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 if (!isActiveSubscription(subId)) {
3933 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3934 }
3935 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003939 }
3940
Brad Ebinger35c841c2018-10-01 10:40:55 -07003941 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003942 public boolean isInEmergencySmsMode() {
3943 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 for (Phone phone : PhoneFactory.getPhones()) {
3947 if (phone.isInEmergencySmsMode()) {
3948 return true;
3949 }
3950 }
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
3953 }
3954 return false;
3955 }
3956
shilu366312e2019-12-17 09:28:10 -08003957 /**
3958 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3959 * @param subId The subscription to use to check the configuration.
3960 * @param c The callback that will be used to send the result.
3961 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003962 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003963 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3964 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003965 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003966 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003967
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003968 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3969 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3970 "IMS not available on device.");
3971 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 final long token = Binder.clearCallingIdentity();
3973 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003974 int slotId = getSlotIndexOrException(subId);
3975 verifyImsMmTelConfiguredOrThrow(slotId);
3976 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003977 } catch (ImsException e) {
3978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 } finally {
3980 Binder.restoreCallingIdentity(token);
3981 }
3982 }
3983
shilu366312e2019-12-17 09:28:10 -08003984 /**
3985 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3986 * @param subId The subscription to use to check the configuration.
3987 * @param c The callback that will be used to send the result.
3988 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003990 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003991 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003992 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003993 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3994 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3995 }
Meng Wangafbc5852019-09-19 17:37:13 -07003996 final long token = Binder.clearCallingIdentity();
3997 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003998 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3999 .removeRegistrationCallbackForSubscription(c, subId);
4000 } catch (ImsException e) {
4001 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4002 + "is inactive, ignoring unregister.");
4003 // If the subscription is no longer active, just return, since the callback
4004 // will already have been removed internally.
4005 } finally {
4006 Binder.restoreCallingIdentity(token);
4007 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 }
4009
Brad Ebingera34a6c22019-10-22 17:36:18 -07004010 /**
4011 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4012 */
4013 @Override
4014 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4015 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4016 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4017 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4018 "IMS not available on device.");
4019 }
4020 final long token = Binder.clearCallingIdentity();
4021 try {
4022 Phone phone = getPhone(subId);
4023 if (phone == null) {
4024 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4025 + subId + "'");
4026 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4027 }
4028 phone.getImsRegistrationState(regState -> {
4029 try {
4030 consumer.accept((regState == null)
4031 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4032 } catch (RemoteException e) {
4033 // Ignore if the remote process is no longer available to call back.
4034 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4035 }
4036 });
4037 } finally {
4038 Binder.restoreCallingIdentity(token);
4039 }
4040 }
4041
4042 /**
4043 * Get the transport type for the IMS service registration state.
4044 */
4045 @Override
4046 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004047 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004048 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004049 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4050 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4051 "IMS not available on device.");
4052 }
4053 final long token = Binder.clearCallingIdentity();
4054 try {
4055 Phone phone = getPhone(subId);
4056 if (phone == null) {
4057 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4058 + subId + "'");
4059 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4060 }
4061 phone.getImsRegistrationTech(regTech -> {
4062 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4063 int regTechConverted = (regTech == null)
4064 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4065 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4066 regTechConverted);
4067 try {
4068 consumer.accept(regTechConverted);
4069 } catch (RemoteException e) {
4070 // Ignore if the remote process is no longer available to call back.
4071 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4072 }
4073 });
4074 } finally {
4075 Binder.restoreCallingIdentity(token);
4076 }
4077 }
4078
shilu366312e2019-12-17 09:28:10 -08004079 /**
4080 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4081 * @param subId The subscription to use to check the configuration.
4082 * @param c The callback that will be used to send the result.
4083 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004085 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4086 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004087 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004088 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004089 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4090 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4091 "IMS not available on device.");
4092 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 final long token = Binder.clearCallingIdentity();
4094 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004095 int slotId = getSlotIndexOrException(subId);
4096 verifyImsMmTelConfiguredOrThrow(slotId);
4097 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004098 } catch (ImsException e) {
4099 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 } finally {
4101 Binder.restoreCallingIdentity(token);
4102 }
4103 }
4104
shilu366312e2019-12-17 09:28:10 -08004105 /**
4106 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4107 * @param subId The subscription to use to check the configuration.
4108 * @param c The callback that will be used to send the result.
4109 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004111 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004112 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004113 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4116 }
Meng Wangafbc5852019-09-19 17:37:13 -07004117
4118 final long token = Binder.clearCallingIdentity();
4119 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004120 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004121 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004122 } catch (ImsException e) {
4123 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4124 + "is inactive, ignoring unregister.");
4125 // If the subscription is no longer active, just return, since the callback
4126 // will already have been removed internally.
4127 } finally {
4128 Binder.restoreCallingIdentity(token);
4129 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 }
4131
4132 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004133 public boolean isCapable(int subId, int capability, int regTech) {
4134 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 final long token = Binder.clearCallingIdentity();
4136 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004137 int slotId = getSlotIndexOrException(subId);
4138 verifyImsMmTelConfiguredOrThrow(slotId);
4139 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004140 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4142 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004144 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4145 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 } finally {
4147 Binder.restoreCallingIdentity(token);
4148 }
4149 }
4150
4151 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004152 public boolean isAvailable(int subId, int capability, int regTech) {
4153 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 final long token = Binder.clearCallingIdentity();
4155 try {
4156 Phone phone = getPhone(subId);
4157 if (phone == null) return false;
4158 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004159 } catch (com.android.ims.ImsException e) {
4160 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4161 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 } finally {
4163 Binder.restoreCallingIdentity(token);
4164 }
4165 }
4166
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004167 /**
4168 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4169 * subscription.
4170 * @param subId The subscription to use to check the configuration.
4171 * @param callback The callback that will be used to send the result.
4172 * @param capability The MmTelFeature capability that will be used to send the result.
4173 * @param transportType The transport type of the MmTelFeature capability.
4174 */
4175 @Override
4176 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4177 int transportType) {
4178 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4179 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4180 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4181 "IMS not available on device.");
4182 }
4183 final long token = Binder.clearCallingIdentity();
4184 try {
4185 int slotId = getSlotIndex(subId);
4186 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4187 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4188 + subId + "'");
4189 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4190 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004191 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004192 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4193 transportType, aBoolean -> {
4194 try {
4195 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4196 } catch (RemoteException e) {
4197 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4198 + "running. Ignore");
4199 }
4200 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004201 } catch (ImsException e) {
4202 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004203 } finally {
4204 Binder.restoreCallingIdentity(token);
4205 }
4206 }
4207
shilu366312e2019-12-17 09:28:10 -08004208 /**
4209 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4210 * @param subId The subscription to use to check the configuration.
4211 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 @Override
4213 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004214 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004215 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004216
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 final long token = Binder.clearCallingIdentity();
4218 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004219 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004220 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004221 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004222 } catch (ImsException e) {
4223 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 } finally {
4225 Binder.restoreCallingIdentity(token);
4226 }
4227 }
4228
4229 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004230 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004232 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 final long identity = Binder.clearCallingIdentity();
4234 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004235 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004236 // This setting doesn't require an active ImsService connection, so do not verify. The
4237 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004238 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004239 } catch (ImsException e) {
4240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 } finally {
4242 Binder.restoreCallingIdentity(identity);
4243 }
4244 }
4245
shilu366312e2019-12-17 09:28:10 -08004246 /**
4247 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4248 * @param subId The subscription to use to check the configuration.
4249 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004250 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004251 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004252 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004253 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 final long identity = Binder.clearCallingIdentity();
4255 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004256 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004257 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004258 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004259 } catch (ImsException e) {
4260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
4264 }
4265
4266 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004267 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004269 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 final long identity = Binder.clearCallingIdentity();
4271 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004272 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004273 // This setting doesn't require an active ImsService connection, so do not verify. The
4274 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004276 } catch (ImsException e) {
4277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
4281 }
4282
shilu366312e2019-12-17 09:28:10 -08004283 /**
4284 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4285 * @param subId The subscription to use to check the configuration.
4286 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 @Override
4288 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004289 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004290 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 final long identity = Binder.clearCallingIdentity();
4292 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004293 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004294 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004295 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004296 } catch (ImsException e) {
4297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
4301 }
4302
4303 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004304 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004306 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 final long identity = Binder.clearCallingIdentity();
4308 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004309 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004310 // This setting doesn't require an active ImsService connection, so do not verify. The
4311 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004312 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004313 } catch (ImsException e) {
4314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
4318 }
4319
shilu366312e2019-12-17 09:28:10 -08004320 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004321 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4322 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4323 * @param subId The subscription to use to check the configuration.
4324 */
4325 @Override
4326 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004327 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004328 mApp, subId, "isCrossSimCallingEnabledByUser");
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004331 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004332 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004333 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004334 } catch (ImsException e) {
4335 throw new ServiceSpecificException(e.getCode());
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
4339 }
4340
4341 /**
4342 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4343 * Requires MODIFY_PHONE_STATE permission.
4344 * @param subId The subscription to use to check the configuration.
4345 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4346 * false otherwise
4347 */
4348 @Override
4349 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4351 "setCrossSimCallingEnabled");
4352 final long identity = Binder.clearCallingIdentity();
4353 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004354 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004355 // This setting doesn't require an active ImsService connection, so do not verify. The
4356 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004358 } catch (ImsException e) {
4359 throw new ServiceSpecificException(e.getCode());
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
4363 }
4364
4365 /**
shilu366312e2019-12-17 09:28:10 -08004366 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4367 * @param subId The subscription to use to check the configuration.
4368 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004370
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004372 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004373 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004377 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004378 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004379 } catch (ImsException e) {
4380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
4384 }
4385
4386 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004387 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004389 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 final long identity = Binder.clearCallingIdentity();
4391 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004392 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004393 // This setting doesn't require an active ImsService connection, so do not verify. The
4394 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004396 } catch (ImsException e) {
4397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402
4403 @Override
4404 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4406 "setVoWiFiNonPersistent");
4407 final long identity = Binder.clearCallingIdentity();
4408 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004410 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004412 } catch (ImsException e) {
4413 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
4417 }
4418
shilu366312e2019-12-17 09:28:10 -08004419 /**
4420 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4421 * @param subId The subscription to use to check the configuration.
4422 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004423 @Override
4424 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004425 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004426 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 final long identity = Binder.clearCallingIdentity();
4428 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004429 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004430 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004431 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004432 } catch (ImsException e) {
4433 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
4437 }
4438
4439 @Override
4440 public void setVoWiFiModeSetting(int subId, int mode) {
4441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4442 "setVoWiFiModeSetting");
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004446 // This setting doesn't require an active ImsService connection, so do not verify. The
4447 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004448 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004449 } catch (ImsException e) {
4450 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
4454 }
4455
4456 @Override
4457 public int getVoWiFiRoamingModeSetting(int subId) {
4458 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004462 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (ImsException e) {
4465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
4471 @Override
4472 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4474 "setVoWiFiRoamingModeSetting");
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004478 // This setting doesn't require an active ImsService connection, so do not verify. The
4479 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004481 } catch (ImsException e) {
4482 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
4486 }
4487
4488 @Override
4489 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4491 "setRttCapabilityEnabled");
4492 final long identity = Binder.clearCallingIdentity();
4493 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004494 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004495 // This setting doesn't require an active ImsService connection, so do not verify. The
4496 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004498 } catch (ImsException e) {
4499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
4503 }
4504
shilu366312e2019-12-17 09:28:10 -08004505 /**
4506 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4507 * @param subId The subscription to use to check the configuration.
4508 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004509 @Override
4510 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004511 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004512 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 final long identity = Binder.clearCallingIdentity();
4514 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004516 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004517 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004518 } catch (ImsException e) {
4519 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
4523 }
4524
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004525 @Override
4526 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4527 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4528 final long identity = Binder.clearCallingIdentity();
4529 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004530 if (!isImsAvailableOnDevice()) {
4531 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4532 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004533 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004534 int slotId = getSlotIndexOrException(subId);
4535 verifyImsMmTelConfiguredOrThrow(slotId);
4536 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004537 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004538 } catch (ImsException e) {
4539 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
4543 }
4544
4545 @Override
4546 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4547 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4548 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004549 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4550 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4551 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004552 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004553 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004554 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004555 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004556 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4557 + "is inactive, ignoring unregister.");
4558 // If the subscription is no longer active, just return, since the callback will already
4559 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
4563 }
4564
allenwtsu99c623b2020-01-03 18:24:23 +08004565
4566 private void checkModifyPhoneStatePermission(int subId, String message) {
4567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4568 message);
4569 }
4570
4571 private boolean isImsProvisioningRequired(int subId, int capability,
4572 boolean isMmtelCapability) {
4573 Phone phone = getPhone(subId);
4574 if (phone == null) {
4575 loge("phone instance null for subid " + subId);
4576 return false;
4577 }
4578 if (isMmtelCapability) {
4579 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4580 return false;
4581 }
4582 } else {
4583 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4584 return false;
4585 }
4586 }
4587 return true;
4588 }
4589
4590 @Override
4591 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4592 boolean isProvisioned) {
4593 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4594
4595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4598 if (!isImsProvisioningRequired(subId, capability, false)) {
4599 return;
4600 }
4601
4602 // this capability requires provisioning, route to the correct API.
4603 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4604 switch (capability) {
4605 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4606 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4607 ims.setEabProvisioned(isProvisioned);
4608 break;
4609 default: {
4610 throw new IllegalArgumentException("Tried to set provisioning for "
4611 + "rcs capability '" + capability + "', which does not require "
4612 + "provisioning.");
4613 }
4614 }
4615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
4618
4619 }
4620
4621
4622 @Override
4623 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4624 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4625 final long identity = Binder.clearCallingIdentity();
4626 try {
4627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4628 if (!isImsProvisioningRequired(subId, capability, false)) {
4629 return true;
4630 }
4631
4632 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4633 switch (capability) {
4634 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4635 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4636 return ims.isEabProvisionedOnDevice();
4637
4638 default: {
4639 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4640 + "capability '" + capability + "', which does not require "
4641 + "provisioning.");
4642 }
4643 }
4644
4645 } finally {
4646 Binder.restoreCallingIdentity(identity);
4647 }
4648 }
4649
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004650 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004651 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4652 boolean isProvisioned) {
4653 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004654 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4655 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4656 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4658 }
allenwtsu99c623b2020-01-03 18:24:23 +08004659 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660 final long identity = Binder.clearCallingIdentity();
4661 try {
4662 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004663 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004664 return;
4665 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004666 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4667 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4668 loge("setImsProvisioningStatusForCapability: called for technology that does "
4669 + "not support provisioning - " + tech);
4670 return;
4671 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004672
4673 // this capability requires provisioning, route to the correct API.
4674 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4675 switch (capability) {
4676 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4677 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4678 ims.setVolteProvisioned(isProvisioned);
4679 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4680 ims.setWfcProvisioned(isProvisioned);
4681 }
4682 break;
4683 }
4684 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4685 // There is currently no difference in VT provisioning type.
4686 ims.setVtProvisioned(isProvisioned);
4687 break;
4688 }
4689 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4690 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4691 // change the capability of the feature instead if needed.
4692 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4693 == isProvisioned) {
4694 // No change in provisioning.
4695 return;
4696 }
4697 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4698 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004699 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004700 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4702 + ", Exception" + e.getMessage());
4703 }
4704 break;
4705 }
4706 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004707 throw new IllegalArgumentException("Tried to set provisioning for "
4708 + "MmTel capability '" + capability + "', which does not require "
4709 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004710 }
4711 }
4712
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
4716 }
4717
4718 @Override
4719 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4720 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004721 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4722 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4723 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4725 }
4726 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004730 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004731 return true;
4732 }
4733
Brad Ebinger0d79c572021-04-17 15:20:49 -07004734 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4735 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4736 loge("getImsProvisioningStatusForCapability: called for technology that does "
4737 + "not support provisioning - " + tech);
4738 return true;
4739 }
4740
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004741 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4742 switch (capability) {
4743 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4744 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4745 return ims.isVolteProvisionedOnDevice();
4746 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4747 return ims.isWfcProvisionedOnDevice();
4748 }
4749 // This should never happen, since we are checking tech above to make sure it
4750 // is either LTE or IWLAN.
4751 throw new IllegalArgumentException("Invalid radio technology for voice "
4752 + "capability.");
4753 }
4754 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4755 // There is currently no difference in VT provisioning type.
4756 return ims.isVtProvisionedOnDevice();
4757 }
4758 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4759 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4760 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4761 }
4762 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004763 throw new IllegalArgumentException(
4764 "Tried to get provisioning for MmTel capability '" + capability
4765 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004766 }
4767 }
4768
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
4772 }
4773
4774 @Override
4775 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4776 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4777 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4778 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4779 }
4780 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4781 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4782 return (provisionedBits & capability) > 0;
4783 }
4784
4785 @Override
4786 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4787 boolean isProvisioned) {
4788 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4789 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4790 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4791 }
4792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4793 "setProvisioningStatusForCapability");
4794 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4795 // If the current provisioning status for capability already matches isProvisioned,
4796 // do nothing.
4797 if (((provisionedBits & capability) > 0) == isProvisioned) {
4798 return;
4799 }
4800 if (isProvisioned) {
4801 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4802 } else {
4803 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4804 }
4805 }
4806
4807 /**
4808 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4809 * technology. The bitfield should mirror the bitfield defined by
4810 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4811 */
4812 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4813 String key = getMmTelProvisioningKey(subId, tech);
4814 // Default is no capabilities are provisioned.
4815 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4816 }
4817
4818 /**
4819 * Sets the MmTel capability provisioning bitfield (defined by
4820 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4821 * technology specified.
4822 *
4823 * Note: This is a synchronous command and should not be called on UI thread.
4824 */
4825 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4826 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4827 String key = getMmTelProvisioningKey(subId, tech);
4828 editor.putInt(key, newField);
4829 editor.commit();
4830 }
4831
4832 private static String getMmTelProvisioningKey(int subId, int tech) {
4833 // resulting key is provision_ims_mmtel_{subId}_{tech}
4834 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4835 }
4836
4837 /**
4838 * Query CarrierConfig to see if the specified capability requires provisioning for the
4839 * carrier associated with the subscription id.
4840 */
4841 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4842 int capability) {
4843 CarrierConfigManager configManager = new CarrierConfigManager(context);
4844 PersistableBundle c = configManager.getConfigForSubId(subId);
4845 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004846 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004847 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4848 false);
4849 boolean requireVoiceVtProvisioning = c.getBoolean(
4850 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4851
4852 // First check to make sure that the capability requires provisioning.
4853 switch (capability) {
4854 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4855 // intentional fallthrough
4856 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4857 if (requireVoiceVtProvisioning) {
4858 // Voice and Video requires provisioning
4859 return true;
4860 }
4861 break;
4862 }
4863 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4864 if (requireUtProvisioning) {
4865 // UT requires provisioning
4866 return true;
4867 }
4868 break;
4869 }
4870 }
4871 return false;
4872 }
4873
allenwtsu99c623b2020-01-03 18:24:23 +08004874 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4875 int capability) {
4876 CarrierConfigManager configManager = new CarrierConfigManager(context);
4877 PersistableBundle c = configManager.getConfigForSubId(subId);
4878
4879 boolean requireRcsProvisioning = c.getBoolean(
4880 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4881
4882 // First check to make sure that the capability requires provisioning.
4883 switch (capability) {
4884 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4885 // intentional fallthrough
4886 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4887 if (requireRcsProvisioning) {
4888 // OPTION or PRESENCE requires provisioning
4889 return true;
4890 }
4891 break;
4892 }
4893 }
4894 return false;
4895 }
4896
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004898 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4900 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4901 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004902 enforceReadPrivilegedPermission("getImsProvisioningInt");
4903 final long identity = Binder.clearCallingIdentity();
4904 try {
4905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004906 int slotId = getSlotIndex(subId);
4907 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4908 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4909 + subId + "' for key:" + key);
4910 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4911 }
calvinpanb5a34062021-02-08 19:59:36 +08004912 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004913 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004914 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4915 + subId + "' for key:" + key);
4916 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
4920 }
4921
4922 @Override
4923 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4925 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4926 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004927 enforceReadPrivilegedPermission("getImsProvisioningString");
4928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 int slotId = getSlotIndex(subId);
4932 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4933 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4934 + subId + "' for key:" + key);
4935 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4936 }
calvinpanb5a34062021-02-08 19:59:36 +08004937 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004938 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4940 + subId + "' for key:" + key);
4941 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004942 } finally {
4943 Binder.restoreCallingIdentity(identity);
4944 }
4945 }
4946
4947 @Override
4948 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4950 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4951 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4953 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 int slotId = getSlotIndex(subId);
4958 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4959 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4960 + subId + "' for key:" + key);
4961 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4962 }
calvinpanb5a34062021-02-08 19:59:36 +08004963 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4964 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004966 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004968 } finally {
4969 Binder.restoreCallingIdentity(identity);
4970 }
4971 }
4972
4973 @Override
4974 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004975 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4976 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4977 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4979 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004980 final long identity = Binder.clearCallingIdentity();
4981 try {
4982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004983 int slotId = getSlotIndex(subId);
4984 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4985 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4986 + subId + "' for key:" + key);
4987 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4988 }
calvinpanb5a34062021-02-08 19:59:36 +08004989 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4990 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004991 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004992 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004993 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
4997 }
4998
Brad Ebinger919631e2021-06-02 17:46:35 -07004999 /**
5000 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5001 * for the given slot ID or no ImsResolver instance has been created.
5002 * @param slotId The slot ID that the IMS service is created for.
5003 * @throws ImsException If there is no ImsService configured for this slot.
5004 */
5005 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5006 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5007 ImsFeature.FEATURE_MMTEL)) {
5008 throw new ImsException("This subscription does not support MMTEL over IMS",
5009 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5010 }
5011 }
5012
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005013 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005014 int slotId = SubscriptionManager.getSlotIndex(subId);
5015 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005016 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5017 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005018 }
5019 return slotId;
5020 }
5021
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005022 private int getSlotIndex(int subId) {
5023 int slotId = SubscriptionManager.getSlotIndex(subId);
5024 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5025 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5026 }
5027 return slotId;
5028 }
5029
Wink Saville36469e72014-06-11 15:17:00 -07005030 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005031 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005032 */
5033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005034 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5035 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005036 try {
5037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5038 } catch (SecurityException se) {
5039 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5040 throw new SecurityException("Package " + callingPackage + " does not belong to "
5041 + Binder.getCallingUid());
5042 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005043 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005044 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005045 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005046 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005047 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005048 mApp, subId, callingPackage, callingFeatureId,
5049 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005050 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5051 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
5055 final Phone phone = getPhone(subId);
5056 if (phone != null) {
5057 return phone.getServiceState().getDataNetworkType();
5058 } else {
5059 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5060 }
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005064 }
5065
5066 /**
5067 * Returns the data network type
5068 */
5069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005070 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005071 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5072 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005073 }
5074
5075 /**
5076 * Returns the data network type for a subId
5077 */
5078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005079 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5080 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005082 mApp, subId, callingPackage, callingFeatureId,
5083 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005084 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5085 }
5086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 final Phone phone = getPhone(subId);
5090 if (phone != null) {
5091 return phone.getServiceState().getDataNetworkType();
5092 } else {
5093 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5094 }
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005098 }
5099
5100 /**
Wink Saville36469e72014-06-11 15:17:00 -07005101 * Returns the Voice network type for a subId
5102 */
5103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005104 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5105 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005107 mApp, subId, callingPackage, callingFeatureId,
5108 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005109 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5110 }
5111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 final long identity = Binder.clearCallingIdentity();
5113 try {
5114 final Phone phone = getPhone(subId);
5115 if (phone != null) {
5116 return phone.getServiceState().getVoiceNetworkType();
5117 } else {
5118 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5119 }
5120 } finally {
5121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005123 }
5124
5125 /**
5126 * @return true if a ICC card is present
5127 */
5128 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005129 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005130 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5131 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005132 }
5133
5134 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005135 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005136 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005137 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005138 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 final Phone phone = PhoneFactory.getPhone(slotIndex);
5142 if (phone != null) {
5143 return phone.getIccCard().hasIccCard();
5144 } else {
5145 return false;
5146 }
5147 } finally {
5148 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005150 }
5151
5152 /**
5153 * Return if the current radio is LTE on CDMA. This
5154 * is a tri-state return value as for a period of time
5155 * the mode may be unknown.
5156 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005157 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005158 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005159 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005160 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005162 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5163 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5164 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005165 }
5166
Sanket Padawe356d7632015-06-22 14:03:32 -07005167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005168 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5169 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005170 try {
5171 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5172 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005173 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5174 }
5175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 final long identity = Binder.clearCallingIdentity();
5177 try {
5178 final Phone phone = getPhone(subId);
5179 if (phone == null) {
5180 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5181 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005182 return TelephonyProperties.lte_on_cdma_device()
5183 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 }
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005187 }
Wink Saville36469e72014-06-11 15:17:00 -07005188 }
5189
Wink Saville36469e72014-06-11 15:17:00 -07005190 /**
5191 * {@hide}
5192 * Returns Default subId, 0 in the case of single standby.
5193 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005194 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005195 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005196 }
5197
Shishir Agrawala9f32182016-04-12 12:00:16 -07005198 private int getSlotForDefaultSubscription() {
5199 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5200 }
5201
Wink Savilleb564aae2014-10-23 10:18:09 -07005202 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005203 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005204 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005205
Pengquan Menge92a50d2018-09-21 15:54:48 -07005206 private boolean isActiveSubscription(int subId) {
5207 return mSubscriptionController.isActiveSubId(subId);
5208 }
5209
Ihab Awadf2177b72013-11-25 13:33:23 -08005210 /**
5211 * @see android.telephony.TelephonyManager.WifiCallingChoices
5212 */
5213 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 final long identity = Binder.clearCallingIdentity();
5215 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005216 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5218 getWhenToMakeWifiCallsDefaultPreference());
5219 } finally {
5220 Binder.restoreCallingIdentity(identity);
5221 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005222 }
5223
5224 /**
5225 * @see android.telephony.TelephonyManager.WifiCallingChoices
5226 */
5227 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005231 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005236 }
5237
Sailesh Nepald1e68152013-12-12 19:08:02 -08005238 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005239 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005240 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005241 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005242
Jordan Liu4c733742019-02-28 12:03:40 -08005243 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5244 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5245 if (phoneId == -1) {
5246 throw new IllegalArgumentException("Given slot index: " + slotIndex
5247 + " does not correspond to an active phone");
5248 }
5249 return PhoneFactory.getPhone(phoneId);
5250 }
5251
Shishir Agrawal566b7612013-10-28 14:41:00 -07005252 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005253 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5254 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5256 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005258 if (DBG) {
5259 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5260 }
5261 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5262 p2);
5263 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005264
Jordan Liu4c733742019-02-28 12:03:40 -08005265
5266 @Override
5267 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5268 int slotIndex, String callingPackage, String aid, int p2) {
5269 enforceModifyPermission();
5270 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5271 if (DBG) {
5272 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5273 }
5274 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5275 callingPackage, aid, p2);
5276 }
5277
5278 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5279 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 if (TextUtils.equals(ISDR_AID, aid)) {
5283 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005284 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5285 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 if (bestComponent == null
5287 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5288 loge("The calling package is not allowed to access ISD-R.");
5289 throw new SecurityException(
5290 "The calling package is not allowed to access ISD-R.");
5291 }
Derek Tan740e1672017-06-27 14:56:27 -07005292 }
Derek Tan740e1672017-06-27 14:56:27 -07005293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005295 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5296 null /* workSource */);
5297 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 return response;
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005302 }
5303
5304 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005305 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5307 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005308 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5309 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5310 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005311
Jordan Liu4c733742019-02-28 12:03:40 -08005312 @Override
5313 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5314 enforceModifyPermission();
5315 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5316 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5317 channel);
5318 }
5319
5320 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 final long identity = Binder.clearCallingIdentity();
5322 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 if (channel < 0) {
5324 return false;
5325 }
Jordan Liu4c733742019-02-28 12:03:40 -08005326 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5327 null /* workSource */);
5328 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 return success;
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005332 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005333 }
5334
5335 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005336 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5339 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005340 if (DBG) {
5341 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5342 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5343 + p3 + " data=" + data);
5344 }
5345 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5346 command, p1, p2, p3, data);
5347 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005348
Jordan Liu4c733742019-02-28 12:03:40 -08005349 @Override
5350 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5351 int command, int p1, int p2, int p3, String data) {
5352 enforceModifyPermission();
5353 if (DBG) {
5354 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5355 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5356 + p3 + " data=" + data);
5357 }
5358 return iccTransmitApduLogicalChannelWithPermission(
5359 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5360 data);
5361 }
5362
5363 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5364 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 final long identity = Binder.clearCallingIdentity();
5366 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005367 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 return "";
5369 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005372 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5373 null /* workSource */);
5374 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 // Append the returned status code to the end of the response payload.
5377 String s = Integer.toHexString(
5378 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5379 if (response.payload != null) {
5380 s = IccUtils.bytesToHexString(response.payload) + s;
5381 }
5382 return s;
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005385 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005386 }
Jake Hambye994d462014-02-03 13:10:13 -08005387
Evan Charltonc66da362014-05-16 14:06:40 -07005388 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005389 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5390 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5392 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005394 if (DBG) {
5395 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5396 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5397 }
5398 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5399 cla, command, p1, p2, p3, data);
5400 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005401
Jordan Liu4c733742019-02-28 12:03:40 -08005402 @Override
5403 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5404 int command, int p1, int p2, int p3, String data) {
5405 enforceModifyPermission();
5406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5407 if (DBG) {
5408 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5409 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5410 + " data=" + data);
5411 }
5412
5413 return iccTransmitApduBasicChannelWithPermission(
5414 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5415 p2, p3, data);
5416 }
5417
5418 // open APDU basic channel assuming the caller has sufficient permissions
5419 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5420 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 final long identity = Binder.clearCallingIdentity();
5422 try {
5423 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5424 && TextUtils.equals(ISDR_AID, data)) {
5425 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005426 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5427 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 if (bestComponent == null
5429 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5430 loge("The calling package is not allowed to select ISD-R.");
5431 throw new SecurityException(
5432 "The calling package is not allowed to select ISD-R.");
5433 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005434 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005437 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5438 null /* workSource */);
5439 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 // Append the returned status code to the end of the response payload.
5442 String s = Integer.toHexString(
5443 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5444 if (response.payload != null) {
5445 s = IccUtils.bytesToHexString(response.payload) + s;
5446 }
5447 return s;
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005450 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005451 }
5452
5453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005454 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005455 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5457 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 final long identity = Binder.clearCallingIdentity();
5460 try {
5461 if (DBG) {
5462 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5463 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5464 }
5465
5466 IccIoResult response =
5467 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5468 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5469 subId);
5470
5471 if (DBG) {
5472 log("Exchange SIM_IO [R]" + response);
5473 }
5474
5475 byte[] result = null;
5476 int length = 2;
5477 if (response.payload != null) {
5478 length = 2 + response.payload.length;
5479 result = new byte[length];
5480 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5481 } else {
5482 result = new byte[length];
5483 }
5484
5485 result[length - 1] = (byte) response.sw2;
5486 result[length - 2] = (byte) response.sw1;
5487 return result;
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005490 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005491 }
5492
Nathan Haroldb3014052017-01-25 15:57:32 -08005493 /**
5494 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5495 * on a particular subscription
5496 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005497 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5498 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005500 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005501 return null;
5502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503
5504 final long identity = Binder.clearCallingIdentity();
5505 try {
5506 if (appType != TelephonyManager.APPTYPE_USIM
5507 && appType != TelephonyManager.APPTYPE_SIM) {
5508 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5509 return null;
5510 }
5511 Object response = sendRequest(
5512 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5513 if (response instanceof String[]) {
5514 return (String[]) response;
5515 }
yincheng zhao2737e882019-09-06 17:06:54 -07005516 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005518 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 } finally {
5520 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005521 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005522 }
5523
yincheng zhao2737e882019-09-06 17:06:54 -07005524 /**
5525 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5526 * subscription.
5527 *
5528 * @param subId the id of the subscription.
5529 * @param appType the uicc app type, must be USIM or SIM.
5530 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5531 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005532 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005533 * @return number of fplmns that is successfully written to the SIM.
5534 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005535 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5536 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5538 mApp, subId, "setForbiddenPlmns");
5539
yincheng zhao2737e882019-09-06 17:06:54 -07005540 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5541 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5542 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5543 }
5544 if (fplmns == null) {
5545 throw new IllegalArgumentException("Fplmn List provided is null");
5546 }
5547 for (String fplmn : fplmns) {
5548 if (!CellIdentity.isValidPlmn(fplmn)) {
5549 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5550 }
5551 }
5552 final long identity = Binder.clearCallingIdentity();
5553 try {
5554 Object response = sendRequest(
5555 CMD_SET_FORBIDDEN_PLMNS,
5556 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5557 subId);
5558 return (int) response;
5559 } finally {
5560 Binder.restoreCallingIdentity(identity);
5561 }
5562 }
5563
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005564 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005565 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5567 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5572 if (response.payload == null) {
5573 return "";
5574 }
Evan Charltonc66da362014-05-16 14:06:40 -07005575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 // Append the returned status code to the end of the response payload.
5577 String s = Integer.toHexString(
5578 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5579 s = IccUtils.bytesToHexString(response.payload) + s;
5580 return s;
5581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
Evan Charltonc66da362014-05-16 14:06:40 -07005584 }
5585
Jake Hambye994d462014-02-03 13:10:13 -08005586 /**
5587 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5588 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5589 *
5590 * @param itemID the ID of the item to read
5591 * @return the NV item as a String, or null on error.
5592 */
5593 @Override
5594 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005595 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5597 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598
5599 final long identity = Binder.clearCallingIdentity();
5600 try {
5601 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005602 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5604 return value;
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Jake Hambye994d462014-02-03 13:10:13 -08005608 }
5609
5610 /**
5611 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5612 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5613 *
5614 * @param itemID the ID of the item to read
5615 * @param itemValue the value to write, as a String
5616 * @return true on success; false on any failure
5617 */
5618 @Override
5619 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005620 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5622 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623
5624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5627 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005628 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5630 return success;
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
Jake Hambye994d462014-02-03 13:10:13 -08005634 }
5635
5636 /**
5637 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5638 * Used for device configuration by some CDMA operators.
5639 *
5640 * @param preferredRoamingList byte array containing the new PRL
5641 * @return true on success; false on any failure
5642 */
5643 @Override
5644 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5646 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647
5648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5651 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5652 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5653 return success;
5654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
Jake Hambye994d462014-02-03 13:10:13 -08005657 }
5658
5659 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005660 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005661 * Used for device configuration by some CDMA operators.
5662 *
chen xu6dac5ab2018-10-26 17:39:23 -07005663 * @param slotIndex - device slot.
5664 *
Jake Hambye994d462014-02-03 13:10:13 -08005665 * @return true on success; false on any failure
5666 */
5667 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005668 public boolean resetModemConfig(int slotIndex) {
5669 Phone phone = PhoneFactory.getPhone(slotIndex);
5670 if (phone != null) {
5671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
chen xu6dac5ab2018-10-26 17:39:23 -07005674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5677 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5678 return success;
5679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 }
chen xu6dac5ab2018-10-26 17:39:23 -07005683 return false;
5684 }
5685
5686 /**
5687 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5688 *
5689 * @param slotIndex - device slot.
5690 *
5691 * @return true on success; false on any failure
5692 */
5693 @Override
5694 public boolean rebootModem(int slotIndex) {
5695 Phone phone = PhoneFactory.getPhone(slotIndex);
5696 if (phone != null) {
5697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5698 mApp, phone.getSubId(), "rebootModem");
5699
5700 final long identity = Binder.clearCallingIdentity();
5701 try {
5702 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5703 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5704 return success;
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
5708 }
5709 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005710 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005711
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005712 public String[] getPcscfAddress(String apnType, String callingPackage,
5713 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005714 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5716 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005717 return new String[0];
5718 }
5719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 final long identity = Binder.clearCallingIdentity();
5721 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005722 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Wink Saville36469e72014-06-11 15:17:00 -07005726 }
5727
Brad Ebinger51f743a2017-01-23 13:50:20 -08005728 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005729 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5730 * {@link #disableIms(int)}.
5731 * @param slotIndex device slot.
5732 */
5733 public void resetIms(int slotIndex) {
5734 enforceModifyPermission();
5735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 if (mImsResolver == null) {
5739 // may happen if the does not support IMS.
5740 return;
5741 }
5742 mImsResolver.disableIms(slotIndex);
5743 mImsResolver.enableIms(slotIndex);
5744 } finally {
5745 Binder.restoreCallingIdentity(identity);
5746 }
5747 }
5748
5749 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005750 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5751 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005752 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005753 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005758 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005759 // may happen if the device does not support IMS.
5760 return;
5761 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005762 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005766 }
5767
5768 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005769 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5770 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005771 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005772 public void disableIms(int slotId) {
5773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005777 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005778 // may happen if the device does not support IMS.
5779 return;
5780 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005785 }
5786
5787 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005788 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5789 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005790 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005791 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005792 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005793 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005797 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005798 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5799 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005800 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005801 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802 } finally {
5803 Binder.restoreCallingIdentity(identity);
5804 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005805 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005806 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005807 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5808 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005809 @Override
5810 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005811 enforceModifyPermission();
5812
5813 final long identity = Binder.clearCallingIdentity();
5814 try {
5815 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005816 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005817 } finally {
5818 Binder.restoreCallingIdentity(identity);
5819 }
5820 }
5821
5822 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005823 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005824 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005825 */
5826 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828
5829 final long identity = Binder.clearCallingIdentity();
5830 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005832 // may happen if the device does not support IMS.
5833 return null;
5834 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005839 }
5840
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005841 /**
5842 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005843 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005844 */
5845 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847
5848 final long identity = Binder.clearCallingIdentity();
5849 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005850 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005851 // may happen if the device does not support IMS.
5852 return null;
5853 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005854 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005858 }
5859
Brad Ebinger884c07b2018-02-15 16:17:40 -08005860 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005861 * Sets the ImsService Package Name that Telephony will bind to.
5862 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 * @param slotIndex the slot ID that the ImsService should bind for.
5864 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005865 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 * @param featureTypes An integer array of feature types associated with a packageName.
5867 * @param packageName The name of the package that the current configuration will be replaced
5868 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005869 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005870 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5872 int[] featureTypes, String packageName) {
5873 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5876 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 final long identity = Binder.clearCallingIdentity();
5880 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005882 // may happen if the device does not support IMS.
5883 return false;
5884 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 Map<Integer, String> featureConfig = new HashMap<>();
5886 for (int featureType : featureTypes) {
5887 featureConfig.put(featureType, packageName);
5888 }
5889 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5890 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005894 }
5895
5896 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005897 * Clears any carrier ImsService overrides for the slot index specified that were previously
5898 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5899 *
5900 * This should only be used for testing.
5901 *
5902 * @param slotIndex the slot ID that the ImsService should bind for.
5903 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5904 */
5905 @Override
5906 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5907 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5909 "clearCarrierImsServiceOverride");
5910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5911 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5912 "clearCarrierImsServiceOverride");
5913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 if (mImsResolver == null) {
5917 // may happen if the device does not support IMS.
5918 return false;
5919 }
5920 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
5924 }
5925
5926 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005928 *
5929 * @param slotId The slot that the ImsService is associated with.
5930 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5931 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005932 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005933 * @return the package name of the ImsService configuration.
5934 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5936 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005937 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005939 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005940 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5941 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 final long identity = Binder.clearCallingIdentity();
5944 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005945 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005946 // may happen if the device does not support IMS.
5947 return "";
5948 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005949 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005950 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5951 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 } finally {
5953 Binder.restoreCallingIdentity(identity);
5954 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005955 }
5956
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005957 /**
5958 * Get the MmTelFeature state associated with the requested subscription id.
5959 * @param subId The subscription that the MmTelFeature is associated with.
5960 * @param callback A callback with an integer containing the
5961 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5962 */
5963 @Override
5964 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5965 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5966 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5967 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5968 "IMS not available on device.");
5969 }
5970 final long token = Binder.clearCallingIdentity();
5971 try {
5972 int slotId = getSlotIndex(subId);
5973 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5974 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5975 + subId + "'");
5976 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5977 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005978 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005979 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5980 try {
5981 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5982 } catch (RemoteException e) {
5983 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5984 + "Ignore");
5985 }
5986 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005987 } catch (ImsException e) {
5988 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005989 } finally {
5990 Binder.restoreCallingIdentity(token);
5991 }
5992 }
5993
Daniel Brightbb5840b2021-01-12 15:48:18 -08005994 /**
5995 * Sets the ims registration state on all valid {@link Phone}s.
5996 */
5997 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005998 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999
6000 final long identity = Binder.clearCallingIdentity();
6001 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006002 // NOTE: Before S, this method only set the default phone.
6003 for (final Phone phone : PhoneFactory.getPhones()) {
6004 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6005 phone.setImsRegistrationState(registered);
6006 }
6007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 } finally {
6009 Binder.restoreCallingIdentity(identity);
6010 }
Wink Saville36469e72014-06-11 15:17:00 -07006011 }
6012
6013 /**
Stuart Scott54788802015-03-30 13:18:01 -07006014 * Set the network selection mode to automatic.
6015 *
6016 */
6017 @Override
6018 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6020 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021
6022 final long identity = Binder.clearCallingIdentity();
6023 try {
shilufc958392020-01-20 11:36:01 -08006024 if (!isActiveSubscription(subId)) {
6025 return;
6026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006028 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6029 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 } finally {
6031 Binder.restoreCallingIdentity(identity);
6032 }
Stuart Scott54788802015-03-30 13:18:01 -07006033 }
6034
Jack Yud10cdd42020-09-28 20:28:01 -07006035 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006036 * Ask the radio to connect to the input network and change selection mode to manual.
6037 *
6038 * @param subId the id of the subscription.
6039 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6040 * the operator to attach to.
6041 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6042 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6043 * normal network selection next time.
6044 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006045 */
6046 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006047 public boolean setNetworkSelectionModeManual(
6048 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6050 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006051
6052 if (!isActiveSubscription(subId)) {
6053 return false;
6054 }
6055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 final long identity = Binder.clearCallingIdentity();
6057 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006058 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006060 if (DBG) {
6061 log("setNetworkSelectionModeManual: subId: " + subId
6062 + " operator: " + operatorInfo);
6063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6065 } finally {
6066 Binder.restoreCallingIdentity(identity);
6067 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006068 }
shilu84f6e8b2019-12-19 13:58:01 -08006069 /**
6070 * Get the manual network selection
6071 *
6072 * @param subId the id of the subscription.
6073 *
6074 * @return the previously saved user selected PLMN
6075 */
6076 @Override
6077 public String getManualNetworkSelectionPlmn(int subId) {
6078 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006079 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006080 mApp, subId, "getManualNetworkSelectionPlmn");
6081
6082 final long identity = Binder.clearCallingIdentity();
6083 try {
6084 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006085 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006086 }
6087
6088 final Phone phone = getPhone(subId);
6089 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006090 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006091 }
6092 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6093 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6094 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
6098 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006099
6100 /**
6101 * Scans for available networks.
6102 */
6103 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006104 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6105 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6107 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006108 LocationAccessPolicy.LocationPermissionResult locationResult =
6109 LocationAccessPolicy.checkLocationPermission(mApp,
6110 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6111 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006112 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006113 .setCallingPid(Binder.getCallingPid())
6114 .setCallingUid(Binder.getCallingUid())
6115 .setMethod("getCellNetworkScanResults")
6116 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006117 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6118 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006119 .build());
6120 switch (locationResult) {
6121 case DENIED_HARD:
6122 throw new SecurityException("Not allowed to access scan results -- location");
6123 case DENIED_SOFT:
6124 return null;
6125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126
Pengquan Menga1bb6272018-09-06 09:59:22 -07006127 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 try {
6129 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006130 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 } finally {
6133 Binder.restoreCallingIdentity(identity);
6134 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006135 }
6136
6137 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006138 * Get the call forwarding info, given the call forwarding reason.
6139 */
6140 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006141 public void getCallForwarding(int subId, int callForwardingReason,
6142 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006143 enforceReadPrivilegedPermission("getCallForwarding");
6144 long identity = Binder.clearCallingIdentity();
6145 try {
6146 if (DBG) {
6147 log("getCallForwarding: subId " + subId
6148 + " callForwardingReason" + callForwardingReason);
6149 }
Hall Liu27d24262020-09-18 19:04:59 -07006150
6151 Phone phone = getPhone(subId);
6152 if (phone == null) {
6153 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006154 callback.onError(
6155 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006156 } catch (RemoteException e) {
6157 // ignore
6158 }
6159 return;
6160 }
6161
6162 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6163 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6164 @Override
6165 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6166 try {
6167 callback.onCallForwardingInfoAvailable(info);
6168 } catch (RemoteException e) {
6169 // ignore
6170 }
6171 }
6172
6173 @Override
6174 public void onError(int error) {
6175 try {
6176 callback.onError(error);
6177 } catch (RemoteException e) {
6178 // ignore
6179 }
6180 }
6181 });
6182 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006183 } finally {
6184 Binder.restoreCallingIdentity(identity);
6185 }
6186 }
6187
6188 /**
6189 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6190 * reason, the number to forward, and the timeout before the forwarding is attempted.
6191 */
6192 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006193 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6194 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006195 enforceModifyPermission();
6196 long identity = Binder.clearCallingIdentity();
6197 try {
6198 if (DBG) {
6199 log("setCallForwarding: subId " + subId
6200 + " callForwardingInfo" + callForwardingInfo);
6201 }
Hall Liu27d24262020-09-18 19:04:59 -07006202
6203 Phone phone = getPhone(subId);
6204 if (phone == null) {
6205 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006206 callback.accept(
6207 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006208 } catch (RemoteException e) {
6209 // ignore
6210 }
6211 return;
6212 }
6213
6214 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6215 FunctionalUtils.ignoreRemoteException(callback::accept));
6216
6217 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006218 } finally {
6219 Binder.restoreCallingIdentity(identity);
6220 }
6221 }
6222
6223 /**
Hall Liu27d24262020-09-18 19:04:59 -07006224 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006225 */
6226 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006227 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006228 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006229 long identity = Binder.clearCallingIdentity();
6230 try {
Hall Liu27d24262020-09-18 19:04:59 -07006231 Phone phone = getPhone(subId);
6232 if (phone == null) {
6233 try {
6234 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6235 } catch (RemoteException e) {
6236 // ignore
6237 }
6238 return;
6239 }
SongFerngWang0e767992021-03-31 22:08:45 +08006240 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6241 PersistableBundle c = configManager.getConfigForSubId(subId);
6242 boolean requireUssd = c.getBoolean(
6243 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006244
Shuo Qian4a594052020-01-23 11:59:30 -08006245 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006246 if (requireUssd) {
6247 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6248 getSubscriptionCarrierId(subId));
6249 String newUssdCommand = "";
6250 try {
6251 newUssdCommand = carrierXmlParser.getFeature(
6252 CarrierXmlParser.FEATURE_CALL_WAITING)
6253 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6254 } catch (NullPointerException e) {
6255 loge("Failed to generate USSD number" + e);
6256 }
6257 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6258 mMainThreadHandler, callback, carrierXmlParser,
6259 CarrierXmlParser.SsEntry.SSAction.QUERY);
6260 final String ussdCommand = newUssdCommand;
6261 Executors.newSingleThreadExecutor().execute(() -> {
6262 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6263 });
6264 } else {
6265 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6266 callback::accept);
6267 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6268 }
Shuo Qian4a594052020-01-23 11:59:30 -08006269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
6272 }
6273
6274 /**
Hall Liu27d24262020-09-18 19:04:59 -07006275 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006276 */
6277 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006278 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006279 enforceModifyPermission();
6280 long identity = Binder.clearCallingIdentity();
6281 try {
Hall Liu27d24262020-09-18 19:04:59 -07006282 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6283
6284 Phone phone = getPhone(subId);
6285 if (phone == null) {
6286 try {
6287 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6288 } catch (RemoteException e) {
6289 // ignore
6290 }
6291 return;
6292 }
6293
SongFerngWang0e767992021-03-31 22:08:45 +08006294 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6295 PersistableBundle c = configManager.getConfigForSubId(subId);
6296 boolean requireUssd = c.getBoolean(
6297 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006298
SongFerngWang0e767992021-03-31 22:08:45 +08006299 if (DBG) log("getCallWaitingStatus: subId " + subId);
6300 if (requireUssd) {
6301 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6302 getSubscriptionCarrierId(subId));
6303 CarrierXmlParser.SsEntry.SSAction ssAction =
6304 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6305 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6306 String newUssdCommand = "";
6307 try {
6308 newUssdCommand = carrierXmlParser.getFeature(
6309 CarrierXmlParser.FEATURE_CALL_WAITING)
6310 .makeCommand(ssAction, null);
6311 } catch (NullPointerException e) {
6312 loge("Failed to generate USSD number" + e);
6313 }
6314 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6315 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6316 final String ussdCommand = newUssdCommand;
6317 Executors.newSingleThreadExecutor().execute(() -> {
6318 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6319 });
6320 } else {
6321 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6322 FunctionalUtils.ignoreRemoteException(callback::accept));
6323
6324 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6325 }
Shuo Qian4a594052020-01-23 11:59:30 -08006326 } finally {
6327 Binder.restoreCallingIdentity(identity);
6328 }
6329 }
6330
6331 /**
yinxub1bed742017-04-17 11:45:04 -07006332 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006333 *
yinxub1bed742017-04-17 11:45:04 -07006334 * @param subId id of the subscription
6335 * @param request contains the radio access networks with bands/channels to scan
6336 * @param messenger callback messenger for scan results or errors
6337 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006338 * @return the id of the requested scan which can be used to stop the scan.
6339 */
6340 @Override
6341 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006342 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6344 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006345 LocationAccessPolicy.LocationPermissionResult locationResult =
6346 LocationAccessPolicy.checkLocationPermission(mApp,
6347 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6348 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006349 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006350 .setCallingPid(Binder.getCallingPid())
6351 .setCallingUid(Binder.getCallingUid())
6352 .setMethod("requestNetworkScan")
6353 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006354 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6355 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006356 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006357 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006358 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6359 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006360 if (e != null) {
6361 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6362 throw e;
6363 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006364 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006365 return TelephonyScanManager.INVALID_SCAN_ID;
6366 }
6367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 }
Hall Liu912dfd32019-04-25 14:02:26 -07006369 int callingUid = Binder.getCallingUid();
6370 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006371 final long identity = Binder.clearCallingIdentity();
6372 try {
6373 return mNetworkScanRequestTracker.startNetworkScan(
6374 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006375 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
yinxu504e1392017-04-12 16:03:22 -07006379 }
6380
Hall Liub2ac8ef2019-02-28 15:56:23 -08006381 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006382 NetworkScanRequest request, int subId, String callingPackage) {
6383 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006384 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6385 boolean hasNetworkScanPermission =
6386 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6387 == PERMISSION_GRANTED;
6388
6389 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6390 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6391 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006392 }
6393
6394 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6395 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006396 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6397 return new SecurityException("Specific channels must not be"
6398 + " scanned without location access.");
6399 }
6400 }
6401 }
6402
Hall Liub2ac8ef2019-02-28 15:56:23 -08006403 return null;
6404 }
6405
yinxu504e1392017-04-12 16:03:22 -07006406 /**
6407 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006408 *
6409 * @param subId id of the subscription
6410 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006411 */
6412 @Override
6413 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6415 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416
Hall Liu912dfd32019-04-25 14:02:26 -07006417 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418 final long identity = Binder.clearCallingIdentity();
6419 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006420 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
yinxu504e1392017-04-12 16:03:22 -07006424 }
6425
6426 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006427 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006428 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006429 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006430 */
6431 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006432 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006433 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006434 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006435 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436
6437 final long identity = Binder.clearCallingIdentity();
6438 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006439 if (DBG) log("getAllowedNetworkTypesBitmask");
6440 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6441 int networkTypesBitmask = (result != null ? result[0] : -1);
6442 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6443 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 } finally {
6445 Binder.restoreCallingIdentity(identity);
6446 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006447 }
6448
6449 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006450 * Get the allowed network types for certain reason.
6451 *
6452 * @param subId the id of the subscription.
6453 * @param reason the reason the allowed network type change is taking place
6454 * @return the allowed network types.
6455 */
6456 @Override
6457 public long getAllowedNetworkTypesForReason(int subId,
6458 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006459 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006460 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006461 final long identity = Binder.clearCallingIdentity();
6462 try {
6463 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6464 } finally {
6465 Binder.restoreCallingIdentity(identity);
6466 }
6467 }
6468
6469 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006470 * Enable/Disable E-UTRA-NR Dual Connectivity
6471 * @param subId subscription id of the sim card
6472 * @param nrDualConnectivityState expected NR dual connectivity state
6473 * This can be passed following states
6474 * <ol>
6475 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6476 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6477 * <li>Disable NR dual connectivity and force secondary cell to be released
6478 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6479 * </ol>
6480 * @return operation result.
6481 */
6482 @Override
6483 public int setNrDualConnectivityState(int subId,
6484 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6486 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006487 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006488 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6489 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6490 }
6491
Sooraj Sasindran37444802020-08-11 10:40:43 -07006492 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6496 nrDualConnectivityState, subId,
6497 workSource);
6498 if (DBG) log("enableNRDualConnectivity result: " + result);
6499 return result;
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
6503 }
6504
6505 /**
6506 * Is E-UTRA-NR Dual Connectivity enabled
6507 * @return true if dual connectivity is enabled else false
6508 */
6509 @Override
6510 public boolean isNrDualConnectivityEnabled(int subId) {
6511 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006512 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006513 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006514 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006515 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6516 return false;
6517 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6519 final long identity = Binder.clearCallingIdentity();
6520 try {
6521 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6522 null, subId, workSource);
6523 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6524 return isEnabled;
6525 } finally {
6526 Binder.restoreCallingIdentity(identity);
6527 }
6528 }
6529
6530 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006531 * Set the allowed network types of the device and
6532 * provide the reason triggering the allowed network change.
6533 *
6534 * @param subId the id of the subscription.
6535 * @param reason the reason the allowed network type change is taking place
6536 * @param allowedNetworkTypes the allowed network types.
6537 * @return true on success; false on any failure.
6538 */
6539 @Override
6540 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 @TelephonyManager.AllowedNetworkTypesReason int reason,
6542 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6544 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006546 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6547 return false;
6548 }
6549 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6550 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006551 return false;
6552 }
6553
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006554 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6555 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6556
6557
6558 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6559 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6560 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006561 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006562
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006563 final long identity = Binder.clearCallingIdentity();
6564 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006565 Boolean success = (Boolean) sendRequest(
6566 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6567 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6568
6569 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6570 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
6574 }
6575
6576 /**
Miaoa84611c2019-03-15 09:21:10 +08006577 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006578 *
Miaoa84611c2019-03-15 09:21:10 +08006579 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006580 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006581 * @hide
6582 */
6583 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006584 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006587 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 try {
Miaoa84611c2019-03-15 09:21:10 +08006589 if (phone != null) {
6590 return phone.hasMatchedTetherApnSetting();
6591 } else {
6592 return false;
6593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 } finally {
6595 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006596 }
Junda Liu475951f2014-11-07 16:45:03 -08006597 }
6598
6599 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006600 * Get the user enabled state of Mobile Data.
6601 *
6602 * TODO: remove and use isUserDataEnabled.
6603 * This can't be removed now because some vendor codes
6604 * calls through ITelephony directly while they should
6605 * use TelephonyManager.
6606 *
6607 * @return true on enabled
6608 */
6609 @Override
6610 public boolean getDataEnabled(int subId) {
6611 return isUserDataEnabled(subId);
6612 }
6613
6614 /**
6615 * Get whether mobile data is enabled per user setting.
6616 *
6617 * There are other factors deciding whether mobile data is actually enabled, but they are
6618 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006619 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006620 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006621 *
6622 * @return {@code true} if data is enabled else {@code false}
6623 */
6624 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006625 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006626 try {
6627 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6628 null);
6629 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6631 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 int phoneId = mSubscriptionController.getPhoneId(subId);
6637 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6638 Phone phone = PhoneFactory.getPhone(phoneId);
6639 if (phone != null) {
6640 boolean retVal = phone.isUserDataEnabled();
6641 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6642 return retVal;
6643 } else {
6644 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6645 return false;
6646 }
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006649 }
6650 }
6651
6652 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006653 * Checks if the device is capable of mobile data by considering whether whether the
6654 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6655 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006656 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006657 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006658 */
6659 @Override
6660 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006661 try {
6662 try {
6663 mApp.enforceCallingOrSelfPermission(
6664 android.Manifest.permission.ACCESS_NETWORK_STATE,
6665 null);
6666 } catch (Exception e) {
6667 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6668 "isDataEnabled");
6669 }
6670 } catch (Exception e) {
6671 enforceReadPrivilegedPermission("isDataEnabled");
6672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673
6674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 int phoneId = mSubscriptionController.getPhoneId(subId);
6677 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6678 Phone phone = PhoneFactory.getPhone(phoneId);
6679 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006680 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6682 return retVal;
6683 } else {
6684 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6685 return false;
6686 }
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006689 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006690 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006691
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006692 /**
6693 * Check if data is enabled for a specific reason
6694 * @param subId Subscription index
6695 * @param reason the reason the data enable change is taking place
6696 * @return {@code true} if the overall data is enabled; {@code false} if not.
6697 */
6698 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006699 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006700 @TelephonyManager.DataEnabledReason int reason) {
6701 try {
6702 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6703 null);
6704 } catch (Exception e) {
6705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006706 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006707 }
6708
6709
6710 final long identity = Binder.clearCallingIdentity();
6711 try {
6712 int phoneId = mSubscriptionController.getPhoneId(subId);
6713 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006714 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 + " reason=" + reason);
6716 }
6717 Phone phone = PhoneFactory.getPhone(phoneId);
6718 if (phone != null) {
6719 boolean retVal;
6720 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6721 retVal = phone.isUserDataEnabled();
6722 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006723 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006724 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006725 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006726 return retVal;
6727 } else {
6728 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006729 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 + subId + " retVal=false");
6731 }
6732 return false;
6733 }
6734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
6737 }
6738
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006739 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006740 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006741 if (uid == Process.PHONE_UID) {
6742 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6743 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006744 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6745 }
6746
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006747 //load access rules from carrier configs, and check those as well: b/139133814
6748 SubscriptionController subController = SubscriptionController.getInstance();
6749 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6750 || subController == null) return privilegeFromSim;
6751
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006752 PackageManager pkgMgr = phone.getContext().getPackageManager();
6753 String[] packages = pkgMgr.getPackagesForUid(uid);
6754
6755 final long identity = Binder.clearCallingIdentity();
6756 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006757 int subId = phone.getSubId();
6758 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6759 // A test override is in place for the privileges for this subId, so don't try to
6760 // read the subscription privileges.
6761 return privilegeFromSim;
6762 }
6763 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006764 SubscriptionManager subManager = (SubscriptionManager)
6765 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6766 for (String pkg : packages) {
6767 if (subManager.canManageSubscription(subInfo, pkg)) {
6768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6769 }
6770 }
6771 return privilegeFromSim;
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
6775 }
6776
6777 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6778 String pkgName) {
6779 //load access rules from carrier configs, and check those as well: b/139133814
6780 SubscriptionController subController = SubscriptionController.getInstance();
6781 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6782 || subController == null) return privilegeFromSim;
6783
6784 final long identity = Binder.clearCallingIdentity();
6785 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006786 int subId = phone.getSubId();
6787 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6788 // A test override is in place for the privileges for this subId, so don't try to
6789 // read the subscription privileges.
6790 return privilegeFromSim;
6791 }
6792 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006793 SubscriptionManager subManager = (SubscriptionManager)
6794 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6795 return subManager.canManageSubscription(subInfo, pkgName)
6796 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
6800 }
6801
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006802 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006803 public int getCarrierPrivilegeStatus(int subId) {
6804 final Phone phone = getPhone(subId);
6805 if (phone == null) {
6806 loge("getCarrierPrivilegeStatus: Invalid subId");
6807 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6808 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006809 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6810 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006811 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006812 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6813 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006814
6815 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006816 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006817 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006818 }
Junda Liu29340342014-07-10 15:23:27 -07006819
6820 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006821 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006822 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006823 final Phone phone = getPhone(subId);
6824 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006825 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006826 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6827 }
6828 UiccProfile profile =
6829 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6830 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006831 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006832 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6833 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006834 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006835 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006836 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006837 }
6838
6839 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006840 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006841 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006842 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006844 }
6845
6846 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006847 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6848 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006849 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6851 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006852 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006853 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006854 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006855 }
6856
6857 @Override
6858 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006859 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006860 if (TextUtils.isEmpty(pkgName))
6861 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006862 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6863 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006864 UiccPort port = UiccController.getInstance().getUiccPort(i);
6865 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006866 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006867 continue;
6868 }
6869
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006870 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006871 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006872 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006873 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6874 break;
6875 }
6876 }
6877
6878 return result;
Junda Liu29340342014-07-10 15:23:27 -07006879 }
Derek Tan89e89d42014-07-08 17:00:10 -07006880
6881 @Override
Junda Liue64de782015-04-16 17:19:16 -07006882 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006883 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006884 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6885 loge("phoneId " + phoneId + " is not valid.");
6886 return null;
6887 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006888 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6889 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006890 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006891 return null ;
6892 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006893 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006894 }
6895
Amith Yamasani6e118872016-02-19 12:53:51 -08006896 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006897 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006898 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006899 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006900 List<String> privilegedPackages = new ArrayList<>();
6901 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006902 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006903 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006904 if (port != null) {
6905 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006906 if (packages == null) {
6907 // Only check packages in user 0 for now
6908 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006909 PackageManager.MATCH_DISABLED_COMPONENTS
6910 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006911 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006912 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006913 }
6914 for (int p = packages.size() - 1; p >= 0; p--) {
6915 PackageInfo pkgInfo = packages.get(p);
6916 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006917 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6918 port.getCarrierPrivilegeStatus(pkgInfo),
6919 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006920 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006921 privilegedPackages.add(pkgInfo.packageName);
6922 }
6923 }
6924 }
6925 }
6926 return privilegedPackages;
6927 }
6928
chen xuf7e9fe82019-05-09 19:31:02 -07006929 @Override
6930 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006931 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6932
6933 final long identity = Binder.clearCallingIdentity();
6934
chen xuf7e9fe82019-05-09 19:31:02 -07006935 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006936 try {
6937 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6938 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6939 }
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006942 }
6943 return privilegedPackages;
6944 }
6945
Wink Savilleb564aae2014-10-23 10:18:09 -07006946 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006947 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006948 UiccPort port = phone == null ? null : phone.getUiccPort();
6949 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006950 return null;
6951 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006952 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006953 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006954 return null;
6955 }
6956 return iccId;
6957 }
6958
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006959 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006960 public void setCallComposerStatus(int subId, int status) {
6961 enforceModifyPermission();
6962
6963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 Phone phone = getPhone(subId);
6966 if (phone != null) {
6967 Phone defaultPhone = phone.getImsPhone();
6968 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6969 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6970 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006971 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6972 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006973 }
6974 }
Shuo Qian284ae752020-12-22 19:10:14 -08006975 } catch (ImsException e) {
6976 throw new ServiceSpecificException(e.getCode());
6977 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006978 Binder.restoreCallingIdentity(identity);
6979 }
6980 }
6981
6982 @Override
6983 public int getCallComposerStatus(int subId) {
6984 enforceReadPrivilegedPermission("getCallComposerStatus");
6985
6986 final long identity = Binder.clearCallingIdentity();
6987 try {
6988 Phone phone = getPhone(subId);
6989 if (phone != null) {
6990 Phone defaultPhone = phone.getImsPhone();
6991 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6992 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6993 return imsPhone.getCallComposerStatus();
6994 }
6995 }
6996 } finally {
6997 Binder.restoreCallingIdentity(identity);
6998 }
6999 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7000 }
7001
7002 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007003 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7004 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007005 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007006 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 final String iccId = getIccId(subId);
7011 final Phone phone = getPhone(subId);
7012 if (phone == null) {
7013 return false;
7014 }
7015 final String subscriberId = phone.getSubscriberId();
7016
7017 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007018 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 + subscriberId + " to " + number);
7020 }
7021
7022 if (TextUtils.isEmpty(iccId)) {
7023 return false;
7024 }
7025
7026 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7027
7028 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7029 if (alphaTag == null) {
7030 editor.remove(alphaTagPrefKey);
7031 } else {
7032 editor.putString(alphaTagPrefKey, alphaTag);
7033 }
7034
7035 // Record both the line number and IMSI for this ICCID, since we need to
7036 // track all merged IMSIs based on line number
7037 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7038 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7039 if (number == null) {
7040 editor.remove(numberPrefKey);
7041 editor.remove(subscriberPrefKey);
7042 } else {
7043 editor.putString(numberPrefKey, number);
7044 editor.putString(subscriberPrefKey, subscriberId);
7045 }
7046
7047 editor.commit();
7048 return true;
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007051 }
Derek Tan7226c842014-07-02 17:42:23 -07007052 }
7053
7054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007055 public String getLine1NumberForDisplay(int subId, String callingPackage,
7056 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007057 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007059 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007060 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007061 return null;
7062 }
Derek Tan97ebb422014-09-05 16:55:38 -07007063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 final long identity = Binder.clearCallingIdentity();
7065 try {
7066 String iccId = getIccId(subId);
7067 if (iccId != null) {
7068 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7069 if (DBG_MERGE) {
7070 log("getLine1NumberForDisplay returning "
7071 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7072 }
7073 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7076 return null;
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007079 }
Derek Tan7226c842014-07-02 17:42:23 -07007080 }
7081
7082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007083 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7084 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007086 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007087 return null;
7088 }
Derek Tan97ebb422014-09-05 16:55:38 -07007089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 final long identity = Binder.clearCallingIdentity();
7091 try {
7092 String iccId = getIccId(subId);
7093 if (iccId != null) {
7094 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7095 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7096 }
7097 return null;
7098 } finally {
7099 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007100 }
Derek Tan7226c842014-07-02 17:42:23 -07007101 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007102
7103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007104 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7105 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007106 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7107 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007109 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007110 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007111 return null;
7112 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007113
Jordan Liub49b04b2019-05-06 14:45:15 -07007114 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7115 // the process, where TelephonyManager was instantiated.
7116 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007117 final long identity = Binder.clearCallingIdentity();
7118 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007119 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 final TelephonyManager tele = TelephonyManager.from(context);
7121 final SubscriptionManager sub = SubscriptionManager.from(context);
7122
7123 // Figure out what subscribers are currently active
7124 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125
Jordan Liub49b04b2019-05-06 14:45:15 -07007126 // Only consider subs which match the current subId
7127 // This logic can be simplified. See b/131189269 for progress.
7128 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007129 activeSubscriberIds.add(tele.getSubscriberId(subId));
7130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131
7132 // First pass, find a number override for an active subscriber
7133 String mergeNumber = null;
7134 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7135 for (String key : prefs.keySet()) {
7136 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7137 final String subscriberId = (String) prefs.get(key);
7138 if (activeSubscriberIds.contains(subscriberId)) {
7139 final String iccId = key.substring(
7140 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7141 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7142 mergeNumber = (String) prefs.get(numberKey);
7143 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007144 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 + " for active subscriber " + subscriberId);
7146 }
7147 if (!TextUtils.isEmpty(mergeNumber)) {
7148 break;
7149 }
7150 }
7151 }
7152 }
7153
7154 // Shortcut when no active merged subscribers
7155 if (TextUtils.isEmpty(mergeNumber)) {
7156 return null;
7157 }
7158
7159 // Second pass, find all subscribers under that line override
7160 final ArraySet<String> result = new ArraySet<>();
7161 for (String key : prefs.keySet()) {
7162 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7163 final String number = (String) prefs.get(key);
7164 if (mergeNumber.equals(number)) {
7165 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7166 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7167 final String subscriberId = (String) prefs.get(subscriberKey);
7168 if (!TextUtils.isEmpty(subscriberId)) {
7169 result.add(subscriberId);
7170 }
7171 }
7172 }
7173 }
7174
7175 final String[] resultArray = result.toArray(new String[result.size()]);
7176 Arrays.sort(resultArray);
7177 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007178 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7180 }
7181 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007182 } finally {
7183 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007184 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007185 }
7186
7187 @Override
zoey chen38003472019-12-13 17:16:31 +08007188 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7189 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007190
7191 final long identity = Binder.clearCallingIdentity();
7192 try {
7193 final TelephonyManager telephonyManager = mApp.getSystemService(
7194 TelephonyManager.class);
7195 String subscriberId = telephonyManager.getSubscriberId(subId);
7196 if (subscriberId == null) {
7197 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007198 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007199 + subId);
7200 }
7201 return null;
7202 }
7203
7204 final SubscriptionInfo info = SubscriptionController.getInstance()
7205 .getSubscriptionInfo(subId);
7206 final ParcelUuid groupUuid = info.getGroupUuid();
7207 // If it doesn't belong to any group, return just subscriberId of itself.
7208 if (groupUuid == null) {
7209 return new String[]{subscriberId};
7210 }
7211
7212 // Get all subscriberIds from the group.
7213 final List<String> mergedSubscriberIds = new ArrayList<>();
7214 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007215 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007216 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007217 for (SubscriptionInfo subInfo : groupInfos) {
7218 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7219 if (subscriberId != null) {
7220 mergedSubscriberIds.add(subscriberId);
7221 }
7222 }
7223
7224 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227
7228 }
7229 }
7230
7231 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007232 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007233 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007234 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235
7236 final long identity = Binder.clearCallingIdentity();
7237 try {
7238 final Phone phone = getPhone(subId);
7239 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007243 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007244
7245 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007246 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007247 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7248 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007249 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7250 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251
7252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 final Phone phone = getPhone(subId);
7255 if (phone == null) {
7256 return false;
7257 }
7258 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7259 cdmaNonRoamingList);
7260 } finally {
7261 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007262 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007263 }
7264
7265 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007266 @Deprecated
7267 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7268 enforceModifyPermission();
7269
7270 int returnValue = 0;
7271 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007272 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007273 if(result.exception == null) {
7274 if (result.result != null) {
7275 byte[] responseData = (byte[])(result.result);
7276 if(responseData.length > oemResp.length) {
7277 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7278 responseData.length + "bytes. Buffer Size is " +
7279 oemResp.length + "bytes.");
7280 }
7281 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7282 returnValue = responseData.length;
7283 }
7284 } else {
7285 CommandException ex = (CommandException) result.exception;
7286 returnValue = ex.getCommandError().ordinal();
7287 if(returnValue > 0) returnValue *= -1;
7288 }
7289 } catch (RuntimeException e) {
7290 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7291 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7292 if(returnValue > 0) returnValue *= -1;
7293 }
7294
7295 return returnValue;
7296 }
7297
7298 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007299 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007300 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007301 try {
7302 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007303 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007304 mApp, phone.getSubId(), "getRadioAccessFamily");
7305 } catch (SecurityException e) {
7306 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7307 throw e;
7308 }
chen xub97461a2018-10-26 14:17:57 -07007309 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007310 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007311 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 final long identity = Binder.clearCallingIdentity();
7314 try {
chen xub97461a2018-10-26 14:17:57 -07007315 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007316 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007317 mApp, phone.getSubId(), "getRadioAccessFamily");
7318 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 } finally {
7320 Binder.restoreCallingIdentity(identity);
7321 }
chen xub97461a2018-10-26 14:17:57 -07007322 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007323 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007324
7325 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007326 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007327 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007328 try {
7329 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7330 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007331 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007332 }
7333 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007334 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007335 }
7336 RoleManager rm = mApp.getSystemService(RoleManager.class);
7337 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7338 if (!dialerRoleHolders.contains(callingPackage)) {
7339 throw new SecurityException("App must be the dialer role holder to"
7340 + " upload a call composer pic");
7341 }
7342
7343 Executors.newSingleThreadExecutor().execute(() -> {
7344 ByteArrayOutputStream output = new ByteArrayOutputStream(
7345 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7346 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7347 boolean readUntilEnd = false;
7348 int totalBytesRead = 0;
7349 byte[] buffer = new byte[16 * 1024];
7350 while (true) {
7351 int numRead;
7352 try {
7353 numRead = input.read(buffer);
7354 } catch (IOException e) {
7355 try {
7356 fd.checkError();
7357 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7358 null);
7359 } catch (IOException e1) {
7360 // This means that the other side closed explicitly with an error. If this
7361 // happens, log and ignore.
7362 loge("Remote end of call composer picture pipe closed: " + e1);
7363 }
7364 break;
7365 }
7366 if (numRead == -1) {
7367 readUntilEnd = true;
7368 break;
7369 }
7370 totalBytesRead += numRead;
7371 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7372 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7373 try {
7374 input.close();
7375 } catch (IOException e) {
7376 // ignore
7377 }
7378 break;
7379 }
7380 output.write(buffer, 0, numRead);
7381 }
7382 // Generally, the remote end will close the file descriptors. The only case where we
7383 // close is above, where the picture size is too big.
7384
7385 try {
7386 fd.checkError();
7387 } catch (IOException e) {
7388 loge("Remote end for call composer closed with an error: " + e);
7389 return;
7390 }
7391
Hall Liuaa4211e2021-01-20 15:43:39 -08007392 if (!readUntilEnd) {
7393 loge("Did not finish reading entire image; aborting");
7394 return;
7395 }
Hall Liu82694d52020-12-11 18:22:04 -08007396
Hall Liuaa4211e2021-01-20 15:43:39 -08007397 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7398 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7399 new CallComposerPictureTransfer.Factory() {},
7400 imageData,
7401 (result) -> {
7402 if (result.first != null) {
7403 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7404 Bundle outputResult = new Bundle();
7405 outputResult.putParcelable(
7406 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7407 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7408 outputResult);
7409 } else {
7410 callback.send(result.second, null);
7411 }
7412 }
7413 );
Hall Liu82694d52020-12-11 18:22:04 -08007414 });
7415 }
7416
7417 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007418 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007419 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007424 ImsManager.getInstance(defaultPhone.getContext(),
7425 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 } finally {
7427 Binder.restoreCallingIdentity(identity);
7428 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007429 }
7430
7431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007432 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007433 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7435 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007436 return false;
7437 }
Svet Ganovb320e182015-04-16 12:30:10 -07007438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 final long identity = Binder.clearCallingIdentity();
7440 try {
7441 // Check the user preference and the system-level IMS setting. Even if the user has
7442 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7443 // In the long run, we may instead need to check if there exists a connection service
7444 // which can support video calling.
7445 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007446 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 return imsManager.isVtEnabledByPlatform()
7448 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7449 && imsManager.isVtEnabledByUser();
7450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007453 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007454
Andrew Leea1239f22015-03-02 17:44:07 -08007455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007456 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7457 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007459 mApp, subId, callingPackage, callingFeatureId,
7460 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 return false;
7462 }
7463
7464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 CarrierConfigManager configManager =
7467 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007468 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
Andrew Leea1239f22015-03-02 17:44:07 -08007473 }
7474
7475 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007476 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 return false;
7480 }
7481
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 CarrierConfigManager configManager =
7485 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Andrew Leea1239f22015-03-02 17:44:07 -08007491 }
7492
Andrew Lee9431b832015-03-09 18:46:45 -07007493 @Override
7494 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007495 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007496 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007497 }
7498
7499 @Override
7500 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 final long identity = Binder.clearCallingIdentity();
7502 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007503 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
Andrew Lee9431b832015-03-09 18:46:45 -07007507 }
7508
Hall Liuf6668912018-10-31 17:05:23 -07007509 /**
7510 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7511 * support for the feature and device firmware support.
7512 *
7513 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7514 */
7515 @Override
7516 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007518 final Phone phone = getPhone(subscriptionId);
7519 if (phone == null) {
7520 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7521 return false;
7522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007524 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7526 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007527 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 return isCarrierSupported && isDeviceSupported;
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
Hall Liu98187582018-01-22 19:15:32 -08007532 }
7533
Hall Liuf6668912018-10-31 17:05:23 -07007534 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007535 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7536 * RTT setting, will return true if the device and carrier both support RTT.
7537 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007538 */
7539 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 final long identity = Binder.clearCallingIdentity();
7541 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007542 boolean isRttSupported = isRttSupported(subscriptionId);
7543 boolean isUserRttSettingOn = Settings.Secure.getInt(
7544 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7545 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7546 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7547 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 } finally {
7549 Binder.restoreCallingIdentity(identity);
7550 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007551 }
7552
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007553 @Deprecated
7554 @Override
7555 public String getDeviceId(String callingPackage) {
7556 return getDeviceIdWithFeature(callingPackage, null);
7557 }
7558
Sanket Padawe7310cc72015-01-14 09:53:20 -08007559 /**
7560 * Returns the unique device ID of phone, for example, the IMEI for
7561 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7562 *
7563 * <p>Requires Permission:
7564 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7565 */
7566 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007567 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007568 try {
7569 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7570 } catch (SecurityException se) {
7571 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7572 throw new SecurityException("Package " + callingPackage + " does not belong to "
7573 + Binder.getCallingUid());
7574 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007575 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007576 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007577 return null;
7578 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007579 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007580 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007581 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007582 return null;
7583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584
7585 final long identity = Binder.clearCallingIdentity();
7586 try {
7587 return phone.getDeviceId();
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
7590 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007591 }
7592
Ping Sunc67b7c22016-03-02 19:16:45 +08007593 /**
7594 * {@hide}
7595 * Returns the IMS Registration Status on a particular subid
7596 *
7597 * @param subId
7598 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007599 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007600 Phone phone = getPhone(subId);
7601 if (phone != null) {
7602 return phone.isImsRegistered();
7603 } else {
7604 return false;
7605 }
7606 }
7607
Santos Cordon7a1885b2015-02-03 11:15:19 -08007608 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007609 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007610 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007612 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007613 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7614 }
7615 final long identity = Binder.clearCallingIdentity();
7616 try {
7617 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7618 } finally {
7619 Binder.restoreCallingIdentity(identity);
7620 }
7621 }
7622
7623 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007624 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007625 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007626 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007627 mApp,
7628 subscriptionId,
7629 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 Phone phone = getPhone(subscriptionId);
7633 if (phone == null) {
7634 return null;
7635 }
7636 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
7640 }
7641
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007642 /**
7643 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007644 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007645 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 Phone phone = getPhone(subId);
7649 if (phone != null) {
7650 return phone.isWifiCallingEnabled();
7651 } else {
7652 return false;
7653 }
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007656 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007657 }
7658
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007659 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007661 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 Phone phone = getPhone(subId);
7666 if (phone != null) {
7667 return phone.isVideoEnabled();
7668 } else {
7669 return false;
7670 }
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007673 }
7674 }
7675
7676 /**
7677 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7678 * defined in {@link ImsRegistrationImplBase}.
7679 */
7680 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 Phone phone = getPhone(subId);
7684 if (phone != null) {
7685 return phone.getImsRegistrationTech();
7686 } else {
7687 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7688 }
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007692 }
7693
Stuart Scott8eef64f2015-04-08 15:13:54 -07007694 @Override
7695 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007696 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007697 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7698 return;
7699 }
Kai Shif70f46f2021-03-03 13:59:46 -08007700 Phone defaultPhone = getDefaultPhone();
7701 if (defaultPhone != null) {
7702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7703 mApp, getDefaultPhone().getSubId(), "factoryReset");
7704 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007705 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007706
Svet Ganovcc087f82015-05-12 20:35:54 -07007707 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007708 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7709 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007710 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007711 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007712 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007713 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007714 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007715 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007716 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007717 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007718 // There has been issues when Sms raw table somehow stores orphan
7719 // fragments. They lead to garbled message when new fragments come
7720 // in and combined with those stale ones. In case this happens again,
7721 // user can reset all network settings which will clean up this table.
7722 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007723 // Clean up IMS settings as well here.
7724 int slotId = getSlotIndex(subId);
7725 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7726 ImsManager.getInstance(mApp, slotId).factoryReset();
7727 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007728
Kai Shif70f46f2021-03-03 13:59:46 -08007729 if (defaultPhone == null) {
7730 return;
7731 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007732 // Erase modem config if erase modem on network setting is enabled.
7733 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7734 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7735 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007736 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007737 }
Kai Shif70f46f2021-03-03 13:59:46 -08007738
7739 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007740 } finally {
7741 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007742 }
7743 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007744
SongFerngWangfd89b102021-05-27 22:44:54 +08007745 @VisibleForTesting
7746 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7747 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7748 return;
7749 }
7750 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7751 RILConstants.PREFERRED_NETWORK_MODE);
7752 SubscriptionManager.setSubscriptionProperty(subId,
7753 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7754 "user=" + defaultNetworkType);
7755 phone.loadAllowedNetworksFromSubscriptionDatabase();
7756 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7757 defaultNetworkType, null);
7758 }
7759
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007760 private void cleanUpSmsRawTable(Context context) {
7761 ContentResolver resolver = context.getContentResolver();
7762 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7763 resolver.delete(uri, null, null);
7764 }
7765
Narayan Kamath1c496c22015-04-16 14:40:19 +01007766 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007767 public String getSimLocaleForSubscriber(int subId) {
7768 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7769 final Phone phone = getPhone(subId);
7770 if (phone == null) {
7771 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007772 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 final long identity = Binder.clearCallingIdentity();
7775 try {
chen xu5d3637b2019-01-21 23:31:38 -08007776 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007777 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007778 if (info == null) {
7779 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7780 return null;
7781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 // Try and fetch the locale from the carrier properties or from the SIM language
7783 // preferences (EF-PL and EF-LI)...
7784 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007786 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7787 if (localeFromDefaultSim != null) {
7788 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7789 if (DBG) log("Using locale from subId: " + subId + " locale: "
7790 + localeFromDefaultSim);
7791 return localeFromDefaultSim.toLanguageTag();
7792 } else {
7793 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 }
7795 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 // The SIM language preferences only store a language (e.g. fr = French), not an
7798 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7799 // the SIM and carrier preferences does not include a country we add the country
7800 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007801 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007803 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804 return mccLocale.toLanguageTag();
7805 }
7806
7807 if (DBG) log("No locale found - returning null");
7808 return null;
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
7811 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007812 }
7813
7814 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007815 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007816 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007817 }
7818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 /**
7820 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7821 */
7822 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007824 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007825 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007826
Chenjie Yu1ba97252018-01-11 18:16:20 -08007827 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007828 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007829
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007830 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007831 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7832 * representing the state of the modem.
7833 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007834 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7835 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007836 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007837 */
7838 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007839 public void requestModemActivityInfo(ResultReceiver result) {
7840 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007841 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842
7843 final long identity = Binder.clearCallingIdentity();
7844 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007845 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 } finally {
7847 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007849 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007850
Siddharth Rayb8114062018-06-17 15:02:38 -07007851 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7852 // less than total activity duration.
7853 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7854 if (info == null) {
7855 return false;
7856 }
7857 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007858 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7859 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7860
Siddharth Rayb8114062018-06-17 15:02:38 -07007861 return (info.isValid()
7862 && (info.getSleepTimeMillis() <= activityDurationMs)
7863 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007864 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007865 && (totalTxTimeMs <= activityDurationMs));
7866 }
7867
Jack Yu85bd38a2015-11-09 11:34:32 -08007868 /**
7869 * {@hide}
7870 * Returns the service state information on specified subscription.
7871 */
7872 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007873 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7874 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007876 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007877 return null;
7878 }
7879
Hall Liuf19c44f2018-11-27 14:38:17 -08007880 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7881 LocationAccessPolicy.checkLocationPermission(mApp,
7882 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7883 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007884 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007885 .setCallingPid(Binder.getCallingPid())
7886 .setCallingUid(Binder.getCallingUid())
7887 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007888 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007889 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007890 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7891 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007892 .build());
7893
7894 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7895 LocationAccessPolicy.checkLocationPermission(mApp,
7896 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7897 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007898 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007899 .setCallingPid(Binder.getCallingPid())
7900 .setCallingUid(Binder.getCallingUid())
7901 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007902 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007903 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007904 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7905 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007906 .build());
7907 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7908 boolean hasFinePermission =
7909 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7910 boolean hasCoarsePermission =
7911 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7912
Jack Yu479f40e2020-10-27 21:29:25 -07007913 final Phone phone = getPhone(subId);
7914 if (phone == null) {
7915 return null;
7916 }
7917
Jordan Liu0f2bc442020-11-18 16:47:37 -08007918 final long identity = Binder.clearCallingIdentity();
7919
Jack Yu479f40e2020-10-27 21:29:25 -07007920 boolean isCallingPackageDataService = phone.getDataServicePackages()
7921 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007923 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7924 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7925 Rlog.d(LOG_TAG,
7926 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7927 return null;
7928 }
7929
Hall Liuf19c44f2018-11-27 14:38:17 -08007930 ServiceState ss = phone.getServiceState();
7931
7932 // Scrub out the location info in ServiceState depending on what level of access
7933 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007934 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007935 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7936 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 } finally {
7938 Binder.restoreCallingIdentity(identity);
7939 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007940 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007941
7942 /**
7943 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7944 *
7945 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7946 * voicemail ringtone.
7947 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7948 * PhoneAccount.
7949 */
7950 @Override
7951 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 final long identity = Binder.clearCallingIdentity();
7953 try {
7954 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7955 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007956 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7960 } finally {
7961 Binder.restoreCallingIdentity(identity);
7962 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007963 }
7964
7965 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007966 * Sets the per-account voicemail ringtone.
7967 *
7968 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7969 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7970 *
7971 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7972 * voicemail ringtone.
7973 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7974 * PhoneAccount.
7975 */
7976 @Override
7977 public void setVoicemailRingtoneUri(String callingPackage,
7978 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007979 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007981 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7982 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7984 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7985 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987
7988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7991 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007992 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 }
7994 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007998 }
7999
8000 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008001 * Returns whether vibration is set for voicemail notification in Phone settings.
8002 *
8003 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8004 * voicemail vibration setting.
8005 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8006 */
8007 @Override
8008 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008013 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008020 }
8021
Youhan Wange64578a2016-05-02 15:32:42 -07008022 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008023 * Sets the per-account voicemail vibration.
8024 *
8025 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8026 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8027 *
8028 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8029 * voicemail vibration setting.
8030 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8031 * specific PhoneAccount.
8032 */
8033 @Override
8034 public void setVoicemailVibrationEnabled(String callingPackage,
8035 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008036 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008037 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008038 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8039 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8041 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8042 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008043 }
8044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 final long identity = Binder.clearCallingIdentity();
8046 try {
8047 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8048 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008049 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 }
8051 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8052 } finally {
8053 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008054 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008055 }
8056
8057 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008058 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8059 *
8060 * @throws SecurityException if the caller does not have the required permission
8061 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008062 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008063 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008064 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008065 }
8066
8067 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008068 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8069 * permission.
8070 *
8071 * @throws SecurityException if the caller does not have the required permission
8072 */
8073 private void enforceSendSmsPermission() {
8074 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8075 }
8076
8077 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008078 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008079 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008080 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008081 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008082 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 final long identity = Binder.clearCallingIdentity();
8084 try {
8085 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008086 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 if (componentName == null) {
8088 throw new SecurityException(
8089 "Caller not current active visual voicemail package[null]");
8090 }
8091 String vvmPackage = componentName.getPackageName();
8092 if (!callingPackage.equals(vvmPackage)) {
8093 throw new SecurityException("Caller not current active visual voicemail package["
8094 + vvmPackage + "]");
8095 }
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008098 }
8099 }
8100
8101 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008102 * Return the application ID for the app type.
8103 *
8104 * @param subId the subscription ID that this request applies to.
8105 * @param appType the uicc app type.
8106 * @return Application ID for specificied app type, or null if no uicc.
8107 */
8108 @Override
8109 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008110 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008111 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112
8113 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008114 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 if (phone == null) {
8116 return null;
8117 }
8118 String aid = null;
8119 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008120 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 .getApplicationByType(appType).getAid();
8122 } catch (Exception e) {
8123 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8124 }
8125 return aid;
8126 } finally {
8127 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008128 }
Youhan Wange64578a2016-05-02 15:32:42 -07008129 }
8130
Youhan Wang4001d252016-05-11 10:29:41 -07008131 /**
8132 * Return the Electronic Serial Number.
8133 *
8134 * @param subId the subscription ID that this request applies to.
8135 * @return ESN or null if error.
8136 */
8137 @Override
8138 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008139 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008140 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141
8142 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008143 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008144 if (phone == null) {
8145 return null;
8146 }
8147 String esn = null;
8148 try {
8149 esn = phone.getEsn();
8150 } catch (Exception e) {
8151 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8152 }
8153 return esn;
8154 } finally {
8155 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008156 }
Youhan Wang4001d252016-05-11 10:29:41 -07008157 }
8158
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008159 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008160 * Return the Preferred Roaming List Version.
8161 *
8162 * @param subId the subscription ID that this request applies to.
8163 * @return PRLVersion or null if error.
8164 */
8165 @Override
8166 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008167 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008168 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008169
8170 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008171 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008172 if (phone == null) {
8173 return null;
8174 }
8175 String cdmaPrlVersion = null;
8176 try {
8177 cdmaPrlVersion = phone.getCdmaPrlVersion();
8178 } catch (Exception e) {
8179 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8180 }
8181 return cdmaPrlVersion;
8182 } finally {
8183 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008184 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008185 }
8186
8187 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008188 * Get snapshot of Telephony histograms
8189 * @return List of Telephony histograms
8190 * @hide
8191 */
8192 @Override
8193 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8195 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196
8197 final long identity = Binder.clearCallingIdentity();
8198 try {
8199 return RIL.getTelephonyRILTimingHistograms();
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008203 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008204
8205 /**
8206 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008207 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8208 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008209 * Require system privileges. In the future we may add this to carrier APIs.
8210 *
Michele Berionne482f8202018-11-27 18:57:59 -08008211 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008212 */
8213 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008214 @TelephonyManager.SetCarrierRestrictionResult
8215 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008216 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008217 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008218
Michele Berionne482f8202018-11-27 18:57:59 -08008219 if (carrierRestrictionRules == null) {
8220 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008221 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223 final long identity = Binder.clearCallingIdentity();
8224 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008225 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008226 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008227 } finally {
8228 Binder.restoreCallingIdentity(identity);
8229 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008230 }
8231
8232 /**
8233 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008234 * Get the allowed carrier list and the excluded carrier list, including the priority between
8235 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008236 * Require system privileges. In the future we may add this to carrier APIs.
8237 *
Michele Berionne482f8202018-11-27 18:57:59 -08008238 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008239 */
8240 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008241 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008242 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244
8245 final long identity = Binder.clearCallingIdentity();
8246 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008247 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8248 if (response instanceof CarrierRestrictionRules) {
8249 return (CarrierRestrictionRules) response;
8250 }
8251 // Response is an Exception of some kind,
8252 // which is signalled to the user as a NULL retval
8253 return null;
8254 } catch (Exception e) {
8255 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8256 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 } finally {
8258 Binder.restoreCallingIdentity(identity);
8259 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008260 }
8261
fionaxu59545b42016-05-25 15:53:37 -07008262 /**
fionaxu59545b42016-05-25 15:53:37 -07008263 * Action set from carrier signalling broadcast receivers to enable/disable radio
8264 * @param subId the subscription ID that this action applies to.
8265 * @param enabled control enable or disable radio.
8266 * {@hide}
8267 */
8268 @Override
8269 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8270 enforceModifyPermission();
8271 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272
8273 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008274 if (phone == null) {
8275 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8276 return;
8277 }
8278 try {
8279 phone.carrierActionSetRadioEnabled(enabled);
8280 } catch (Exception e) {
8281 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 } finally {
8283 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008284 }
8285 }
8286
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008287 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008288 * Enable or disable Voice over NR (VoNR)
8289 * @param subId the subscription ID that this action applies to.
8290 * @param enabled enable or disable VoNR.
8291 * @return operation result.
8292 */
8293 @Override
8294 public int setVoNrEnabled(int subId, boolean enabled) {
8295 enforceModifyPermission();
8296 final Phone phone = getPhone(subId);
8297
8298 final long identity = Binder.clearCallingIdentity();
8299 if (phone == null) {
8300 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8301 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8302 }
8303
8304 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8305 try {
8306 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8307 workSource);
8308 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008309
8310 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8311 if (DBG) {
8312 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8313 }
8314 SubscriptionManager.setSubscriptionProperty(
8315 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8316 (enabled ? "1" : "0"));
8317 }
8318
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008319 return result;
8320 } finally {
8321 Binder.restoreCallingIdentity(identity);
8322 }
8323 }
8324
8325 /**
8326 * Is voice over NR enabled
8327 * @return true if VoNR is enabled else false
8328 */
8329 @Override
8330 public boolean isVoNrEnabled(int subId) {
8331 enforceReadPrivilegedPermission("isVoNrEnabled");
8332 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8336 null, subId, workSource);
8337 if (DBG) log("isVoNrEnabled: " + isEnabled);
8338 return isEnabled;
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
8344 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008345 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8346 * network status based on which carrier apps could apply actions accordingly,
8347 * enable/disable default url handler for example.
8348 *
8349 * @param subId the subscription ID that this action applies to.
8350 * @param report control start/stop reporting the default network status.
8351 * {@hide}
8352 */
8353 @Override
8354 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8355 enforceModifyPermission();
8356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357
8358 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008359 if (phone == null) {
8360 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8361 return;
8362 }
8363 try {
8364 phone.carrierActionReportDefaultNetworkStatus(report);
8365 } catch (Exception e) {
8366 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 } finally {
8368 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008369 }
8370 }
8371
8372 /**
fionaxud9622282017-07-17 17:51:30 -07008373 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8374 * @param subId the subscription ID that this action applies to.
8375 * {@hide}
8376 */
8377 @Override
8378 public void carrierActionResetAll(int subId) {
8379 enforceModifyPermission();
8380 final Phone phone = getPhone(subId);
8381 if (phone == null) {
8382 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8383 return;
8384 }
8385 try {
8386 phone.carrierActionResetAll();
8387 } catch (Exception e) {
8388 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8389 }
8390 }
8391
8392 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008393 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8394 * bug report is being generated.
8395 */
8396 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008397 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008398 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8399 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008400 writer.println("Permission Denial: can't dump Phone from pid="
8401 + Binder.getCallingPid()
8402 + ", uid=" + Binder.getCallingUid()
8403 + "without permission "
8404 + android.Manifest.permission.DUMP);
8405 return;
8406 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008407 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008408 }
Jack Yueb89b242016-06-22 13:27:47 -07008409
Brad Ebingerdac2f002018-04-03 15:17:52 -07008410 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008411 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8412 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8413 @NonNull String[] args) {
8414 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8415 this, in.getFileDescriptor(), out.getFileDescriptor(),
8416 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008417 }
8418
Jack Yueb89b242016-06-22 13:27:47 -07008419 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008420 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008421 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008422 * @param reason the reason the data enable change is taking place
8423 * @param enabled True if enabling the data, otherwise disabling.
8424 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008425 */
8426 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008427 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008428 boolean enabled) {
8429 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8430 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8431 try {
8432 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008433 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008434 } catch (SecurityException se) {
8435 enforceModifyPermission();
8436 }
8437 } else {
8438 enforceModifyPermission();
8439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440
8441 final long identity = Binder.clearCallingIdentity();
8442 try {
8443 Phone phone = getPhone(subId);
8444 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008445 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8446 phone.carrierActionSetMeteredApnsEnabled(enabled);
8447 } else {
8448 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 }
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008453 }
8454 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008455
8456 /**
8457 * Get Client request stats
8458 * @return List of Client Request Stats
8459 * @hide
8460 */
8461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008462 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8463 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008466 return null;
8467 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008468 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 if (phone != null) {
8473 return phone.getClientRequestStats();
8474 }
8475
8476 return null;
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
8479 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008480 }
8481
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008482 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008483 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008484 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008485 }
Jack Yueb4124c2017-02-16 15:32:43 -08008486
8487 /**
Grace Chen70990072017-03-24 17:21:30 -07008488 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008489 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008490 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008491 * @param state State of SIM (power down, power up, pass through)
8492 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8493 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8494 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008495 *
8496 **/
8497 @Override
Grace Chen70990072017-03-24 17:21:30 -07008498 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008499 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008500 Phone phone = PhoneFactory.getPhone(slotIndex);
8501
vagdeviaf9a5b92018-08-15 16:01:53 -07008502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008504 final long identity = Binder.clearCallingIdentity();
8505 try {
8506 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008507 phone.setSimPowerState(state, null, workSource);
8508 }
8509 } finally {
8510 Binder.restoreCallingIdentity(identity);
8511 }
8512 }
8513
8514 /**
8515 * Set SIM card power state.
8516 *
8517 * @param slotIndex SIM slot id.
8518 * @param state State of SIM (power down, power up, pass through)
8519 * @param callback callback to trigger after success or failure
8520 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8521 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8522 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8523 *
8524 **/
8525 @Override
8526 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8527 IIntegerConsumer callback) {
8528 enforceModifyPermission();
8529 Phone phone = PhoneFactory.getPhone(slotIndex);
8530
8531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8532
8533 final long identity = Binder.clearCallingIdentity();
8534 try {
8535 if (phone != null) {
8536 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8537 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008538 }
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008541 }
8542 }
Shuo Qiandd210312017-04-12 22:11:33 +00008543
Tyler Gunn65d45c22017-06-05 11:22:26 -07008544 private boolean isUssdApiAllowed(int subId) {
8545 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008546 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008547 if (configManager == null) {
8548 return false;
8549 }
8550 PersistableBundle pb = configManager.getConfigForSubId(subId);
8551 if (pb == null) {
8552 return false;
8553 }
8554 return pb.getBoolean(
8555 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8556 }
8557
Shuo Qiandd210312017-04-12 22:11:33 +00008558 /**
8559 * Check if phone is in emergency callback mode
8560 * @return true if phone is in emergency callback mode
8561 * @param subId sub id
8562 */
goneil9c5f4872017-12-05 14:07:56 -08008563 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008564 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008565 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008566 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
8570 if (phone != null) {
8571 return phone.isInEcm();
8572 } else {
8573 return false;
8574 }
8575 } finally {
8576 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008577 }
8578 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008579
8580 /**
8581 * Get the current signal strength information for the given subscription.
8582 * Because this information is not updated when the device is in a low power state
8583 * it should not be relied-upon to be current.
8584 * @param subId Subscription index
8585 * @return the most recent cached signal strength info from the modem
8586 */
8587 @Override
8588 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008589 final long identity = Binder.clearCallingIdentity();
8590 try {
8591 Phone p = getPhone(subId);
8592 if (p == null) {
8593 return null;
8594 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 return p.getSignalStrength();
8597 } finally {
8598 Binder.restoreCallingIdentity(identity);
8599 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008600 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008601
Pengquan Meng77b7f132018-08-22 14:49:57 -07008602 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008603 * Get the current modem radio state for the given slot.
8604 * @param slotIndex slot index.
8605 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008606 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008607 * @return the current radio power state from the modem
8608 */
8609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008610 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008611 Phone phone = PhoneFactory.getPhone(slotIndex);
8612 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8614 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008615 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8616 }
8617
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 return phone.getRadioPowerState();
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8626 }
8627
8628 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008629 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8630 *
8631 * <p>Requires one of the following permissions:
8632 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8633 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8634 * privileges.
8635 *
8636 * @param subId subscription id
8637 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8638 * {@code false}.
8639 */
8640 @Override
8641 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008642 try {
8643 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8644 null);
8645 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008646 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008647 mApp, subId, "isDataRoamingEnabled");
8648 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008649
Pengquan Menga1bb6272018-09-06 09:59:22 -07008650 boolean isEnabled = false;
8651 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008652 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008653 Phone phone = getPhone(subId);
8654 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008655 } finally {
8656 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008658 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008659 }
8660
8661
8662 /**
8663 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8664 *
8665 * <p> Requires permission:
8666 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8667 * privileges.
8668 *
8669 * @param subId subscription id
8670 * @param isEnabled {@code true} means enable, {@code false} means disable.
8671 */
8672 @Override
8673 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8675 mApp, subId, "setDataRoamingEnabled");
8676
Pengquan Menga1bb6272018-09-06 09:59:22 -07008677 final long identity = Binder.clearCallingIdentity();
8678 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008679 Phone phone = getPhone(subId);
8680 if (phone != null) {
8681 phone.setDataRoamingEnabled(isEnabled);
8682 }
8683 } finally {
8684 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008685 }
8686 }
8687
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008688 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008689 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008690 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008691 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008692 mApp, subId, "isManualNetworkSelectionAllowed");
8693
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008694 boolean isAllowed = true;
8695 final long identity = Binder.clearCallingIdentity();
8696 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008697 Phone phone = getPhone(subId);
8698 if (phone != null) {
8699 isAllowed = phone.isCspPlmnEnabled();
8700 }
8701 } finally {
8702 Binder.restoreCallingIdentity(identity);
8703 }
8704 return isAllowed;
8705 }
8706
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008707 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8708 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8709 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8710 // Update each UiccPort object based on privilege access
8711 UiccPort[] uiccPorts = card.getUiccPortList();
8712 for (UiccPort port : uiccPorts) {
8713 UiccProfile profile = port.getUiccProfile();
8714 if (profile == null ||
8715 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8716 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8717 return false;
8718 }
8719 }
8720 return true;
8721 }
8722
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008723 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008724 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008725 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008726 mApp.getSystemService(AppOpsManager.class)
8727 .checkPackage(Binder.getCallingUid(), callingPackage);
8728
Jordan Liu1e142fc2019-04-22 15:10:43 -07008729 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008730 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008731 try {
8732 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008733 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008734 } catch (SecurityException e) {
8735 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8736 // has carrier privileges on an active UICC
8737 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8738 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008739 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008740 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008741 }
sandeepjsb6c87872021-09-27 15:34:44 +00008742 // checking compatibility, if calling app's target SDK is T and beyond.
8743 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8744 Binder.getCallingUid())) {
8745 isIccIdAccessRestricted = true;
8746 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008747 final long identity = Binder.clearCallingIdentity();
8748 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008749 UiccController uiccController = UiccController.getInstance();
8750 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008751 if (hasReadPermission) {
8752 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008753 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008754
8755 // Remove private info if the caller doesn't have access
8756 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8757 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008758 //setting the value after compatibility check
8759 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008760 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8761 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008762 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008763 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8764 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8765 if (card == null || card.getUiccPortList().length == 0) {
8766 // assume no access if the card or ports are unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008767 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008768 continue;
8769 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008770 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008771 filteredInfos.add(cardInfo);
8772 } else {
sandeepjsb6c87872021-09-27 15:34:44 +00008773 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008774 }
8775 }
8776 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008777 } finally {
8778 Binder.restoreCallingIdentity(identity);
8779 }
8780 }
8781
sandeepjsb6c87872021-09-27 15:34:44 +00008782 /**
8783 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8784 * generally private and require carrier privileges to view.
8785 *
8786 * @hide
8787 */
8788 @NonNull
8789 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8790 List<UiccPortInfo> portinfo = new ArrayList<>();
8791 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8792 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8793 }
8794 return new UiccCardInfo(
8795 cardInfo.isEuicc(),
8796 cardInfo.getCardId(),
8797 null,
8798 cardInfo.getPhysicalSlotIndex(),
8799 cardInfo.isRemovable(),
8800 cardInfo.isMultipleEnabledProfilesSupported(),
8801 portinfo
8802 );
8803 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008804
sandeepjsb6c87872021-09-27 15:34:44 +00008805 /**
8806 * @hide
8807 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8808 * These values are generally private and require carrier privileges to view.
8809 */
8810 @NonNull
8811 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8812 return new UiccPortInfo(
8813 UiccPortInfo.ICCID_REDACTED,
8814 portInfo.getPortIndex(),
8815 portInfo.getLogicalSlotIndex(),
8816 portInfo.isActive()
8817 );
8818 }
8819 @Override
8820 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008821 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008822 mApp.getSystemService(AppOpsManager.class)
8823 .checkPackage(Binder.getCallingUid(), callingPackage);
8824
8825 boolean hasReadPermission = false;
8826 boolean isLogicalSlotAccessRestricted = false;
8827 String iccId;
8828
8829 try {
8830 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8831 hasReadPermission = true;
8832 } catch (SecurityException e) {
8833 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8834 // has carrier privileges on an active UICC
8835 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8836 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8837 hasReadPermission = true;
8838 }
8839 }
8840
8841 // checking compatibility, if calling app's target SDK is T and beyond.
8842 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8843 Binder.getCallingUid())) {
8844 isLogicalSlotAccessRestricted = true;
8845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008846 final long identity = Binder.clearCallingIdentity();
8847 try {
8848 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8849 if (slots == null) {
8850 Rlog.i(LOG_TAG, "slots is null.");
8851 return null;
8852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008853 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8854 for (int i = 0; i < slots.length; i++) {
8855 UiccSlot slot = slots[i];
8856 if (slot == null) {
8857 continue;
8858 }
8859
Jordan Liu7be7e652019-05-06 18:55:02 +00008860 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008861 UiccCard card = slot.getUiccCard();
sandeepjsb6c87872021-09-27 15:34:44 +00008862 //if has read permission
8863 if (hasReadPermission) {
8864 iccId = slot.getIccId();
8865 } else {
sandeepjsa208e3b2021-11-17 04:05:58 +00008866 if (card != null) {
8867 // if no read permission checking carrier
8868 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
8869 iccId = slot.getIccId();
8870 } else {
8871 //if no carrier permission redact ICCID
8872 iccId = IccUtils.TEST_ICCID;
8873 }
sandeepjsb6c87872021-09-27 15:34:44 +00008874 } else {
sandeepjsa208e3b2021-11-17 04:05:58 +00008875 iccId = null;
sandeepjsb6c87872021-09-27 15:34:44 +00008876 }
8877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008878 if (card != null) {
8879 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008880 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008881 cardId = slot.getEid();
8882 if (TextUtils.isEmpty(cardId)) {
sandeepjsb6c87872021-09-27 15:34:44 +00008883 cardId = iccId;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008885 }
8886
Jordan Liu857451f2019-05-09 16:35:35 -07008887 if (cardId != null) {
8888 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8889 // if cardId is an EID, it's all digits so this is fine
8890 cardId = IccUtils.stripTrailingFs(cardId);
8891 }
8892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008893 int cardState = 0;
8894 switch (slot.getCardState()) {
8895 case CARDSTATE_ABSENT:
8896 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8897 break;
8898 case CARDSTATE_PRESENT:
8899 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8900 break;
8901 case CARDSTATE_ERROR:
8902 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8903 break;
8904 case CARDSTATE_RESTRICTED:
8905 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8906 break;
8907 default:
8908 break;
8909
8910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008911 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 slot.isEuicc(),
8913 cardId,
8914 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008915 slot.isExtendedApduSupported(),
sandeepjsb6c87872021-09-27 15:34:44 +00008916 slot.isRemovable(), Collections.singletonList(
8917 new UiccPortInfo(
8918 iccId,
8919 0 /* TODO: to use portList from UiccSlots */,
8920 slot.getPhoneId(),
8921 slot.isActive())));
8922 //setting the value after compatibility check
8923 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008924 }
8925 return infos;
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008928 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008929 }
8930
8931 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008932 @Deprecated
8933 //TODO : once integrating with HAL Changes we can clean up this Internal API.
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008934 public boolean switchSlots(int[] physicalSlots) {
8935 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936
8937 final long identity = Binder.clearCallingIdentity();
8938 try {
8939 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8940 } finally {
8941 Binder.restoreCallingIdentity(identity);
8942 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008943 }
Jack Yu4c988042018-02-27 15:30:01 -08008944
8945 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008946 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8947 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8948 enforceModifyPermission();
8949
8950 final long identity = Binder.clearCallingIdentity();
8951 try {
8952 //TODO: once integrating the HAL changes we can proceed with to work on the parsing side
8953 int[] physicalSlots = new int[slotMapping.size()];
8954 for (int i = 0; i < physicalSlots.length; i++) {
8955 physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex();
8956 }
8957 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8958 } finally {
8959 Binder.restoreCallingIdentity(identity);
8960 }
8961 }
8962
8963 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008964 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008965 final long identity = Binder.clearCallingIdentity();
8966 try {
8967 return UiccController.getInstance().getCardIdForDefaultEuicc();
8968 } finally {
8969 Binder.restoreCallingIdentity(identity);
8970 }
8971 }
8972
Pengquan Meng85728fb2018-03-12 16:31:21 -07008973 /**
goneil47ffb6e2018-04-06 15:40:58 -07008974 * A test API to reload the UICC profile.
8975 *
8976 * <p>Requires that the calling app has permission
8977 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8978 * @hide
8979 */
8980 @Override
8981 public void refreshUiccProfile(int subId) {
8982 enforceModifyPermission();
8983
8984 final long identity = Binder.clearCallingIdentity();
8985 try {
8986 Phone phone = getPhone(subId);
8987 if (phone == null) {
8988 return;
8989 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008990 UiccPort uiccPort = phone.getUiccPort();
8991 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008992 return;
8993 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008994 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008995 if (uiccProfile == null) {
8996 return;
8997 }
8998 uiccProfile.refresh();
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
9002 }
9003
9004 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009005 * Returns false if the mobile data is disabled by default, otherwise return true.
9006 */
9007 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009008 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009009 }
9010
9011 /**
9012 * Returns true if the data roaming is enabled by default, i.e the system property
9013 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9014 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9015 */
9016 private boolean getDefaultDataRoamingEnabled(int subId) {
9017 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009018 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009019 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009020 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9021 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9022 return isDataRoamingEnabled;
9023 }
9024
9025 /**
9026 * Returns the default network type for the given {@code subId}, if the default network type is
9027 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9028 */
9029 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009030 List<Integer> list = TelephonyProperties.default_network();
9031 int phoneId = mSubscriptionController.getPhoneId(subId);
9032 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9033 return list.get(phoneId);
9034 }
9035 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009036 }
fionaxua13278b2018-03-21 00:08:13 -07009037
9038 @Override
9039 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009040 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042
9043 final long identity = Binder.clearCallingIdentity();
9044 try {
9045 final Phone phone = getPhone(subId);
9046 if (phone == null) {
9047 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9048 return;
9049 }
chen xueaba88a2019-03-15 13:15:10 -07009050 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9051 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009052 if (carrierPrivilegeRules == null) {
9053 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9054 } else {
9055 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 } finally {
9058 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009059 }
fionaxua13278b2018-03-21 00:08:13 -07009060 }
9061
9062 @Override
9063 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009064 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065
9066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 final Phone phone = getPhone(subId);
9069 if (phone == null) {
9070 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9071 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9072 }
9073 return phone.getCarrierIdListVersion();
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009076 }
fionaxua13278b2018-03-21 00:08:13 -07009077 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009078
9079 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009080 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9081 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009083 mApp, subId, callingPackage, callingFeatureId,
9084 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009085 return -1;
9086 }
9087
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
9090 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9091 } finally {
9092 Binder.restoreCallingIdentity(identity);
9093 }
9094 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009095
9096 @Override
9097 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009098 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009099 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009100 mApp, subId, "getCdmaRoamingMode");
9101
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9105 } finally {
9106 Binder.restoreCallingIdentity(identity);
9107 }
9108 }
9109
9110 @Override
9111 public boolean setCdmaRoamingMode(int subId, int mode) {
9112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9113 mApp, subId, "setCdmaRoamingMode");
9114
9115 final long identity = Binder.clearCallingIdentity();
9116 try {
9117 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9118 } finally {
9119 Binder.restoreCallingIdentity(identity);
9120 }
9121 }
9122
9123 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009124 public int getCdmaSubscriptionMode(int subId) {
9125 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009126 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009127 mApp, subId, "getCdmaSubscriptionMode");
9128
9129 final long identity = Binder.clearCallingIdentity();
9130 try {
9131 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
9136
9137 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009138 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9140 mApp, subId, "setCdmaSubscriptionMode");
9141
9142 final long identity = Binder.clearCallingIdentity();
9143 try {
9144 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9145 } finally {
9146 Binder.restoreCallingIdentity(identity);
9147 }
9148 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009149
sqianc5eccab2018-10-19 18:46:41 -07009150 @Override
sqian8c685422019-02-22 15:55:18 -08009151 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009152 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009154 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9155 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009156 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9157 }
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
sqian854d44b2018-12-12 16:48:18 -08009160 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9161 for (Phone phone: PhoneFactory.getPhones()) {
9162 if (phone.getEmergencyNumberTracker() != null
9163 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9164 emergencyNumberListInternal.put(
9165 phone.getSubId(),
9166 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9167 }
sqian11b7a0e2018-12-05 18:48:28 -08009168 }
sqian854d44b2018-12-12 16:48:18 -08009169 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
sqianc5eccab2018-10-19 18:46:41 -07009173 }
9174
9175 @Override
sqian8c685422019-02-22 15:55:18 -08009176 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009177 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009178 if (!exactMatch) {
9179 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009180 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009181 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009182 }
9183 final long identity = Binder.clearCallingIdentity();
9184 try {
sqian854d44b2018-12-12 16:48:18 -08009185 for (Phone phone: PhoneFactory.getPhones()) {
9186 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009187 && phone.getEmergencyNumberTracker()
9188 .isEmergencyNumber(number, exactMatch)) {
9189 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009190 }
sqian11b7a0e2018-12-05 18:48:28 -08009191 }
9192 return false;
9193 } finally {
9194 Binder.restoreCallingIdentity(identity);
9195 }
9196 }
9197
sqianf4ca7ed2019-01-15 18:32:07 -08009198 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009199 * Start emergency callback mode for GsmCdmaPhone for testing.
9200 */
9201 @Override
9202 public void startEmergencyCallbackMode() {
9203 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9204 "startEmergencyCallbackMode");
9205 enforceModifyPermission();
9206 final long identity = Binder.clearCallingIdentity();
9207 try {
9208 for (Phone phone : PhoneFactory.getPhones()) {
9209 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9210 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9211 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9212 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9213 gsmCdmaPhone.obtainMessage(
9214 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9215 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9216 }
9217 }
9218 } finally {
9219 Binder.restoreCallingIdentity(identity);
9220 }
9221 }
9222
9223 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009224 * Update emergency number list for test mode.
9225 */
9226 @Override
9227 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9228 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9229 "updateEmergencyNumberListTestMode");
9230
9231 final long identity = Binder.clearCallingIdentity();
9232 try {
9233 for (Phone phone: PhoneFactory.getPhones()) {
9234 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9235 if (tracker != null) {
9236 tracker.executeEmergencyNumberTestModeCommand(action, num);
9237 }
9238 }
9239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 }
9243
9244 /**
9245 * Get the full emergency number list for test mode.
9246 */
9247 @Override
9248 public List<String> getEmergencyNumberListTestMode() {
9249 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9250 "getEmergencyNumberListTestMode");
9251
9252 final long identity = Binder.clearCallingIdentity();
9253 try {
9254 Set<String> emergencyNumbers = new HashSet<>();
9255 for (Phone phone: PhoneFactory.getPhones()) {
9256 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9257 if (tracker != null) {
9258 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9259 emergencyNumbers.add(num.getNumber());
9260 }
9261 }
9262 }
9263 return new ArrayList<>(emergencyNumbers);
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267 }
9268
chen xud6b45bd2018-10-30 22:27:10 -07009269 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009270 public int getEmergencyNumberDbVersion(int subId) {
9271 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9272
9273 final long identity = Binder.clearCallingIdentity();
9274 try {
9275 final Phone phone = getPhone(subId);
9276 if (phone == null) {
9277 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9278 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9279 }
9280 return phone.getEmergencyNumberDbVersion();
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 }
9285
9286 @Override
9287 public void notifyOtaEmergencyNumberDbInstalled() {
9288 enforceModifyPermission();
9289
9290 final long identity = Binder.clearCallingIdentity();
9291 try {
9292 for (Phone phone: PhoneFactory.getPhones()) {
9293 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9294 if (tracker != null) {
9295 tracker.updateOtaEmergencyNumberDatabase();
9296 }
9297 }
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
9302
9303 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009304 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009305 enforceActiveEmergencySessionPermission();
9306
9307 final long identity = Binder.clearCallingIdentity();
9308 try {
9309 for (Phone phone: PhoneFactory.getPhones()) {
9310 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9311 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009312 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9313 }
9314 }
9315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
9319
9320 @Override
9321 public void resetOtaEmergencyNumberDbFilePath() {
9322 enforceActiveEmergencySessionPermission();
9323
9324 final long identity = Binder.clearCallingIdentity();
9325 try {
9326 for (Phone phone: PhoneFactory.getPhones()) {
9327 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9328 if (tracker != null) {
9329 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009330 }
9331 }
9332 } finally {
9333 Binder.restoreCallingIdentity(identity);
9334 }
9335 }
9336
9337 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009338 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9339 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9340 Phone phone = getPhone(subId);
9341 if (phone == null) {
9342 return null;
9343 }
9344 final long identity = Binder.clearCallingIdentity();
9345 try {
9346 UiccProfile profile = UiccController.getInstance()
9347 .getUiccProfileForPhone(phone.getPhoneId());
9348 if (profile != null) {
9349 return profile.getCertsFromCarrierPrivilegeAccessRules();
9350 }
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 return null;
9355 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009356
9357 /**
9358 * Enable or disable a modem stack.
9359 */
9360 @Override
9361 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9362 enforceModifyPermission();
9363
9364 final long identity = Binder.clearCallingIdentity();
9365 try {
9366 Phone phone = PhoneFactory.getPhone(slotIndex);
9367 if (phone == null) {
9368 return false;
9369 } else {
9370 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9371 }
9372 } finally {
9373 Binder.restoreCallingIdentity(identity);
9374 }
9375 }
Michelecea4cf22018-12-21 15:00:11 -08009376
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009377 /**
9378 * Whether a modem stack is enabled or not.
9379 */
9380 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009381 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9382 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009383 Phone phone = PhoneFactory.getPhone(slotIndex);
9384 if (phone == null) return false;
9385
9386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009387 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9388 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009389 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9390 }
9391
9392 final long identity = Binder.clearCallingIdentity();
9393 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009394 try {
9395 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9396 } catch (NoSuchElementException ex) {
9397 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9398 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
9403
Michelecea4cf22018-12-21 15:00:11 -08009404 @Override
Michele0ea7d782019-03-19 14:58:42 -07009405 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009406 enforceModifyPermission();
9407
9408 final long identity = Binder.clearCallingIdentity();
9409 try {
9410 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009411 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009412 .commit();
9413 } finally {
9414 Binder.restoreCallingIdentity(identity);
9415 }
9416 }
9417
9418 @Override
Michele0ea7d782019-03-19 14:58:42 -07009419 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009420 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009422 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9423 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009424 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009425 }
Michelecea4cf22018-12-21 15:00:11 -08009426
9427 final long identity = Binder.clearCallingIdentity();
9428 try {
Michele0ea7d782019-03-19 14:58:42 -07009429 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009434
Michele0ea7d782019-03-19 14:58:42 -07009435 @TelephonyManager.IsMultiSimSupportedResult
9436 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009437 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9438 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9439 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009440 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9441 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009442 }
9443 // Check if the hardware supports multisim functionality. If usage of multisim is not
9444 // supported by the modem, indicate that it is restricted.
9445 PhoneCapability staticCapability =
9446 mPhoneConfigurationManager.getStaticPhoneCapability();
9447 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009448 loge("isMultiSimSupportedInternal: no static configuration available");
9449 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009450 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009451 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009452 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9453 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009454 }
9455 // Check if support of multiple SIMs is restricted by carrier
9456 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009457 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009458 }
9459
Michele0ea7d782019-03-19 14:58:42 -07009460 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009461 }
9462
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009463 /**
9464 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009465 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9466 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9467 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009468 * @param numOfSims number of active sims we want to switch to
9469 */
9470 @Override
9471 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009472 if (numOfSims == 1) {
9473 enforceModifyPermission();
9474 } else {
9475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9476 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9477 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009478 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009479
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009480 try {
Michele30b57b22019-03-01 12:01:14 -08009481 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009482 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009483 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9484 return;
9485 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009486 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9487 } finally {
9488 Binder.restoreCallingIdentity(identity);
9489 }
9490 }
9491
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009492 @Override
9493 public boolean isApplicationOnUicc(int subId, int appType) {
9494 enforceReadPrivilegedPermission("isApplicationOnUicc");
9495 Phone phone = getPhone(subId);
9496 if (phone == null) {
9497 return false;
9498 }
9499 final long identity = Binder.clearCallingIdentity();
9500 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009501 UiccPort uiccPort = phone.getUiccPort();
9502 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009503 return false;
9504 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009505 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009506 if (uiccProfile == null) {
9507 return false;
9508 }
9509 if (TelephonyManager.APPTYPE_SIM <= appType
9510 && appType <= TelephonyManager.APPTYPE_ISIM) {
9511 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9512 }
9513 return false;
9514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
9517 }
9518
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009519 /**
chen xub4baa772019-04-03 10:23:41 -07009520 * Get whether making changes to modem configurations will trigger reboot.
9521 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009522 */
9523 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009524 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9525 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009527 mApp, subId, callingPackage, callingFeatureId,
9528 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009529 return false;
9530 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009531 final long identity = Binder.clearCallingIdentity();
9532 try {
9533 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9534 } finally {
9535 Binder.restoreCallingIdentity(identity);
9536 }
9537 }
9538
Nathan Harold29f5f052019-02-15 13:41:57 -08009539 private void updateModemStateMetrics() {
9540 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9541 // TODO: check the state for each modem if the api is ready.
9542 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9543 }
9544
Pengquan Meng3889a572019-01-23 11:16:29 -08009545 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009546 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009547 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009548 // Verify that the callingPackage belongs to the calling UID
9549 mApp.getSystemService(AppOpsManager.class)
9550 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009551 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009552 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009553 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009554 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9555 if (slotInfos != null) {
9556 for (int i = 0; i < slotInfos.length; i++) {
9557 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9558 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9559 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9560 portInfo.getLogicalSlotIndex()));
9561 }
9562 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009563 }
9564 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009565 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009566 } finally {
9567 Binder.restoreCallingIdentity(identity);
9568 }
9569 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009570
9571 /**
9572 * Get the IRadio HAL Version
9573 */
9574 @Override
9575 public int getRadioHalVersion() {
9576 Phone phone = getDefaultPhone();
9577 if (phone == null) return -1;
9578 HalVersion hv = phone.getHalVersion();
9579 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9580 return hv.major * 100 + hv.minor;
9581 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009582
9583 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009584 * Get the current calling package name.
9585 * @return the current calling package name
9586 */
9587 @Override
9588 public String getCurrentPackageName() {
9589 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9590 }
9591
9592 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009593 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9594 * corresponding network requests on a subId.
9595 *
9596 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009597 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009598 * 2) APN is un-metered for this subscription, or
9599 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009600 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009601 *
9602 * @return whether data is allowed for a apn type.
9603 *
9604 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009605 */
9606 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009607 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009608 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9609 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009610
9611 // Now that all security checks passes, perform the operation as ourselves.
9612 final long identity = Binder.clearCallingIdentity();
9613 try {
9614 Phone phone = getPhone(subId);
9615 if (phone == null) return false;
9616
Jack Yu41407ee2019-05-13 16:54:09 -07009617 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009618 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9619 } finally {
9620 Binder.restoreCallingIdentity(identity);
9621 }
9622 }
9623
9624 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009625 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009626 enforceReadPrivilegedPermission("isApnMetered");
9627
9628 // Now that all security checks passes, perform the operation as ourselves.
9629 final long identity = Binder.clearCallingIdentity();
9630 try {
9631 Phone phone = getPhone(subId);
9632 if (phone == null) return true; // By default return true.
9633
Jack Yu41407ee2019-05-13 16:54:09 -07009634 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009635 } finally {
9636 Binder.restoreCallingIdentity(identity);
9637 }
9638 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009639
9640 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009641 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9642 int subscriptionId, IBooleanConsumer resultCallback) {
9643 enforceModifyPermission();
9644 long token = Binder.clearCallingIdentity();
9645 try {
9646 Phone phone = getPhone(subscriptionId);
9647 if (phone == null) {
9648 try {
9649 if (resultCallback != null) {
9650 resultCallback.accept(false);
9651 }
9652 } catch (RemoteException e) {
9653 // ignore
9654 }
9655 return;
9656 }
9657 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9658 Pair.create(specifiers, (x) -> {
9659 try {
9660 if (resultCallback != null) {
9661 resultCallback.accept(x);
9662 }
9663 } catch (RemoteException e) {
9664 // ignore
9665 }
9666 });
9667 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9668 } finally {
9669 Binder.restoreCallingIdentity(token);
9670 }
9671 }
9672
9673 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009674 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9675 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009676 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009677 mApp, subId, "getSystemSelectionChannels");
9678 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9679 final long identity = Binder.clearCallingIdentity();
9680 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009681 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9682 if (result instanceof IllegalStateException) {
9683 throw (IllegalStateException) result;
9684 }
9685 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009686 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9687 return specifiers;
9688 } finally {
9689 Binder.restoreCallingIdentity(identity);
9690 }
9691 }
9692
9693 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009694 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009695 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009696 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9697 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9698 if (iccRecords == null) {
9699 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9700 return false;
9701 }
9702 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9703 }
9704
9705 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009706 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9707 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009708 if (callingPackage == null) {
9709 callingPackage = getCurrentPackageName();
9710 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009711 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9712 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009713 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9714 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009715 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9716 }
9717 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9718 Intent intent = new Intent();
9719 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9720 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9721 // Bring up choose default SMS subscription dialog right now
9722 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9723 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9724 mApp.startActivity(intent);
9725 }
chen xud5ca2d52019-05-28 15:20:57 -07009726
9727 @Override
9728 public String getMmsUAProfUrl(int subId) {
9729 //TODO investigate if this API should require proper permission check in R b/133791609
9730 final long identity = Binder.clearCallingIdentity();
9731 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009732 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9733 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9734 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9735 return carrierUAProfUrl;
9736 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009737 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9738 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009739 } finally {
9740 Binder.restoreCallingIdentity(identity);
9741 }
9742 }
9743
9744 @Override
9745 public String getMmsUserAgent(int subId) {
9746 //TODO investigate if this API should require proper permission check in R b/133791609
9747 final long identity = Binder.clearCallingIdentity();
9748 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009749 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9750 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9751 if (!TextUtils.isEmpty(carrierUserAgent)) {
9752 return carrierUserAgent;
9753 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009754 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9755 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009756 } finally {
9757 Binder.restoreCallingIdentity(identity);
9758 }
9759 }
Jack Yub07d4972019-05-28 16:12:25 -07009760
9761 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009762 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9763 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009764
Jack Yub07d4972019-05-28 16:12:25 -07009765 final long identity = Binder.clearCallingIdentity();
9766 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009767 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009768 if (phone == null) return false;
9769
Hall Liua62f5da2020-09-25 10:42:19 -07009770 switch (policy) {
9771 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9772 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9773 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9774 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9775 default:
9776 throw new IllegalArgumentException(policy + " is not a valid policy");
9777 }
Jack Yub07d4972019-05-28 16:12:25 -07009778 } finally {
9779 Binder.restoreCallingIdentity(identity);
9780 }
9781 }
9782
9783 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009784 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009785 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009786 enforceModifyPermission();
9787
changbettyd5c246e2019-12-24 15:40:37 +08009788 final long identity = Binder.clearCallingIdentity();
9789 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009790 Phone phone = getPhone(subscriptionId);
9791 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009792
Hall Liua62f5da2020-09-25 10:42:19 -07009793 switch (policy) {
9794 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9795 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9796 break;
9797 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9798 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9799 break;
9800 default:
9801 throw new IllegalArgumentException(policy + " is not a valid policy");
9802 }
changbettyd5c246e2019-12-24 15:40:37 +08009803 } finally {
9804 Binder.restoreCallingIdentity(identity);
9805 }
9806 }
9807
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009808 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009809 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009810 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9811 * otherwise.
9812 */
9813 @Override
9814 public void setCepEnabled(boolean isCepEnabled) {
9815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9816
9817 final long identity = Binder.clearCallingIdentity();
9818 try {
9819 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9820 for (Phone phone : PhoneFactory.getPhones()) {
9821 Phone defaultPhone = phone.getImsPhone();
9822 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9823 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9824 ImsPhoneCallTracker imsPhoneCallTracker =
9825 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9826 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9827 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9828 + imsPhone.getMsisdn());
9829 }
9830 }
9831 } finally {
9832 Binder.restoreCallingIdentity(identity);
9833 }
9834 }
allenwtsu46dcc572020-01-08 18:24:03 +08009835
9836 /**
9837 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9838 *
9839 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9840 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9841 * before being read.
9842 */
9843 @Override
9844 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9845 isCompressed) {
9846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9847 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009848 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9849 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9850 }
9851 if (!isImsAvailableOnDevice()) {
9852 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9853 "IMS not available on device.");
9854 }
9855
9856 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009857 try {
Hui Wang761a6682020-10-31 05:12:53 +00009858 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9859 } finally {
9860 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009861 }
9862 }
zoey chene02881a2019-12-30 16:11:23 +08009863
9864 @Override
9865 public boolean isIccLockEnabled(int subId) {
9866 enforceReadPrivilegedPermission("isIccLockEnabled");
9867
9868 // Now that all security checks passes, perform the operation as ourselves.
9869 final long identity = Binder.clearCallingIdentity();
9870 try {
9871 Phone phone = getPhone(subId);
9872 if (phone != null && phone.getIccCard() != null) {
9873 return phone.getIccCard().getIccLockEnabled();
9874 } else {
9875 return false;
9876 }
9877 } finally {
9878 Binder.restoreCallingIdentity(identity);
9879 }
9880 }
9881
9882 /**
9883 * Set the ICC pin lock enabled or disabled.
9884 *
9885 * @return an integer representing the status of IccLock enabled or disabled in the following
9886 * three cases:
9887 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9888 * successfully.
9889 * - Positive number and zero for remaining password attempts.
9890 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9891 *
9892 */
9893 @Override
9894 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9895 enforceModifyPermission();
9896
9897 Phone phone = getPhone(subId);
9898 if (phone == null) {
9899 return 0;
9900 }
9901 // Now that all security checks passes, perform the operation as ourselves.
9902 final long identity = Binder.clearCallingIdentity();
9903 try {
9904 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9905 new Pair<Boolean, String>(enabled, password), phone, null);
9906 return attemptsRemaining;
9907
9908 } catch (Exception e) {
9909 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9910 } finally {
9911 Binder.restoreCallingIdentity(identity);
9912 }
9913 return 0;
9914 }
9915
9916 /**
9917 * Change the ICC password used in ICC pin lock.
9918 *
9919 * @return an integer representing the status of IccLock changed in the following three cases:
9920 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9921 * - Positive number and zero for remaining password attempts.
9922 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9923 *
9924 */
9925 @Override
9926 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9927 enforceModifyPermission();
9928
9929 Phone phone = getPhone(subId);
9930 if (phone == null) {
9931 return 0;
9932 }
9933 // Now that all security checks passes, perform the operation as ourselves.
9934 final long identity = Binder.clearCallingIdentity();
9935 try {
9936 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9937 new Pair<String, String>(oldPassword, newPassword), phone, null);
9938 return attemptsRemaining;
9939
9940 } catch (Exception e) {
9941 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9942 } finally {
9943 Binder.restoreCallingIdentity(identity);
9944 }
9945 return 0;
9946 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009947
9948 /**
9949 * Request for receiving user activity notification
9950 */
9951 @Override
9952 public void requestUserActivityNotification() {
9953 if (!mNotifyUserActivity.get()
9954 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9955 mNotifyUserActivity.set(true);
9956 }
9957 }
9958
9959 /**
9960 * Called when userActivity is signalled in the power manager.
9961 * This is safe to call from any thread, with any window manager locks held or not.
9962 */
9963 @Override
9964 public void userActivity() {
9965 // ***************************************
9966 // * Inherited from PhoneWindowManager *
9967 // ***************************************
9968 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9969 // WITH ITS LOCKS HELD.
9970 //
9971 // This code must be VERY careful about the locks
9972 // it acquires.
9973 // In fact, the current code acquires way too many,
9974 // and probably has lurking deadlocks.
9975
9976 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9977 throw new SecurityException("Only the OS may call notifyUserActivity()");
9978 }
9979
9980 if (mNotifyUserActivity.getAndSet(false)) {
9981 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9982 USER_ACTIVITY_NOTIFICATION_DELAY);
9983 }
9984 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009985
9986 @Override
9987 public boolean canConnectTo5GInDsdsMode() {
9988 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9989 }
Jack Yud10cdd42020-09-28 20:28:01 -07009990
9991 @Override
9992 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9993 String callingFeatureId) {
9994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9995 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9996 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9997 }
9998
9999 Phone phone = getPhone(subId);
10000 if (phone == null) {
10001 throw new RuntimeException("phone is not available");
10002 }
10003 // Now that all security checks passes, perform the operation as ourselves.
10004 final long identity = Binder.clearCallingIdentity();
10005 try {
10006 return phone.getEquivalentHomePlmns();
10007 } finally {
10008 Binder.restoreCallingIdentity(identity);
10009 }
10010 }
Daniel Bright59e67312020-11-13 11:49:37 -080010011
10012 @Override
10013 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010014 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10015 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010016 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010017 if (radioInterfaceCapabilities == null) {
10018 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010019 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010020 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010021 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010022
Hui Wang641e81c2020-10-12 12:14:23 -070010023 @Override
10024 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10025 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010026 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10027 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10028 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10029 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10030 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010031 if (DBG) {
10032 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10033 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10034 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10035 }
10036
10037 if (!SubscriptionManager.isValidSubscriptionId(subId)
10038 || appType < TelephonyManager.APPTYPE_UNKNOWN
10039 || appType > TelephonyManager.APPTYPE_ISIM
10040 || nafUrl == null || securityProtocol == null || callback == null) {
10041 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10042 if (callback != null) {
10043 try {
10044 callback.onAuthenticationFailure(
10045 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10046 } catch (RemoteException exception) {
10047 log("Fail to notify onAuthenticationFailure due to " + exception);
10048 }
10049 return;
10050 }
10051 }
10052
10053 final long token = Binder.clearCallingIdentity();
10054 try {
10055 getGbaManager(subId).bootstrapAuthenticationRequest(
10056 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10057 forceBootStrapping, callback));
10058 } finally {
10059 Binder.restoreCallingIdentity(token);
10060 }
10061 }
10062
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010063 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010064 * Attempts to set the radio power state for all phones for thermal reason.
10065 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010066 * requested radio power state will actually be set. See {@link
10067 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10068 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010069 * @param enable {@code true} if trying to turn radio on.
10070 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10071 * false}.
10072 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010073 private boolean setRadioPowerForThermal(boolean enable) {
10074 boolean isPhoneAvailable = false;
10075 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10076 Phone phone = PhoneFactory.getPhone(i);
10077 if (phone != null) {
10078 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10079 isPhoneAvailable = true;
10080 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010081 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010082
10083 // return true if successfully informed the phone object about the thermal radio power
10084 // request.
10085 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010086 }
10087
10088 private int handleDataThrottlingRequest(int subId,
10089 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010090 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10091 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10092 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10093 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10094 throw new IllegalArgumentException("modem does not support data throttling");
10095 }
10096
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010097 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10098 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010099 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010100 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10101 }
10102
10103 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10104
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010105 if (isDataThrottlingSupported) {
10106 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010107 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010108 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10109 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10110 } else if (thermalMitigationResult
10111 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010112 log("Modem likely does not support data throttling on secondary carrier. Data " +
10113 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10114 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010115 }
10116 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010117 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010118
10119 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010120 }
10121
Jack Nudelman644b91a2021-03-12 14:09:48 -080010122 private static List<String> getThermalMitigationAllowlist(Context context) {
10123 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10124 for (String pckg : context.getResources()
10125 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10126 sThermalMitigationAllowlistedPackages.add(pckg);
10127 }
10128 }
10129
10130 return sThermalMitigationAllowlistedPackages;
10131 }
10132
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010133 private boolean isAnyPhoneInEmergencyState() {
10134 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10135 if (tm.isInEmergencyCall()) {
10136 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10137 return true;
10138 }
10139 for (Phone phone : PhoneFactory.getPhones()) {
10140 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10141 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10142 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10143 + phone.isInEcm());
10144 return true;
10145 }
10146 }
10147
10148 return false;
10149 }
10150
Jack Nudelman644b91a2021-03-12 14:09:48 -080010151 /**
10152 * Used by shell commands to add an authorized package name for thermal mitigation.
10153 * @param packageName name of package to be allowlisted
10154 * @param context
10155 */
10156 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10157 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10158 sThermalMitigationAllowlistedPackages.add(packageName);
10159 }
10160
10161 /**
10162 * Used by shell commands to remove an authorized package name for thermal mitigation.
10163 * @param packageName name of package to remove from allowlist
10164 * @param context
10165 */
10166 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10167 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10168 sThermalMitigationAllowlistedPackages.remove(packageName);
10169 }
10170
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010171 /**
10172 * Thermal mitigation request to control functionalities at modem.
10173 *
10174 * @param subId the id of the subscription.
10175 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010176 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010177 *
10178 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10179 */
10180 @Override
10181 @ThermalMitigationResult
10182 public int sendThermalMitigationRequest(
10183 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010184 ThermalMitigationRequest thermalMitigationRequest,
10185 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010186 enforceModifyPermission();
10187
Jack Nudelman644b91a2021-03-12 14:09:48 -080010188 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10189 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10190 .contains(callingPackage)) {
10191 throw new SecurityException("Calling package must be configured in the device config. "
10192 + "calling package: " + callingPackage);
10193 }
10194
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10196 final long identity = Binder.clearCallingIdentity();
10197
10198 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10199 try {
10200 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10201 switch (thermalMitigationAction) {
10202 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10203 thermalMitigationResult =
10204 handleDataThrottlingRequest(subId,
10205 thermalMitigationRequest.getDataThrottlingRequest());
10206 break;
10207 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10208 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10209 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10210 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10211 }
10212
10213 // Ensure that radio is on. If not able to power on due to phone being
10214 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010215 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010216 thermalMitigationResult =
10217 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10218 break;
10219 }
10220
10221 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10222 false);
10223 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10224 break;
10225 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10226 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10227 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10228 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10229 }
10230
10231 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10232 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010233 Phone phone = getPhone(subId);
10234 if (phone == null) {
10235 thermalMitigationResult =
10236 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10237 break;
10238 }
10239
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010240 TelephonyConnectionService service =
10241 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010242 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010243 Log.e(LOG_TAG, "An emergency call is pending");
10244 thermalMitigationResult =
10245 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10246 break;
10247 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010248 thermalMitigationResult =
10249 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10250 break;
10251 }
10252 } else {
10253 thermalMitigationResult =
10254 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10255 break;
10256 }
10257
10258 // Turn radio off. If not able to power off due to phone being unavailable,
10259 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010260 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010261 thermalMitigationResult =
10262 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10263 break;
10264 }
10265 thermalMitigationResult =
10266 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10267 break;
10268 default:
10269 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10270 + "not exist. Requested action: " + thermalMitigationAction);
10271 }
10272 } catch (IllegalArgumentException e) {
10273 throw e;
10274 } catch (Exception e) {
10275 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10276 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10277 } finally {
10278 Binder.restoreCallingIdentity(identity);
10279 }
10280
10281 if (DBG) {
10282 log("thermalMitigationRequest returning with thermalMitigationResult: "
10283 + thermalMitigationResult);
10284 }
10285
10286 return thermalMitigationResult;
10287 }
Hui Wang641e81c2020-10-12 12:14:23 -070010288
10289 /**
10290 * Set the GbaService Package Name that Telephony will bind to.
10291 *
10292 * @param subId The sim that the GbaService is associated with.
10293 * @param packageName The name of the package to be replaced with.
10294 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10295 */
10296 @Override
10297 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10298 enforceModifyPermission();
10299
10300 final long identity = Binder.clearCallingIdentity();
10301 try {
10302 return getGbaManager(subId).overrideServicePackage(packageName);
10303 } finally {
10304 Binder.restoreCallingIdentity(identity);
10305 }
10306 }
10307
10308 /**
10309 * Return the package name of the currently bound GbaService.
10310 *
10311 * @param subId The sim that the GbaService is associated with.
10312 * @return the package name of the GbaService configuration, null if GBA is not supported.
10313 */
10314 @Override
10315 public String getBoundGbaService(int subId) {
10316 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10317
10318 final long identity = Binder.clearCallingIdentity();
10319 try {
10320 return getGbaManager(subId).getServicePackage();
10321 } finally {
10322 Binder.restoreCallingIdentity(identity);
10323 }
10324 }
10325
10326 /**
10327 * Set the release time for telephony to unbind GbaService.
10328 *
10329 * @param subId The sim that the GbaService is associated with.
10330 * @param interval The release time to unbind GbaService by millisecond.
10331 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10332 */
10333 @Override
10334 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10335 enforceModifyPermission();
10336
10337 final long identity = Binder.clearCallingIdentity();
10338 try {
10339 return getGbaManager(subId).overrideReleaseTime(interval);
10340 } finally {
10341 Binder.restoreCallingIdentity(identity);
10342 }
10343 }
10344
10345 /**
10346 * Return the release time for telephony to unbind GbaService.
10347 *
10348 * @param subId The sim that the GbaService is associated with.
10349 * @return The release time to unbind GbaService by millisecond.
10350 */
10351 @Override
10352 public int getGbaReleaseTime(int subId) {
10353 enforceReadPrivilegedPermission("getGbaReleaseTime");
10354
10355 final long identity = Binder.clearCallingIdentity();
10356 try {
10357 return getGbaManager(subId).getReleaseTime();
10358 } finally {
10359 Binder.restoreCallingIdentity(identity);
10360 }
10361 }
10362
10363 private GbaManager getGbaManager(int subId) {
10364 GbaManager instance = GbaManager.getInstance(subId);
10365 if (instance == null) {
10366 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10367 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10368 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10369 }
10370 return instance;
10371 }
Hui Wang761a6682020-10-31 05:12:53 +000010372
10373 /**
10374 * indicate whether the device and the carrier can support
10375 * RCS VoLTE single registration.
10376 */
10377 @Override
10378 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010379 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10380 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10381 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10382 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010383
10384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10385 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10386 }
10387
10388 final long identity = Binder.clearCallingIdentity();
10389 try {
10390 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10391 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010392 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10393 if (isCapable != null) {
10394 return isCapable;
10395 }
Hui Wang761a6682020-10-31 05:12:53 +000010396 }
Hui Wang67af90e2021-06-04 16:57:15 -070010397 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10398 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010399 } finally {
10400 Binder.restoreCallingIdentity(identity);
10401 }
10402 }
10403
10404 /**
10405 * Register RCS provisioning callback.
10406 */
10407 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010408 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010409 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010410 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010411 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010412 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10413 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010414
10415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10416 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10417 }
10418 if (!isImsAvailableOnDevice()) {
10419 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10420 "IMS not available on device.");
10421 }
10422
10423 final long identity = Binder.clearCallingIdentity();
10424 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010425 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010426 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010427 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10428 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010429 }
Hui Wang761a6682020-10-31 05:12:53 +000010430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
10434
10435 /**
10436 * Unregister RCS provisioning callback.
10437 */
10438 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010439 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010440 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010441 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010442 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010443 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10444 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010445
10446 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10447 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10448 }
10449 if (!isImsAvailableOnDevice()) {
10450 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10451 "IMS not available on device.");
10452 }
10453
10454 final long identity = Binder.clearCallingIdentity();
10455 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010456 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010457 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
10463 /**
10464 * trigger RCS reconfiguration.
10465 */
10466 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010467 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10468 "triggerRcsReconfiguration",
10469 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010470
10471 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10472 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10473 }
10474 if (!isImsAvailableOnDevice()) {
10475 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10476 "IMS not available on device.");
10477 }
10478
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
10485 }
10486
10487 /**
10488 * Provide the client configuration parameters of the RCS application.
10489 */
10490 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010491 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10492 "setRcsClientConfiguration",
10493 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010494
10495 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10496 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10497 }
10498 if (!isImsAvailableOnDevice()) {
10499 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10500 "IMS not available on device.");
10501 }
10502
10503 final long identity = Binder.clearCallingIdentity();
10504
10505 try {
10506 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10507 if (configBinder == null) {
10508 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010509 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10510 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010511 } else {
10512 configBinder.setRcsClientConfiguration(rcc);
10513 }
joonhunshin3e154242021-09-17 06:33:39 +000010514
10515 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10516 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010517 } catch (RemoteException e) {
10518 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010519 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10520 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010521 } finally {
10522 Binder.restoreCallingIdentity(identity);
10523 }
10524 }
10525
10526 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010527 * Enables or disables the test mode for RCS VoLTE single registration.
10528 */
10529 @Override
10530 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10531 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10532 "setRcsSingleRegistrationTestModeEnabled");
10533
10534 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10535 }
10536
10537 /**
10538 * Gets the test mode for RCS VoLTE single registration.
10539 */
10540 @Override
10541 public boolean getRcsSingleRegistrationTestModeEnabled() {
10542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10543 "getRcsSingleRegistrationTestModeEnabled");
10544
10545 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10546 }
10547
10548 /**
Hui Wang761a6682020-10-31 05:12:53 +000010549 * Overrides the config of RCS VoLTE single registration enabled for the device.
10550 */
10551 @Override
10552 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10554 "setDeviceSingleRegistrationEnabledOverride");
10555 enforceModifyPermission();
10556
10557 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10558 : Boolean.parseBoolean(enabledStr);
10559 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010560 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010561 }
10562
10563 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010564 * Sends a device to device communication message. Only usable via shell.
10565 * @param message message to send.
10566 * @param value message value.
10567 */
10568 @Override
10569 public void sendDeviceToDeviceMessage(int message, int value) {
10570 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010571 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010572 enforceModifyPermission();
10573
10574 final long identity = Binder.clearCallingIdentity();
10575 try {
10576 TelephonyConnectionService service =
10577 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10578 if (service == null) {
10579 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10580 return;
10581 }
10582 service.sendTestDeviceToDeviceMessage(message, value);
10583 } finally {
10584 Binder.restoreCallingIdentity(identity);
10585 }
10586 }
10587
Tyler Gunnbabbda02021-02-10 11:05:02 -080010588 /**
10589 * Sets the specified device to device transport active.
10590 * @param transport The transport to set active.
10591 */
10592 @Override
10593 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10594 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10595 "setActiveDeviceToDeviceTransport");
10596 enforceModifyPermission();
10597
10598 final long identity = Binder.clearCallingIdentity();
10599 try {
10600 TelephonyConnectionService service =
10601 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10602 if (service == null) {
10603 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10604 return;
10605 }
10606 service.setActiveDeviceToDeviceTransport(transport);
10607 } finally {
10608 Binder.restoreCallingIdentity(identity);
10609 }
10610 }
Tyler Gunn92479152021-01-20 16:30:10 -080010611
Tyler Gunnd4339262021-05-03 14:46:49 -070010612 @Override
10613 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10614 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10615 "setDeviceToDeviceForceEnabled");
10616
10617 final long identity = Binder.clearCallingIdentity();
10618 try {
10619 Arrays.stream(PhoneFactory.getPhones()).forEach(
10620 p -> {
10621 Phone thePhone = p.getImsPhone();
10622 if (thePhone != null && thePhone instanceof ImsPhone) {
10623 ImsPhone imsPhone = (ImsPhone) thePhone;
10624 CallTracker tracker = imsPhone.getCallTracker();
10625 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10626 ImsPhoneCallTracker imsPhoneCallTracker =
10627 (ImsPhoneCallTracker) tracker;
10628 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10629 }
10630 }
10631 }
10632 );
10633 } finally {
10634 Binder.restoreCallingIdentity(identity);
10635 }
10636 }
10637
Tyler Gunn92479152021-01-20 16:30:10 -080010638 /**
Hui Wang761a6682020-10-31 05:12:53 +000010639 * Gets the config of RCS VoLTE single registration enabled for the device.
10640 */
10641 @Override
10642 public boolean getDeviceSingleRegistrationEnabled() {
10643 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10644 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10645 }
10646
10647 /**
10648 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10649 */
10650 @Override
10651 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10653 "setCarrierSingleRegistrationEnabledOverride");
10654 enforceModifyPermission();
10655
10656 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10657 : Boolean.parseBoolean(enabledStr);
10658 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10659 subId, enabled);
10660 }
10661
10662 /**
10663 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10664 */
10665 @Override
10666 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10667 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10668 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10669 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010670
10671 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010672 * Overrides the ims feature validation result
10673 */
10674 @Override
10675 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10677 "setImsFeatureValidationOverride");
10678
10679 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10680 : Boolean.parseBoolean(enabledStr);
10681 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10682 subId, enabled);
10683 }
10684
10685 /**
10686 * Gets the ims feature validation override value
10687 */
10688 @Override
10689 public boolean getImsFeatureValidationOverride(int subId) {
10690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10691 "getImsFeatureValidationOverride");
10692 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10693 }
10694
10695 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010696 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10697 * their mobile plan.
10698 */
10699 @Override
10700 public String getMobileProvisioningUrl() {
10701 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10702 final long identity = Binder.clearCallingIdentity();
10703 try {
10704 return getDefaultPhone().getMobileProvisioningUrl();
10705 } finally {
10706 Binder.restoreCallingIdentity(identity);
10707 }
10708 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010709
James.cf Linbcdf8b32021-01-14 16:44:13 +080010710 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010711 * Get the EAB contact from the EAB database.
10712 */
10713 @Override
10714 public String getContactFromEab(String contact) {
10715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10716 enforceModifyPermission();
10717 final long identity = Binder.clearCallingIdentity();
10718 try {
10719 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10720 } finally {
10721 Binder.restoreCallingIdentity(identity);
10722 }
10723 }
10724
10725 /**
Calvin Pana1434322021-07-01 19:27:01 +080010726 * Get the EAB capability from the EAB database.
10727 */
10728 @Override
10729 public String getCapabilityFromEab(String contact) {
10730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10731 enforceModifyPermission();
10732 final long identity = Binder.clearCallingIdentity();
10733 try {
10734 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10735 } finally {
10736 Binder.restoreCallingIdentity(identity);
10737 }
10738 }
10739
10740 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010741 * Remove the EAB contacts from the EAB database.
10742 */
10743 @Override
10744 public int removeContactFromEab(int subId, String contacts) {
10745 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10746 enforceModifyPermission();
10747 final long identity = Binder.clearCallingIdentity();
10748 try {
10749 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10750 } finally {
10751 Binder.restoreCallingIdentity(identity);
10752 }
10753 }
10754
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010755 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010756 public boolean getDeviceUceEnabled() {
10757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10758 final long identity = Binder.clearCallingIdentity();
10759 try {
10760 return mApp.getDeviceUceEnabled();
10761 } finally {
10762 Binder.restoreCallingIdentity(identity);
10763 }
10764 }
10765
10766 @Override
10767 public void setDeviceUceEnabled(boolean isEnabled) {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 mApp.setDeviceUceEnabled(isEnabled);
10772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
10776
Brad Ebinger14d467f2021-02-12 06:18:28 +000010777 /**
10778 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10779 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10780 */
10781 // Used for SHELL command only right now.
10782 @Override
10783 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10784 List<String> featureTags) {
10785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10786 "addUceRegistrationOverrideShell");
10787 final long identity = Binder.clearCallingIdentity();
10788 try {
10789 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10790 new ArraySet<>(featureTags));
10791 } catch (ImsException e) {
10792 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10793 } finally {
10794 Binder.restoreCallingIdentity(identity);
10795 }
10796 }
10797
10798 /**
10799 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10800 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10801 */
10802 // Used for SHELL command only right now.
10803 @Override
10804 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10805 List<String> featureTags) {
10806 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10807 "removeUceRegistrationOverrideShell");
10808 final long identity = Binder.clearCallingIdentity();
10809 try {
10810 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10811 new ArraySet<>(featureTags));
10812 } catch (ImsException e) {
10813 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10814 } finally {
10815 Binder.restoreCallingIdentity(identity);
10816 }
10817 }
10818
10819 /**
10820 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10821 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10822 */
10823 // Used for SHELL command only right now.
10824 @Override
10825 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10827 "clearUceRegistrationOverrideShell");
10828 final long identity = Binder.clearCallingIdentity();
10829 try {
10830 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10831 } catch (ImsException e) {
10832 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10833 } finally {
10834 Binder.restoreCallingIdentity(identity);
10835 }
10836 }
10837
10838 /**
10839 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10840 */
10841 // Used for SHELL command only right now.
10842 @Override
10843 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10845 "getLatestRcsContactUceCapabilityShell");
10846 final long identity = Binder.clearCallingIdentity();
10847 try {
10848 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10849 } catch (ImsException e) {
10850 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10851 } finally {
10852 Binder.restoreCallingIdentity(identity);
10853 }
10854 }
10855
10856 /**
10857 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10858 * device does not have an active PUBLISH.
10859 */
10860 // Used for SHELL command only right now.
10861 @Override
10862 public String getLastUcePidfXmlShell(int subId) {
10863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10864 final long identity = Binder.clearCallingIdentity();
10865 try {
10866 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10867 } catch (ImsException e) {
10868 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10869 } finally {
10870 Binder.restoreCallingIdentity(identity);
10871 }
10872 }
10873
James.cf Line8713a42021-04-29 16:04:26 +080010874 /**
10875 * Remove UCE requests cannot be sent to the network status.
10876 */
10877 // Used for SHELL command only right now.
10878 @Override
10879 public boolean removeUceRequestDisallowedStatus(int subId) {
10880 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10881 final long identity = Binder.clearCallingIdentity();
10882 try {
10883 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10884 } catch (ImsException e) {
10885 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10886 } finally {
10887 Binder.restoreCallingIdentity(identity);
10888 }
10889 }
10890
James.cf Lin18bb9002021-05-25 01:37:38 +080010891 /**
10892 * Remove UCE requests cannot be sent to the network status.
10893 */
10894 // Used for SHELL command only.
10895 @Override
10896 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10898 final long identity = Binder.clearCallingIdentity();
10899 try {
10900 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10901 } catch (ImsException e) {
10902 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10903 } finally {
10904 Binder.restoreCallingIdentity(identity);
10905 }
10906 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010907
James.cf Lin4b784aa2021-01-31 03:25:15 +080010908 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010909 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10910 String callingPackage) {
10911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10912 mApp, subId, "setSignalStrengthUpdateRequest");
10913
10914 final int callingUid = Binder.getCallingUid();
10915 // Verify that tha callingPackage belongs to the calling UID
10916 mApp.getSystemService(AppOpsManager.class)
10917 .checkPackage(callingUid, callingPackage);
10918
Rambo Wang3607f502021-02-01 21:51:40 -080010919 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010920
10921 final long identity = Binder.clearCallingIdentity();
10922 try {
10923 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10924 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10925
10926 if (result instanceof IllegalStateException) {
10927 throw (IllegalStateException) result;
10928 }
10929 } finally {
10930 Binder.restoreCallingIdentity(identity);
10931 }
10932 }
10933
10934 @Override
10935 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10936 String callingPackage) {
10937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10938 mApp, subId, "clearSignalStrengthUpdateRequest");
10939
10940 final int callingUid = Binder.getCallingUid();
10941 // Verify that tha callingPackage belongs to the calling UID
10942 mApp.getSystemService(AppOpsManager.class)
10943 .checkPackage(callingUid, callingPackage);
10944
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10948 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10949
10950 if (result instanceof IllegalStateException) {
10951 throw (IllegalStateException) result;
10952 }
10953 } finally {
10954 Binder.restoreCallingIdentity(identity);
10955 }
10956 }
10957
Rambo Wang3607f502021-02-01 21:51:40 -080010958 private static void validateSignalStrengthUpdateRequest(Context context,
10959 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010960 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10961 // phone/system process do not have further restriction on request
10962 return;
10963 }
10964
10965 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010966 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010967 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010968 context.enforceCallingOrSelfPermission(
10969 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10970 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010971 }
10972
10973 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10974 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10975 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10976 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10977 || info.isEnabled()) {
10978 throw new IllegalArgumentException(
10979 "Only system can set hide fields in SignalThresholdInfo");
10980 }
10981
10982 // Thresholds length for each RAN need in range. This has been validated in
10983 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10984 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10985 final int[] thresholds = info.getThresholds();
10986 Objects.requireNonNull(thresholds);
10987 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10988 || thresholds.length
10989 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10990 throw new IllegalArgumentException(
10991 "thresholds length is out of range: " + thresholds.length);
10992 }
10993 }
10994 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010995
10996 /**
10997 * Gets the current phone capability.
10998 *
10999 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11000 * @return the PhoneCapability which describes the data connection capability of modem.
11001 * It's used to evaluate possible phone config change, for example from single
11002 * SIM device to multi-SIM device.
11003 */
11004 @Override
11005 public PhoneCapability getPhoneCapability() {
11006 enforceReadPrivilegedPermission("getPhoneCapability");
11007 final long identity = Binder.clearCallingIdentity();
11008 try {
11009 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11010 } finally {
11011 Binder.restoreCallingIdentity(identity);
11012 }
11013 }
Michele Berionne5e411512020-11-13 02:36:59 +000011014
11015 /**
11016 * Prepare TelephonyManager for an unattended reboot. The reboot is
11017 * required to be done shortly after the API is invoked.
11018 */
11019 @Override
11020 @TelephonyManager.PrepareUnattendedRebootResult
11021 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011022 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011023 enforceRebootPermission();
11024
11025 final long identity = Binder.clearCallingIdentity();
11026 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011027 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011028 } finally {
11029 Binder.restoreCallingIdentity(identity);
11030 }
11031 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011032
11033 /**
11034 * Request to get the current slicing configuration including URSP rules and
11035 * NSSAIs (configured, allowed and rejected).
11036 *
11037 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11038 */
11039 @Override
11040 public void getSlicingConfig(ResultReceiver callback) {
11041 enforceReadPrivilegedPermission("getSlicingConfig");
11042
11043 final long identity = Binder.clearCallingIdentity();
11044 try {
11045 Phone phone = getDefaultPhone();
11046 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11047 } finally {
11048 Binder.restoreCallingIdentity(identity);
11049 }
11050 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011051
11052 /**
11053 * Register an IMS connection state callback
11054 */
11055 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011056 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11057 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011058 if (feature == ImsFeature.FEATURE_MMTEL) {
11059 // ImsMmTelManager
11060 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11061 TelephonyPermissions
11062 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11063 mApp, subId, "registerImsStateCallback");
11064 } else if (feature == ImsFeature.FEATURE_RCS) {
11065 // ImsRcsManager or SipDelegateManager
11066 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11067 Binder.getCallingUid(), "registerImsStateCallback",
11068 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11069 Manifest.permission.READ_PRECISE_PHONE_STATE,
11070 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11071 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11072 }
11073
11074 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11075 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11076 "IMS not available on device.");
11077 }
11078
11079 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11080 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11081 }
11082
11083 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11084 if (controller == null) {
11085 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11086 "IMS not available on device.");
11087 }
11088
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011089 if (callingPackage == null) {
11090 callingPackage = getCurrentPackageName();
11091 }
11092
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011093 final long token = Binder.clearCallingIdentity();
11094 try {
11095 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011096 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011097 } catch (ImsException e) {
11098 throw new ServiceSpecificException(e.getCode());
11099 } finally {
11100 Binder.restoreCallingIdentity(token);
11101 }
11102 }
11103
11104 /**
11105 * Unregister an IMS connection state callback
11106 */
11107 @Override
11108 public void unregisterImsStateCallback(IImsStateCallback cb) {
11109 final long token = Binder.clearCallingIdentity();
11110 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11111 if (controller == null) {
11112 return;
11113 }
11114 try {
11115 controller.unregisterImsStateCallback(cb);
11116 } finally {
11117 Binder.restoreCallingIdentity(token);
11118 }
11119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011120}