blob: 815f90ef9bbf156158e57b7ccb6259774448279d [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000036import android.compat.annotation.ChangeId;
37import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070038import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070039import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.content.Context;
41import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070043import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080044import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070075import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080076import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080077import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070078import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080079import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070080import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080081import android.telephony.CellIdentityCdma;
82import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070084import android.telephony.CellInfoGsm;
85import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070086import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070088import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070089import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070090import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080091import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070094import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080095import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080096import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800100import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800101import android.telephony.SignalStrengthUpdateRequest;
102import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800103import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800105import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800110import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000113import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700114import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800116import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800117import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800118import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700119import android.telephony.gba.GbaAuthRequest;
120import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700121import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000124import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700125import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700126import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800127import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700128import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700132import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800134import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800136import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700139import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800141import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Andrew Lee312e8172014-10-23 17:01:36 -0700143import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800144import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800145import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800146import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700149import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700150import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800151import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700156import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800157import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800158import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800159import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700160import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000161import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800163import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700166import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700167import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700170import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800171import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700172import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700173import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700174import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700175import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800176import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800177import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700178import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700179import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700180import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800181import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800182import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700184import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700186import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800187import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700188import com.android.internal.telephony.imsphone.ImsPhone;
189import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000190import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800191import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700192import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700193import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800194import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800196import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700197import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000200import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800201import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000202import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800203import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700204import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700205import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800206import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800207import com.android.phone.callcomposer.CallComposerPictureManager;
208import com.android.phone.callcomposer.CallComposerPictureTransfer;
209import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700210import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700211import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800212import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700214import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800215import com.android.services.telephony.TelecomAccountRegistry;
216import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800217import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800218
Hall Liu82694d52020-12-11 18:22:04 -0800219import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700220import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.IOException;
222import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800225import java.util.Arrays;
sandeepjsb6c87872021-09-27 15:34:44 +0000226import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800227import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800228import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800229import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100230import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800231import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700232import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800233import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800234import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800236import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800237import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239/**
240 * Implementation of the ITelephony interface.
241 */
Santos Cordon117fee72014-05-16 17:56:12 -0700242public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 private static final String LOG_TAG = "PhoneInterfaceManager";
244 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
245 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800246 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
248 // Message codes used with mMainThreadHandler
249 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700250 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
251 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700252 private static final int CMD_OPEN_CHANNEL = 9;
253 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
254 private static final int CMD_CLOSE_CHANNEL = 11;
255 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800256 private static final int CMD_NV_READ_ITEM = 13;
257 private static final int EVENT_NV_READ_ITEM_DONE = 14;
258 private static final int CMD_NV_WRITE_ITEM = 15;
259 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
260 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
261 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700262 private static final int CMD_RESET_MODEM_CONFIG = 19;
263 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800264 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
265 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800266 private static final int CMD_SEND_ENVELOPE = 25;
267 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000268 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
269 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700270 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
271 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
272 private static final int CMD_EXCHANGE_SIM_IO = 31;
273 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800274 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
275 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700276 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
277 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700278 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
279 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700280 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
281 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
282 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700284 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
285 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
286 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
287 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700288 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800289 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
290 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000291 private static final int CMD_SWITCH_SLOTS = 50;
292 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700293 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
294 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
295 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
296 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
297 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
298 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
299 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
300 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700301 private static final int CMD_GET_ALL_CELL_INFO = 60;
302 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
303 private static final int CMD_GET_CELL_LOCATION = 62;
304 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700305 private static final int CMD_MODEM_REBOOT = 64;
306 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700307 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
308 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800309 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
310 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700311 private static final int CMD_GET_MODEM_STATUS = 70;
312 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700313 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
314 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700315 private static final int CMD_ERASE_MODEM_CONFIG = 74;
316 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800317 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
318 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
319 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
320 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800321 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
322 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800323 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800324 private static final int CMD_GET_CALL_FORWARDING = 83;
325 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
326 private static final int CMD_SET_CALL_FORWARDING = 85;
327 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
328 private static final int CMD_GET_CALL_WAITING = 87;
329 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
330 private static final int CMD_SET_CALL_WAITING = 89;
331 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700332 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
333 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
334 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
335 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700336 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
337 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800338 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
339 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800340 private static final int CMD_SET_DATA_THROTTLING = 99;
341 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800342 private static final int CMD_SET_SIM_POWER = 101;
343 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800344 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
345 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
346 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
347 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800348 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
349 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000350 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800351 private static final int CMD_GET_SLICING_CONFIG = 110;
352 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800353 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700354 private static final int CMD_ENABLE_VONR = 113;
355 private static final int EVENT_ENABLE_VONR_DONE = 114;
356 private static final int CMD_IS_VONR_ENABLED = 115;
357 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800359 // Parameters of select command.
360 private static final int SELECT_COMMAND = 0xA4;
361 private static final int SELECT_P1 = 0x04;
362 private static final int SELECT_P2 = 0;
363 private static final int SELECT_P3 = 0x10;
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 /** The singleton instance. */
366 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800367 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800370 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800371 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700372 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700374 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800376 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700378 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800379 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380
Peter Wangdafb9ac2020-01-15 14:13:38 -0800381 /** User Activity */
382 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800383 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
384
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700385 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
386
Derek Tan97ebb422014-09-05 16:55:38 -0700387 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
388 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800389 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800390 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700391
Michelecea4cf22018-12-21 15:00:11 -0800392 // String to store multi SIM allowed
393 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
394
Derek Tan740e1672017-06-27 14:56:27 -0700395 // The AID of ISD-R.
396 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
397
yinxub1bed742017-04-17 11:45:04 -0700398 private NetworkScanRequestTracker mNetworkScanRequestTracker;
399
David Kelly5e06a7f2018-03-12 14:10:59 +0000400 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
401 private static final int MANUFACTURER_CODE_LENGTH = 8;
402
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800403 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800404 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800405
Derek Tan89e89d42014-07-08 17:00:10 -0700406 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700407 * Experiment flag to enable erase modem config on reset network, default value is false
408 */
409 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
410 "reset_network_erase_modem_config_enabled";
411
Rambo Wang0f050d82021-02-12 11:43:36 -0800412 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjsb6c87872021-09-27 15:34:44 +0000413 /**
414 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
415 * one ICCID active at the same time.
416 * Apps should use below API signatures if targeting SDK is T and beyond.
417 *
418 * @hide
419 */
420 @ChangeId
421 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
422 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800423
Naina Nallurid63128d2019-09-17 14:10:30 -0700424 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 * A request object to use for transmitting data to an ICC.
426 */
427 private static final class IccAPDUArgument {
428 public int channel, cla, command, p1, p2, p3;
429 public String data;
430
431 public IccAPDUArgument(int channel, int cla, int command,
432 int p1, int p2, int p3, String data) {
433 this.channel = channel;
434 this.cla = cla;
435 this.command = command;
436 this.p1 = p1;
437 this.p2 = p2;
438 this.p3 = p3;
439 this.data = data;
440 }
441 }
442
443 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700444 * A request object to use for transmitting data to an ICC.
445 */
446 private static final class ManualNetworkSelectionArgument {
447 public OperatorInfo operatorInfo;
448 public boolean persistSelection;
449
450 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
451 this.operatorInfo = operatorInfo;
452 this.persistSelection = persistSelection;
453 }
454 }
455
456 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
458 * request after sending. The main thread will notify the request when it is complete.
459 */
460 private static final class MainThreadRequest {
461 /** The argument to use for the request */
462 public Object argument;
463 /** The result of the request that is run on the main thread */
464 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800465 // The subscriber id that this request applies to. Defaults to
466 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
467 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468
Nathan Harold92bed182018-10-12 18:16:49 -0700469 // In cases where subId is unavailable, the caller needs to specify the phone.
470 public Phone phone;
471
vagdeviaf9a5b92018-08-15 16:01:53 -0700472 public WorkSource workSource;
473
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 public MainThreadRequest(Object argument) {
475 this.argument = argument;
476 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800477
Nathan Harold92bed182018-10-12 18:16:49 -0700478 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
479 this.argument = argument;
480 if (phone != null) {
481 this.phone = phone;
482 }
483 this.workSource = workSource;
484 }
485
vagdeviaf9a5b92018-08-15 16:01:53 -0700486 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800487 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800488 if (subId != null) {
489 this.subId = subId;
490 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700491 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493 }
494
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800495 private static final class IncomingThirdPartyCallArgs {
496 public final ComponentName component;
497 public final String callId;
498 public final String callerDisplayName;
499
500 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
501 String callerDisplayName) {
502 this.component = component;
503 this.callId = callId;
504 this.callerDisplayName = callerDisplayName;
505 }
506 }
507
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 /**
509 * A handler that processes messages on the main thread in the phone process. Since many
510 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
511 * inbound binder threads to the main thread in the phone process. The Binder thread
512 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
513 * on, which will be notified when the operation completes and will contain the result of the
514 * request.
515 *
516 * <p>If a MainThreadRequest object is provided in the msg.obj field,
517 * note that request.result must be set to something non-null for the calling thread to
518 * unblock.
519 */
520 private final class MainThreadHandler extends Handler {
521 @Override
522 public void handleMessage(Message msg) {
523 MainThreadRequest request;
524 Message onCompleted;
525 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000526 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800528 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529
530 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 case CMD_HANDLE_USSD_REQUEST: {
532 request = (MainThreadRequest) msg.obj;
533 final Phone phone = getPhoneFromRequest(request);
534 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
535 String ussdRequest = ussdObject.first;
536 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700537
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 if (!isUssdApiAllowed(request.subId)) {
539 // Carrier does not support use of this API, return failure.
540 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
541 UssdResponse response = new UssdResponse(ussdRequest, null);
542 Bundle returnData = new Bundle();
543 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
544 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700545
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 request.result = true;
547 notifyRequester(request);
548 return;
549 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 try {
552 request.result = phone != null
553 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
554 } catch (CallStateException cse) {
555 request.result = false;
556 }
557 // Wake up the requesting thread
558 notifyRequester(request);
559 break;
pkanwar32d516d2016-10-14 19:37:38 -0700560 }
561
Yorke Lee716f67e2015-06-17 15:39:16 -0700562 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700564 final Phone phone = getPhoneFromRequest(request);
565 request.result = phone != null ?
566 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
567 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000576 uiccPort = getUiccPortFromRequest(request);
577 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 loge("iccTransmitApduLogicalChannel: No UICC");
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
583 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000584 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 iccArgument.channel, iccArgument.cla, iccArgument.command,
586 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
594 if (ar.exception == null && ar.result != null) {
595 request.result = ar.result;
596 } else {
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
598 if (ar.result == null) {
599 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800600 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800602 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 } else {
604 loge("iccTransmitApduLogicalChannel: Unknown exception");
605 }
606 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
611 request = (MainThreadRequest) msg.obj;
612 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000613 uiccPort = getUiccPortFromRequest(request);
614 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 loge("iccTransmitApduBasicChannel: No UICC");
616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 } else {
619 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
620 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000621 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
623 iccArgument.p3, iccArgument.data, onCompleted);
624 }
625 break;
626
627 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result;
632 } else {
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
634 if (ar.result == null) {
635 loge("iccTransmitApduBasicChannel: Empty response");
636 } else if (ar.exception instanceof CommandException) {
637 loge("iccTransmitApduBasicChannel: CommandException: " +
638 ar.exception);
639 } else {
640 loge("iccTransmitApduBasicChannel: Unknown exception");
641 }
642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 break;
645
646 case CMD_EXCHANGE_SIM_IO:
647 request = (MainThreadRequest) msg.obj;
648 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000649 uiccPort = getUiccPortFromRequest(request);
650 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 loge("iccExchangeSimIO: No UICC");
652 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 } else {
655 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
656 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000657 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
659 iccArgument.data, onCompleted);
660 }
661 break;
662
663 case EVENT_EXCHANGE_SIM_IO_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result;
668 } else {
669 request.result = new IccIoResult(0x6f, 0, (byte[])null);
670 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 break;
673
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 case CMD_SEND_ENVELOPE:
675 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000676 uiccPort = getUiccPortFromRequest(request);
677 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 loge("sendEnvelopeWithStatus: No UICC");
679 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 } else {
682 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 break;
686
687 case EVENT_SEND_ENVELOPE_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800692 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700693 request.result = new IccIoResult(0x6F, 0, (byte[])null);
694 if (ar.result == null) {
695 loge("sendEnvelopeWithStatus: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("sendEnvelopeWithStatus: CommandException: " +
698 ar.exception);
699 } else {
700 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
701 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800704 break;
705
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 case CMD_OPEN_CHANNEL:
707 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000708 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800709 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700711 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800712 request.result = new IccOpenLogicalChannelResponse(-1,
713 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 } else {
716 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000717 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800718 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
722 case EVENT_OPEN_CHANNEL_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 int[] result = (int[]) ar.result;
728 int channelId = result[0];
729 byte[] selectResponse = null;
730 if (result.length > 1) {
731 selectResponse = new byte[result.length - 1];
732 for (int i = 1; i < result.length; ++i) {
733 selectResponse[i - 1] = (byte) result[i];
734 }
735 }
736 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700737 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 if (ar.result == null) {
740 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 if (ar.exception != null) {
743 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
744 }
745
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700746 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700747 if (ar.exception instanceof CommandException) {
748 CommandException.Error error =
749 ((CommandException) (ar.exception)).getCommandError();
750 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700751 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700752 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700753 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 }
755 }
756 openChannelResp = new IccOpenLogicalChannelResponse(
757 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700759 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 break;
762
763 case CMD_CLOSE_CHANNEL:
764 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000765 uiccPort = getUiccPortFromRequest(request);
766 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900768 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 } else {
771 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000772 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700773 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 break;
775
776 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800777 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
778 break;
779
780 case CMD_NV_READ_ITEM:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
784 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
787 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800790 if (ar.exception == null && ar.result != null) {
791 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800793 request.result = "";
794 if (ar.result == null) {
795 loge("nvReadItem: Empty response");
796 } else if (ar.exception instanceof CommandException) {
797 loge("nvReadItem: CommandException: " +
798 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800800 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 }
802 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700803 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 break;
805
Jake Hambye994d462014-02-03 13:10:13 -0800806 case CMD_NV_WRITE_ITEM:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
809 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800810 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700811 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
814 case EVENT_NV_WRITE_ITEM_DONE:
815 handleNullReturnEvent(msg, "nvWriteItem");
816 break;
817
818 case CMD_NV_WRITE_CDMA_PRL:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800821 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800822 break;
823
824 case EVENT_NV_WRITE_CDMA_PRL_DONE:
825 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
826 break;
827
chen xu6dac5ab2018-10-26 17:39:23 -0700828 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800829 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700830 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800831 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800832 break;
833
chen xu6dac5ab2018-10-26 17:39:23 -0700834 case EVENT_RESET_MODEM_CONFIG_DONE:
835 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800836 break;
837
Sooraj Sasindran37444802020-08-11 10:40:43 -0700838 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
841 request);
842 Phone phone = getPhoneFromRequest(request);
843 if (phone != null) {
844 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
845 } else {
846 loge("isNRDualConnectivityEnabled: No phone object");
847 request.result = false;
848 notifyRequester(request);
849 }
850 break;
851 }
852
853 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 // request.result must be set to something non-null
860 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700861 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700862 request.result = ar.result;
863 } else {
864 request.result = false;
865 }
866 if (ar.result == null) {
867 loge("isNRDualConnectivityEnabled: Empty response");
868 } else if (ar.exception instanceof CommandException) {
869 loge("isNRDualConnectivityEnabled: CommandException: "
870 + ar.exception);
871 } else {
872 loge("isNRDualConnectivityEnabled: Unknown exception");
873 }
874 }
875 notifyRequester(request);
876 break;
877
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700878 case CMD_IS_VONR_ENABLED: {
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
881 request);
882 Phone phone = getPhoneFromRequest(request);
883 if (phone != null) {
884 phone.isVoNrEnabled(onCompleted, request.workSource);
885 } else {
886 loge("isVoNrEnabled: No phone object");
887 request.result = false;
888 notifyRequester(request);
889 }
890 break;
891 }
892
893 case EVENT_IS_VONR_ENABLED_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
899 // request.result must be set to something non-null
900 // for the calling thread to unblock
901 if (ar.result != null) {
902 request.result = ar.result;
903 } else {
904 request.result = false;
905 }
906 if (ar.result == null) {
907 loge("isVoNrEnabled: Empty response");
908 } else if (ar.exception instanceof CommandException) {
909 loge("isVoNrEnabled: CommandException: "
910 + ar.exception);
911 } else {
912 loge("isVoNrEnabled: Unknown exception");
913 }
914 }
915 notifyRequester(request);
916 break;
917
Sooraj Sasindran37444802020-08-11 10:40:43 -0700918 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
921 Phone phone = getPhoneFromRequest(request);
922 if (phone != null) {
923 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
924 request.workSource);
925 } else {
926 loge("enableNrDualConnectivity: No phone object");
927 request.result =
928 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
929 notifyRequester(request);
930 }
931 break;
932 }
933
934 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 if (ar.exception == null) {
938 request.result =
939 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
940 } else {
941 request.result =
942 TelephonyManager
943 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
944 if (ar.exception instanceof CommandException) {
945 CommandException.Error error =
946 ((CommandException) (ar.exception)).getCommandError();
947 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
948 request.result =
949 TelephonyManager
950 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000951 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
952 request.result =
953 TelephonyManager
954 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700955 }
956 loge("enableNrDualConnectivity" + ": CommandException: "
957 + ar.exception);
958 } else {
959 loge("enableNrDualConnectivity" + ": Unknown exception");
960 }
961 }
962 notifyRequester(request);
963 break;
964 }
965
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700966 case CMD_ENABLE_VONR: {
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
969 Phone phone = getPhoneFromRequest(request);
970 if (phone != null) {
971 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
972 request.workSource);
973 } else {
974 loge("setVoNrEnabled: No phone object");
975 request.result =
976 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
977 notifyRequester(request);
978 }
979 break;
980 }
981
982 case EVENT_ENABLE_VONR_DONE: {
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception == null) {
986 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
987 } else {
988 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
989 if (ar.exception instanceof CommandException) {
990 CommandException.Error error =
991 ((CommandException) (ar.exception)).getCommandError();
992 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
993 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
994 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
995 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
996 } else {
997 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
998 }
999 loge("setVoNrEnabled" + ": CommandException: "
1000 + ar.exception);
1001 } else {
1002 loge("setVoNrEnabled" + ": Unknown exception");
1003 }
1004 }
1005 notifyRequester(request);
1006 break;
1007 }
1008
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1012 request);
1013 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 break;
1015
SongFerngWang3ef3e072020-12-21 16:41:52 +08001016 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception == null && ar.result != null) {
1020 request.result = ar.result; // Integer
1021 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301022 // request.result must be set to something non-null
1023 // for the calling thread to unblock
1024 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001025 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001026 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001028 loge("getAllowedNetworkTypesBitmask: CommandException: "
1029 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001030 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001031 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 }
1033 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001034 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001035 break;
1036
SongFerngWang3ef3e072020-12-21 16:41:52 +08001037 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001038 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001039 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1040 request);
1041 Pair<Integer, Long> reasonWithNetworkTypes =
1042 (Pair<Integer, Long>) request.argument;
1043 getPhoneFromRequest(request).setAllowedNetworkTypes(
1044 reasonWithNetworkTypes.first,
1045 reasonWithNetworkTypes.second,
1046 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001047 break;
1048
SongFerngWang3ef3e072020-12-21 16:41:52 +08001049 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1050 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001051 break;
1052
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001053 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1054 request = (MainThreadRequest)msg.obj;
1055 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001056 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001057 break;
1058
1059 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1060 ar = (AsyncResult)msg.obj;
1061 request = (MainThreadRequest)ar.userObj;
1062 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001063 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001064 break;
1065
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001066 case CMD_SET_VOICEMAIL_NUMBER:
1067 request = (MainThreadRequest) msg.obj;
1068 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1069 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001070 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1071 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001072 break;
1073
1074 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1075 handleNullReturnEvent(msg, "setVoicemailNumber");
1076 break;
1077
Stuart Scott54788802015-03-30 13:18:01 -07001078 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1079 request = (MainThreadRequest) msg.obj;
1080 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1081 request);
1082 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1083 break;
1084
1085 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1086 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1087 break;
1088
Shishir Agrawal302c8692015-06-19 13:49:39 -07001089 case CMD_PERFORM_NETWORK_SCAN:
1090 request = (MainThreadRequest) msg.obj;
1091 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1092 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1093 break;
1094
Hall Liu27d24262020-09-18 19:04:59 -07001095 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001098 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1099 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1100 request.argument;
1101 int callForwardingReason = args.first;
1102 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001103 break;
Hall Liu27d24262020-09-18 19:04:59 -07001104 }
1105 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001106 ar = (AsyncResult) msg.obj;
1107 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001108 TelephonyManager.CallForwardingInfoCallback callback =
1109 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1110 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001111 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001112 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001113 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1114 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1115 // Service Class is a bit mask per 3gpp 27.007. Search for
1116 // any service for voice call.
1117 if ((callForwardInfo.serviceClass
1118 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001119 callForwardingInfo = new CallForwardingInfo(
1120 callForwardInfo.status
1121 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001122 callForwardInfo.reason,
1123 callForwardInfo.number,
1124 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001125 break;
1126 }
1127 }
1128 // Didn't find a call forward info for voice call.
1129 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001130 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1131 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001132 }
Hall Liu27d24262020-09-18 19:04:59 -07001133 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 } else {
1135 if (ar.result == null) {
1136 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1137 }
1138 if (ar.exception != null) {
1139 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1140 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001141 int errorCode = TelephonyManager
1142 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001143 if (ar.exception instanceof CommandException) {
1144 CommandException.Error error =
1145 ((CommandException) (ar.exception)).getCommandError();
1146 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001147 errorCode = TelephonyManager
1148 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001149 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001150 errorCode = TelephonyManager
1151 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001152 }
1153 }
Hall Liu27d24262020-09-18 19:04:59 -07001154 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001155 }
Shuo Qian4a594052020-01-23 11:59:30 -08001156 break;
Hall Liu27d24262020-09-18 19:04:59 -07001157 }
Shuo Qian4a594052020-01-23 11:59:30 -08001158
Hall Liu27d24262020-09-18 19:04:59 -07001159 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001160 request = (MainThreadRequest) msg.obj;
1161 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001162 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001163 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001164 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1165 request.argument).first;
1166 request.phone.setCallForwardingOption(
1167 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001168 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001169 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001170 callForwardingInfoToSet.getReason(),
1171 callForwardingInfoToSet.getNumber(),
1172 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1173 break;
Hall Liu27d24262020-09-18 19:04:59 -07001174 }
Shuo Qian4a594052020-01-23 11:59:30 -08001175
Hall Liu27d24262020-09-18 19:04:59 -07001176 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001177 ar = (AsyncResult) msg.obj;
1178 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001179 Consumer<Integer> callback =
1180 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1181 request.argument).second;
1182 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001184 int errorCode = TelephonyManager.CallForwardingInfoCallback
1185 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001186 if (ar.exception instanceof CommandException) {
1187 CommandException.Error error =
1188 ((CommandException) (ar.exception)).getCommandError();
1189 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001190 errorCode = TelephonyManager.CallForwardingInfoCallback
1191 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001192 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001193 errorCode = TelephonyManager.CallForwardingInfoCallback
1194 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001195 }
1196 }
1197 callback.accept(errorCode);
1198 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001199 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001200 }
Shuo Qian4a594052020-01-23 11:59:30 -08001201 break;
Hall Liu27d24262020-09-18 19:04:59 -07001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203
Hall Liu27d24262020-09-18 19:04:59 -07001204 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1207 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1208 break;
Hall Liu27d24262020-09-18 19:04:59 -07001209 }
Shuo Qian4a594052020-01-23 11:59:30 -08001210
Hall Liu27d24262020-09-18 19:04:59 -07001211 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001214 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001215 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1216 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001217 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 // Service Class is a bit mask per 3gpp 27.007.
1219 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001220 if (callForwardResults.length > 1
1221 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001222 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001223 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001224 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1225 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001227 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 }
1229 } else {
1230 if (ar.result == null) {
1231 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1232 }
1233 if (ar.exception != null) {
1234 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1235 }
1236 if (ar.exception instanceof CommandException) {
1237 CommandException.Error error =
1238 ((CommandException) (ar.exception)).getCommandError();
1239 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1240 callForwardingStatus =
1241 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1242 }
1243 }
1244 }
Hall Liu27d24262020-09-18 19:04:59 -07001245 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 break;
Hall Liu27d24262020-09-18 19:04:59 -07001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248
Hall Liu27d24262020-09-18 19:04:59 -07001249 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001252 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1253 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001254 break;
Hall Liu27d24262020-09-18 19:04:59 -07001255 }
Shuo Qian4a594052020-01-23 11:59:30 -08001256
Hall Liu27d24262020-09-18 19:04:59 -07001257 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001258 ar = (AsyncResult) msg.obj;
1259 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001260 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1261 Consumer<Integer> callback =
1262 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1263 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001264 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001265 if (ar.exception instanceof CommandException) {
1266 CommandException.Error error =
1267 ((CommandException) (ar.exception)).getCommandError();
1268 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1269 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1270 } else {
1271 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1272 }
1273 } else {
1274 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1275 }
1276 } else {
1277 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1278 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280 break;
Hall Liu27d24262020-09-18 19:04:59 -07001281 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001282 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1283 ar = (AsyncResult) msg.obj;
1284 request = (MainThreadRequest) ar.userObj;
1285 CellNetworkScanResult cellScanResult;
1286 if (ar.exception == null && ar.result != null) {
1287 cellScanResult = new CellNetworkScanResult(
1288 CellNetworkScanResult.STATUS_SUCCESS,
1289 (List<OperatorInfo>) ar.result);
1290 } else {
1291 if (ar.result == null) {
1292 loge("getCellNetworkScanResults: Empty response");
1293 }
1294 if (ar.exception != null) {
1295 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1296 }
1297 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1298 if (ar.exception instanceof CommandException) {
1299 CommandException.Error error =
1300 ((CommandException) (ar.exception)).getCommandError();
1301 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1302 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1303 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1304 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1305 }
1306 }
1307 cellScanResult = new CellNetworkScanResult(errorCode, null);
1308 }
1309 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001310 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001311 break;
1312
1313 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1314 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001315 ManualNetworkSelectionArgument selArg =
1316 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001317 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1318 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001319 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1320 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001321 break;
1322
1323 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001324 ar = (AsyncResult) msg.obj;
1325 request = (MainThreadRequest) ar.userObj;
1326 if (ar.exception == null) {
1327 request.result = true;
1328 } else {
1329 request.result = false;
1330 loge("setNetworkSelectionModeManual " + ar.exception);
1331 }
1332 notifyRequester(request);
1333 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001334 break;
1335
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001336 case CMD_GET_MODEM_ACTIVITY_INFO:
1337 request = (MainThreadRequest) msg.obj;
1338 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001339 if (defaultPhone != null) {
1340 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 } else {
1342 ResultReceiver result = (ResultReceiver) request.argument;
1343 Bundle bundle = new Bundle();
1344 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001345 new ModemActivityInfo(0, 0, 0,
1346 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001347 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001348 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001349 break;
1350
Hall Liud0f208c2020-10-14 16:54:44 -07001351 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001354 ResultReceiver result = (ResultReceiver) request.argument;
1355
Hall Liud0f208c2020-10-14 16:54:44 -07001356 ModemActivityInfo ret = null;
1357 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001358 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001359 // Update the last modem activity info and the result of the request.
1360 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1361 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001362 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001363 int[] txTimeMs = info.getTransmitTimeMillis();
1364 int[] lastModemTxTimeMs = mLastModemActivityInfo
1365 .getTransmitTimeMillis();
1366 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1367 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1368 }
Hall Liu49656c02020-10-09 19:00:11 -07001369 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001370 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1371 + mLastModemActivityInfo.getSleepTimeMillis());
1372 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1373 + mLastModemActivityInfo.getIdleTimeMillis());
1374 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1375 mLastModemActivityInfo.setReceiveTimeMillis(
1376 info.getReceiveTimeMillis()
1377 + mLastModemActivityInfo.getReceiveTimeMillis());
1378 }
Hall Liu49656c02020-10-09 19:00:11 -07001379 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001380 mLastModemActivityInfo.getSleepTimeMillis(),
1381 mLastModemActivityInfo.getIdleTimeMillis(),
1382 mLastModemActivityInfo.getTransmitTimeMillis(),
1383 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001384 } else {
1385 if (ar.result == null) {
1386 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001387 error = TelephonyManager.ModemActivityInfoException
1388 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 } else if (ar.exception instanceof CommandException) {
1390 loge("queryModemActivityInfo: CommandException: " +
1391 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001392 error = TelephonyManager.ModemActivityInfoException
1393 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001394 } else {
1395 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001396 error = TelephonyManager.ModemActivityInfoException
1397 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 }
1399 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001400 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001401 if (ret != null) {
1402 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1403 } else {
1404 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1405 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001406 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001407 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001408 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001409 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410
Meng Wang1a7c35a2016-05-05 20:56:15 -07001411 case CMD_SET_ALLOWED_CARRIERS:
1412 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001413 CarrierRestrictionRules argument =
1414 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001415 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001416 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 break;
1418
1419 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception == null && ar.result != null) {
1423 request.result = ar.result;
1424 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001425 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1426 if (ar.exception instanceof CommandException) {
1427 loge("setAllowedCarriers: CommandException: " + ar.exception);
1428 CommandException.Error error =
1429 ((CommandException) (ar.exception)).getCommandError();
1430 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1431 request.result =
1432 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1433 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001434 } else {
1435 loge("setAllowedCarriers: Unknown exception");
1436 }
1437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001438 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001439 break;
1440
1441 case CMD_GET_ALLOWED_CARRIERS:
1442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001444 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001445 break;
1446
1447 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001453 request.result = new IllegalStateException(
1454 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001455 if (ar.result == null) {
1456 loge("getAllowedCarriers: Empty response");
1457 } else if (ar.exception instanceof CommandException) {
1458 loge("getAllowedCarriers: CommandException: " +
1459 ar.exception);
1460 } else {
1461 loge("getAllowedCarriers: Unknown exception");
1462 }
1463 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001464 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001465 break;
1466
Nathan Haroldb3014052017-01-25 15:57:32 -08001467 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 if (ar.exception == null && ar.result != null) {
1471 request.result = ar.result;
1472 } else {
1473 request.result = new IllegalArgumentException(
1474 "Failed to retrieve Forbidden Plmns");
1475 if (ar.result == null) {
1476 loge("getForbiddenPlmns: Empty response");
1477 } else {
1478 loge("getForbiddenPlmns: Unknown exception");
1479 }
1480 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001481 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001482 break;
1483
1484 case CMD_GET_FORBIDDEN_PLMNS:
1485 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001486 uiccPort = getUiccPortFromRequest(request);
1487 if (uiccPort == null) {
1488 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001489 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001490 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001491 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001492 break;
1493 }
1494 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001495 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001496 if (uiccApp == null) {
1497 loge("getForbiddenPlmns() no app with specified type -- "
1498 + appType);
1499 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001501 break;
1502 } else {
1503 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1504 + " specified type -- " + appType);
1505 }
1506 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1507 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1508 onCompleted);
1509 break;
1510
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001511 case CMD_SWITCH_SLOTS:
1512 request = (MainThreadRequest) msg.obj;
1513 int[] physicalSlots = (int[]) request.argument;
1514 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1515 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1516 break;
1517
1518 case EVENT_SWITCH_SLOTS_DONE:
1519 ar = (AsyncResult) msg.obj;
1520 request = (MainThreadRequest) ar.userObj;
1521 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
1523 break;
1524 case CMD_GET_NETWORK_SELECTION_MODE:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1527 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1528 break;
1529
1530 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception != null) {
1534 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1535 } else {
1536 int mode = ((int[]) ar.result)[0];
1537 if (mode == 0) {
1538 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1539 } else {
1540 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1541 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001543 notifyRequester(request);
1544 break;
1545 case CMD_GET_CDMA_ROAMING_MODE:
1546 request = (MainThreadRequest) msg.obj;
1547 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1548 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1549 break;
1550 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 if (ar.exception != null) {
1554 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1555 } else {
1556 request.result = ((int[]) ar.result)[0];
1557 }
1558 notifyRequester(request);
1559 break;
1560 case CMD_SET_CDMA_ROAMING_MODE:
1561 request = (MainThreadRequest) msg.obj;
1562 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1563 int mode = (int) request.argument;
1564 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1565 break;
1566 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1567 ar = (AsyncResult) msg.obj;
1568 request = (MainThreadRequest) ar.userObj;
1569 request.result = ar.exception == null;
1570 notifyRequester(request);
1571 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001572 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1573 request = (MainThreadRequest) msg.obj;
1574 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1575 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1576 break;
1577 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 if (ar.exception != null) {
1581 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1582 } else {
1583 request.result = ((int[]) ar.result)[0];
1584 }
1585 notifyRequester(request);
1586 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001587 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1588 request = (MainThreadRequest) msg.obj;
1589 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1590 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001591 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1592 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001593 break;
1594 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
1597 request.result = ar.exception == null;
1598 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001599 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001600 case CMD_GET_ALL_CELL_INFO:
1601 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001602 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001603 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001605 case EVENT_GET_ALL_CELL_INFO_DONE:
1606 ar = (AsyncResult) msg.obj;
1607 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001608 // If a timeout occurs, the response will be null
1609 request.result = (ar.exception == null && ar.result != null)
1610 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001611 synchronized (request) {
1612 request.notifyAll();
1613 }
1614 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001615 case CMD_REQUEST_CELL_INFO_UPDATE:
1616 request = (MainThreadRequest) msg.obj;
1617 request.phone.requestCellInfoUpdate(request.workSource,
1618 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1619 break;
1620 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1624 try {
1625 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001626 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001627 cb.onError(
1628 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1629 ar.exception.getClass().getName(),
1630 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001631 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001632 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001633 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001634 } else {
1635 // use the result as returned
1636 cb.onCellInfo((List<CellInfo>) ar.result);
1637 }
1638 } catch (RemoteException re) {
1639 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1640 }
1641 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001642 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001643 request = (MainThreadRequest) msg.obj;
1644 WorkSource ws = (WorkSource) request.argument;
1645 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001646 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001647 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001648 }
1649 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001650 ar = (AsyncResult) msg.obj;
1651 request = (MainThreadRequest) ar.userObj;
1652 if (ar.exception == null) {
1653 request.result = ar.result;
1654 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001655 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001656 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001657 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 }
1659
1660 synchronized (request) {
1661 request.notifyAll();
1662 }
1663 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001664 }
chen xu6dac5ab2018-10-26 17:39:23 -07001665 case CMD_MODEM_REBOOT:
1666 request = (MainThreadRequest) msg.obj;
1667 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001668 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001669 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001670 case EVENT_CMD_MODEM_REBOOT_DONE:
1671 handleNullReturnEvent(msg, "rebootModem");
1672 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001673 case CMD_REQUEST_ENABLE_MODEM:
1674 request = (MainThreadRequest) msg.obj;
1675 boolean enable = (boolean) request.argument;
1676 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001677 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001678 PhoneConfigurationManager.getInstance()
1679 .enablePhone(request.phone, enable, onCompleted);
1680 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001681 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001685 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001686 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001687 if ((boolean) request.result) {
1688 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1689 updateModemStateMetrics();
1690 } else {
1691 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1692 + ar.exception);
1693 }
1694 notifyRequester(request);
1695 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001696 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001697 case CMD_GET_MODEM_STATUS:
1698 request = (MainThreadRequest) msg.obj;
1699 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1700 PhoneConfigurationManager.getInstance()
1701 .getPhoneStatusFromModem(request.phone, onCompleted);
1702 break;
1703 case EVENT_GET_MODEM_STATUS_DONE:
1704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 int id = request.phone.getPhoneId();
1707 if (ar.exception == null && ar.result != null) {
1708 request.result = ar.result;
1709 //update the cache as modem status has changed
1710 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1711 (boolean) request.result);
1712 } else {
1713 // Return true if modem status cannot be retrieved. For most cases,
1714 // modem status is on. And for older version modems, GET_MODEM_STATUS
1715 // and disable modem are not supported. Modem is always on.
1716 // TODO: this should be fixed in R to support a third
1717 // status UNKNOWN b/131631629
1718 request.result = true;
1719 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1720 + ar.exception);
1721 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001722 notifyRequester(request);
1723 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001724 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1727 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1728 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1729 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1730 break;
1731 }
1732 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1736 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1737 args.second.accept(ar.exception == null);
1738 notifyRequester(request);
1739 break;
1740 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001741 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1742 request = (MainThreadRequest) msg.obj;
1743 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1744 Phone phone = getPhoneFromRequest(request);
1745 if (phone != null) {
1746 phone.getSystemSelectionChannels(onCompleted);
1747 } else {
1748 loge("getSystemSelectionChannels: No phone object");
1749 request.result = new ArrayList<RadioAccessSpecifier>();
1750 notifyRequester(request);
1751 }
1752 break;
1753 }
1754 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757 if (ar.exception == null && ar.result != null) {
1758 request.result = ar.result;
1759 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001760 request.result = new IllegalStateException(
1761 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001762 if (ar.result == null) {
1763 loge("getSystemSelectionChannels: Empty response");
1764 } else {
1765 loge("getSystemSelectionChannels: Unknown exception");
1766 }
1767 }
1768 notifyRequester(request);
1769 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001770 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 if (ar.exception == null && ar.result != null) {
1774 request.result = ar.result;
1775 } else {
1776 request.result = -1;
1777 loge("Failed to set Forbidden Plmns");
1778 if (ar.result == null) {
1779 loge("setForbidenPlmns: Empty response");
1780 } else if (ar.exception != null) {
1781 loge("setForbiddenPlmns: Exception: " + ar.exception);
1782 request.result = -1;
1783 } else {
1784 loge("setForbiddenPlmns: Unknown exception");
1785 }
1786 }
1787 notifyRequester(request);
1788 break;
1789 case CMD_SET_FORBIDDEN_PLMNS:
1790 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001791 uiccPort = getUiccPortFromRequest(request);
1792 if (uiccPort == null) {
1793 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001794 request.result = -1;
1795 notifyRequester(request);
1796 break;
1797 }
1798 Pair<Integer, List<String>> setFplmnsArgs =
1799 (Pair<Integer, List<String>>) request.argument;
1800 appType = setFplmnsArgs.first;
1801 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001802 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001803 if (uiccApp == null) {
1804 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1805 request.result = -1;
1806 loge("Failed to get UICC App");
1807 notifyRequester(request);
1808 } else {
1809 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1810 ((SIMRecords) uiccApp.getIccRecords())
1811 .setForbiddenPlmns(onCompleted, fplmns);
1812 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001813 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001814 case CMD_ERASE_MODEM_CONFIG:
1815 request = (MainThreadRequest) msg.obj;
1816 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1817 defaultPhone.eraseModemConfig(onCompleted);
1818 break;
1819 case EVENT_ERASE_MODEM_CONFIG_DONE:
1820 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001821 break;
zoey chene02881a2019-12-30 16:11:23 +08001822
Kai Shif70f46f2021-03-03 13:59:46 -08001823 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1824 request = (MainThreadRequest) msg.obj;
1825 request.result = defaultPhone.eraseDataInSharedPreferences();
1826 notifyRequester(request);
1827 break;
1828
zoey chene02881a2019-12-30 16:11:23 +08001829 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1832 Pair<String, String> changed = (Pair<String, String>) request.argument;
1833 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1834 changed.first, changed.second, onCompleted);
1835 break;
1836 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 if (ar.exception == null) {
1840 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001841 // If the operation is successful, update the PIN storage
1842 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1843 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001844 UiccController.getInstance().getPinStorage()
1845 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001846 } else {
1847 request.result = msg.arg1;
1848 }
1849 notifyRequester(request);
1850 break;
1851
Michele Berionne5e411512020-11-13 02:36:59 +00001852 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001853 request = (MainThreadRequest) msg.obj;
1854 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1855 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1856 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1857 enabled.first, enabled.second, onCompleted);
1858 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001859 }
zoey chene02881a2019-12-30 16:11:23 +08001860 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1861 ar = (AsyncResult) msg.obj;
1862 request = (MainThreadRequest) ar.userObj;
1863 if (ar.exception == null) {
1864 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001865 // If the operation is successful, update the PIN storage
1866 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1867 int phoneId = getPhoneFromRequest(request).getPhoneId();
1868 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001869 UiccController.getInstance().getPinStorage()
1870 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001871 } else {
1872 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1873 }
zoey chene02881a2019-12-30 16:11:23 +08001874 } else {
1875 request.result = msg.arg1;
1876 }
Michele Berionne5e411512020-11-13 02:36:59 +00001877
1878
zoey chene02881a2019-12-30 16:11:23 +08001879 notifyRequester(request);
1880 break;
1881
Peter Wangdafb9ac2020-01-15 14:13:38 -08001882 case MSG_NOTIFY_USER_ACTIVITY:
1883 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001884 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001885 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1886 getDefaultPhone().getContext().sendBroadcastAsUser(
1887 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1888 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001889
1890 case CMD_SET_DATA_THROTTLING: {
1891 request = (MainThreadRequest) msg.obj;
1892 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1893 DataThrottlingRequest dataThrottlingRequest =
1894 (DataThrottlingRequest) request.argument;
1895 Phone phone = getPhoneFromRequest(request);
1896 if (phone != null) {
1897 phone.setDataThrottling(onCompleted,
1898 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1899 dataThrottlingRequest.getCompletionDurationMillis());
1900 } else {
1901 loge("setDataThrottling: No phone object");
1902 request.result =
1903 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1904 notifyRequester(request);
1905 }
1906
1907 break;
1908 }
1909 case EVENT_SET_DATA_THROTTLING_DONE:
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912
1913 if (ar.exception == null) {
1914 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1915 } else if (ar.exception instanceof CommandException) {
1916 loge("setDataThrottling: CommandException: " + ar.exception);
1917 CommandException.Error error =
1918 ((CommandException) (ar.exception)).getCommandError();
1919
1920 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1921 request.result = TelephonyManager
1922 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1923 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1924 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001925 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1926 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001927 } else {
1928 request.result =
1929 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1930 }
1931 } else {
1932 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1933 }
1934 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1935 notifyRequester(request);
1936 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001937
1938 case CMD_SET_SIM_POWER: {
1939 request = (MainThreadRequest) msg.obj;
1940 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1941 request = (MainThreadRequest) msg.obj;
1942 int stateToSet =
1943 ((Pair<Integer, IIntegerConsumer>)
1944 request.argument).first;
1945 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1946 break;
1947 }
1948 case EVENT_SET_SIM_POWER_DONE: {
1949 ar = (AsyncResult) msg.obj;
1950 request = (MainThreadRequest) ar.userObj;
1951 IIntegerConsumer callback =
1952 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1953 if (ar.exception != null) {
1954 loge("setSimPower exception: " + ar.exception);
1955 int errorCode = TelephonyManager.CallForwardingInfoCallback
1956 .RESULT_ERROR_UNKNOWN;
1957 if (ar.exception instanceof CommandException) {
1958 CommandException.Error error =
1959 ((CommandException) (ar.exception)).getCommandError();
1960 if (error == CommandException.Error.SIM_ERR) {
1961 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1962 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1963 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1964 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1965 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1966 } else {
1967 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1968 }
1969 }
1970 try {
1971 callback.accept(errorCode);
1972 } catch (RemoteException e) {
1973 // Ignore if the remote process is no longer available to call back.
1974 Log.w(LOG_TAG, "setSimPower: callback not available.");
1975 }
1976 } else {
1977 try {
1978 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1979 } catch (RemoteException e) {
1980 // Ignore if the remote process is no longer available to call back.
1981 Log.w(LOG_TAG, "setSimPower: callback not available.");
1982 }
1983 }
1984 break;
1985 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001986 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1987 request = (MainThreadRequest) msg.obj;
1988
1989 final Phone phone = getPhoneFromRequest(request);
1990 if (phone == null || phone.getServiceStateTracker() == null) {
1991 request.result = new IllegalStateException("Phone or SST is null");
1992 notifyRequester(request);
1993 break;
1994 }
1995
1996 Pair<Integer, SignalStrengthUpdateRequest> pair =
1997 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1998 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1999 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002000 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002001 request.subId, pair.first /*callingUid*/,
2002 pair.second /*request*/, onCompleted);
2003 break;
2004 }
2005 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2006 ar = (AsyncResult) msg.obj;
2007 request = (MainThreadRequest) ar.userObj;
2008 // request.result will be the exception of ar if present, true otherwise.
2009 // Be cautious not to leave result null which will wait() forever
2010 request.result = ar.exception != null ? ar.exception : true;
2011 notifyRequester(request);
2012 break;
2013 }
2014 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2015 request = (MainThreadRequest) msg.obj;
2016
2017 Phone phone = getPhoneFromRequest(request);
2018 if (phone == null || phone.getServiceStateTracker() == null) {
2019 request.result = new IllegalStateException("Phone or SST is null");
2020 notifyRequester(request);
2021 break;
2022 }
2023
2024 Pair<Integer, SignalStrengthUpdateRequest> pair =
2025 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2026 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2027 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002028 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002029 request.subId, pair.first /*callingUid*/,
2030 pair.second /*request*/, onCompleted);
2031 break;
2032 }
2033 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2034 ar = (AsyncResult) msg.obj;
2035 request = (MainThreadRequest) ar.userObj;
2036 request.result = ar.exception != null ? ar.exception : true;
2037 notifyRequester(request);
2038 break;
2039 }
Jordan Liu109698e2020-11-24 14:50:34 -08002040
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002041 case CMD_GET_SLICING_CONFIG: {
2042 request = (MainThreadRequest) msg.obj;
2043 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2044 request.phone.getSlicingConfig(onCompleted);
2045 break;
2046 }
2047 case EVENT_GET_SLICING_CONFIG_DONE: {
2048 ar = (AsyncResult) msg.obj;
2049 request = (MainThreadRequest) ar.userObj;
2050 ResultReceiver result = (ResultReceiver) request.argument;
2051
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002052 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002053 Bundle bundle = new Bundle();
2054 int resultCode = 0;
2055 if (ar.exception != null) {
2056 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2057 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002058 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002059 } else if (ar.result == null) {
2060 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002061 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002062 } else {
2063 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002064 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2065 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002066 }
2067
2068 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002069 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002070 }
2071 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2072 result.send(resultCode, bundle);
2073 notifyRequester(request);
2074 break;
2075 }
2076
Michele Berionne5e411512020-11-13 02:36:59 +00002077 case CMD_PREPARE_UNATTENDED_REBOOT:
2078 request = (MainThreadRequest) msg.obj;
2079 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002080 UiccController.getInstance().getPinStorage()
2081 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002082 notifyRequester(request);
2083 break;
2084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 default:
2086 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2087 break;
2088 }
2089 }
Jake Hambye994d462014-02-03 13:10:13 -08002090
Pengquan Menga1bb6272018-09-06 09:59:22 -07002091 private void notifyRequester(MainThreadRequest request) {
2092 synchronized (request) {
2093 request.notifyAll();
2094 }
2095 }
2096
Jake Hambye994d462014-02-03 13:10:13 -08002097 private void handleNullReturnEvent(Message msg, String command) {
2098 AsyncResult ar = (AsyncResult) msg.obj;
2099 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2100 if (ar.exception == null) {
2101 request.result = true;
2102 } else {
2103 request.result = false;
2104 if (ar.exception instanceof CommandException) {
2105 loge(command + ": CommandException: " + ar.exception);
2106 } else {
2107 loge(command + ": Unknown exception");
2108 }
2109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002110 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
2114 /**
2115 * Posts the specified command to be executed on the main thread,
2116 * waits for the request to complete, and returns the result.
2117 * @see #sendRequestAsync
2118 */
2119 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002120 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2121 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002122 }
2123
2124 /**
2125 * Posts the specified command to be executed on the main thread,
2126 * waits for the request to complete, and returns the result.
2127 * @see #sendRequestAsync
2128 */
2129 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2130 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002131 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002132 }
2133
2134 /**
2135 * Posts the specified command to be executed on the main thread,
2136 * waits for the request to complete, and returns the result.
2137 * @see #sendRequestAsync
2138 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002139 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002140 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2141 }
2142
2143 /**
2144 * Posts the specified command to be executed on the main thread,
2145 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2146 * if not timeout or null otherwise.
2147 * @see #sendRequestAsync
2148 */
2149 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2150 long timeoutInMs) {
2151 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002152 }
2153
2154 /**
2155 * Posts the specified command to be executed on the main thread,
2156 * waits for the request to complete, and returns the result.
2157 * @see #sendRequestAsync
2158 */
Nathan Harold92bed182018-10-12 18:16:49 -07002159 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002160 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002161 }
2162
2163 /**
2164 * Posts the specified command to be executed on the main thread,
2165 * waits for the request to complete, and returns the result.
2166 * @see #sendRequestAsync
2167 */
2168 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002169 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2170 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002171 }
2172
2173 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002174 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2175 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2176 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002177 * @see #sendRequestAsync
2178 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2180 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2182 throw new RuntimeException("This method will deadlock if called from the main thread.");
2183 }
2184
Nathan Harold92bed182018-10-12 18:16:49 -07002185 MainThreadRequest request = null;
2186 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2187 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2188 } else if (phone != null) {
2189 request = new MainThreadRequest(argument, phone, workSource);
2190 } else {
2191 request = new MainThreadRequest(argument, subId, workSource);
2192 }
2193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 Message msg = mMainThreadHandler.obtainMessage(command, request);
2195 msg.sendToTarget();
2196
Rambo Wang0f050d82021-02-12 11:43:36 -08002197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002199 if (timeoutInMs >= 0) {
2200 // Wait for at least timeoutInMs before returning null request result
2201 long now = SystemClock.elapsedRealtime();
2202 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002203 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002204 try {
2205 request.wait(deadline - now);
2206 } catch (InterruptedException e) {
2207 // Do nothing, go back and check if request is completed or timeout
2208 } finally {
2209 now = SystemClock.elapsedRealtime();
2210 }
2211 }
2212 } else {
2213 // Wait for the request to complete
2214 while (request.result == null) {
2215 try {
2216 request.wait();
2217 } catch (InterruptedException e) {
2218 // Do nothing, go back and wait until the request is complete
2219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002223 if (request.result == null) {
2224 Log.wtf(LOG_TAG,
2225 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 return request.result;
2228 }
2229
2230 /**
2231 * Asynchronous ("fire and forget") version of sendRequest():
2232 * Posts the specified command to be executed on the main thread, and
2233 * returns immediately.
2234 * @see #sendRequest
2235 */
2236 private void sendRequestAsync(int command) {
2237 mMainThreadHandler.sendEmptyMessage(command);
2238 }
2239
2240 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002242 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002243 */
2244 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 sendRequestAsync(command, argument, null, null);
2246 }
2247
2248 /**
2249 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2250 * @see {@link #sendRequest(int,Object)}
2251 */
2252 private void sendRequestAsync(
2253 int command, Object argument, Phone phone, WorkSource workSource) {
2254 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002255 Message msg = mMainThreadHandler.obtainMessage(command, request);
2256 msg.sendToTarget();
2257 }
2258
2259 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 * Initialize the singleton PhoneInterfaceManager instance.
2261 * This is only done once, at startup, from PhoneApp.onCreate().
2262 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 synchronized (PhoneInterfaceManager.class) {
2265 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002266 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 } else {
2268 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2269 }
2270 return sInstance;
2271 }
2272 }
2273
2274 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002275 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002278 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002279 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002281 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002283 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002284 mTelephonySharedPreferences =
2285 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002286 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002287 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002288 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002289 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 publish();
2292 }
2293
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002294 private Phone getDefaultPhone() {
2295 Phone thePhone = getPhone(getDefaultSubscription());
2296 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2297 }
2298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 private void publish() {
2300 if (DBG) log("publish: " + this);
2301
Peter Wangc035ce42020-01-08 21:00:22 -08002302 TelephonyFrameworkInitializer
2303 .getTelephonyServiceManager()
2304 .getTelephonyServiceRegisterer()
2305 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
Stuart Scott584921c2015-01-15 17:10:34 -08002308 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002309 if (request.phone != null) {
2310 return request.phone;
2311 } else {
2312 return getPhoneFromSubId(request.subId);
2313 }
2314 }
2315
2316 private Phone getPhoneFromSubId(int subId) {
2317 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2318 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002319 }
2320
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002321 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002322 Phone phone = getPhoneFromRequest(request);
2323 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002324 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002325 }
2326
Wink Saville36469e72014-06-11 15:17:00 -07002327 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002329 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331
Kai Shif70f46f2021-03-03 13:59:46 -08002332 private void sendEraseModemConfig(@NonNull Phone phone) {
2333 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2334 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2335 }
2336
2337 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2338 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2339 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002340 }
2341
Peter Wang44b186e2020-01-13 23:33:09 -08002342 private boolean isImsAvailableOnDevice() {
2343 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2344 if (pm == null) {
2345 // For some reason package manger is not available.. This will fail internally anyway,
2346 // so do not throw error and allow.
2347 return true;
2348 }
2349 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2350 }
2351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002353 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002354 }
2355
Wink Savilleb564aae2014-10-23 10:18:09 -07002356 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 if (DBG) log("dial: " + number);
2358 // No permission check needed here: This is just a wrapper around the
2359 // ACTION_DIAL intent, which is available to any app since it puts up
2360 // the UI before it does anything.
2361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 String url = createTelUrl(number);
2365 if (url == null) {
2366 return;
2367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 // PENDING: should we just silently fail if phone is offhook or ringing?
2370 PhoneConstants.State state = mCM.getState(subId);
2371 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2372 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2373 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2374 mApp.startActivity(intent);
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379 }
2380
2381 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002382 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
2384
Wink Savilleb564aae2014-10-23 10:18:09 -07002385 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 if (DBG) log("call: " + number);
2387
2388 // This is just a wrapper around the ACTION_CALL intent, but we still
2389 // need to do a permission check since we're calling startActivity()
2390 // from the context of the phone app.
2391 enforceCallPermission();
2392
Jordan Liu1617b712019-07-10 15:06:26 -07002393 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 != AppOpsManager.MODE_ALLOWED) {
2395 return;
2396 }
2397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 String url = createTelUrl(number);
2401 if (url == null) {
2402 return;
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002405 boolean isValid = false;
2406 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2407 if (slist != null) {
2408 for (SubscriptionInfo subInfoRecord : slist) {
2409 if (subInfoRecord.getSubscriptionId() == subId) {
2410 isValid = true;
2411 break;
2412 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002413 }
Wink Saville08874612014-08-31 19:19:58 -07002414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 if (!isValid) {
2416 return;
2417 }
Wink Saville08874612014-08-31 19:19:58 -07002418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2420 intent.putExtra(SUBSCRIPTION_KEY, subId);
2421 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2422 mApp.startActivity(intent);
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427
Wink Savilleb564aae2014-10-23 10:18:09 -07002428 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002429 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002430 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002434 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002435 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2436 }
2437
Wink Savilleb564aae2014-10-23 10:18:09 -07002438 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002443 Phone phone = getPhone(subId);
2444 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 checkSimPin.start();
2446 return checkSimPin.unlockSim(null, pin);
2447 } finally {
2448 Binder.restoreCallingIdentity(identity);
2449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 }
2451
Wink Savilleb564aae2014-10-23 10:18:09 -07002452 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454
2455 final long identity = Binder.clearCallingIdentity();
2456 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002457 Phone phone = getPhone(subId);
2458 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 checkSimPuk.start();
2460 return checkSimPuk.unlockSim(puk, pin);
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
2463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
2466 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002467 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 * a synchronous one.
2469 */
2470 private static class UnlockSim extends Thread {
2471
2472 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002473 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474
2475 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002476 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2477 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478
2479 // For replies from SimCard interface
2480 private Handler mHandler;
2481
2482 // For async handler to identify request type
2483 private static final int SUPPLY_PIN_COMPLETE = 100;
2484
Michele Berionne5e411512020-11-13 02:36:59 +00002485 UnlockSim(int phoneId, IccCard simCard) {
2486 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 mSimCard = simCard;
2488 }
2489
2490 @Override
2491 public void run() {
2492 Looper.prepare();
2493 synchronized (UnlockSim.this) {
2494 mHandler = new Handler() {
2495 @Override
2496 public void handleMessage(Message msg) {
2497 AsyncResult ar = (AsyncResult) msg.obj;
2498 switch (msg.what) {
2499 case SUPPLY_PIN_COMPLETE:
2500 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2501 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002502 mRetryCount = msg.arg1;
2503 if (ar.exception != null) {
2504 if (ar.exception instanceof CommandException &&
2505 ((CommandException)(ar.exception)).getCommandError()
2506 == CommandException.Error.PASSWORD_INCORRECT) {
2507 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002508 } //When UiccCardApp dispose,handle message and return exception
2509 else if (ar.exception instanceof CommandException &&
2510 ((CommandException) (ar.exception)).getCommandError()
2511 == CommandException.Error.ABORTED) {
2512 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002513 } else {
2514 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2515 }
2516 } else {
2517 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 mDone = true;
2520 UnlockSim.this.notifyAll();
2521 }
2522 break;
2523 }
2524 }
2525 };
2526 UnlockSim.this.notifyAll();
2527 }
2528 Looper.loop();
2529 }
2530
2531 /*
2532 * Use PIN or PUK to unlock SIM card
2533 *
2534 * If PUK is null, unlock SIM card with PIN
2535 *
2536 * If PUK is not null, unlock SIM card with PUK and set PIN code
2537 */
Wink Saville9de0f752013-10-22 19:04:03 -07002538 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
2540 while (mHandler == null) {
2541 try {
2542 wait();
2543 } catch (InterruptedException e) {
2544 Thread.currentThread().interrupt();
2545 }
2546 }
2547 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2548
2549 if (puk == null) {
2550 mSimCard.supplyPin(pin, callback);
2551 } else {
2552 mSimCard.supplyPuk(puk, pin, callback);
2553 }
2554
2555 while (!mDone) {
2556 try {
2557 Log.d(LOG_TAG, "wait for done");
2558 wait();
2559 } catch (InterruptedException e) {
2560 // Restore the interrupted status
2561 Thread.currentThread().interrupt();
2562 }
2563 }
2564 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002565 int[] resultArray = new int[2];
2566 resultArray[0] = mResult;
2567 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002568
2569 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002570 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002571 }
2572
Wink Saville9de0f752013-10-22 19:04:03 -07002573 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575 }
2576
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002577 /**
2578 * This method has been removed due to privacy and stability concerns.
2579 */
2580 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002582 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2583 return;
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Nathan Harold1f889d82020-06-04 17:05:26 -07002586 @Override
2587 public void updateServiceLocationWithPackageName(String callingPackage) {
2588 mApp.getSystemService(AppOpsManager.class)
2589 .checkPackage(Binder.getCallingUid(), callingPackage);
2590
Nathan Haroldf096d982020-11-18 17:18:06 -08002591 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002592 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2593 // Callers targeting S have no business invoking this method.
2594 return;
2595 }
2596
2597 LocationAccessPolicy.LocationPermissionResult locationResult =
2598 LocationAccessPolicy.checkLocationPermission(mApp,
2599 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2600 .setCallingPackage(callingPackage)
2601 .setCallingFeatureId(null)
2602 .setCallingPid(Binder.getCallingPid())
2603 .setCallingUid(Binder.getCallingUid())
2604 .setMethod("updateServiceLocation")
2605 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2606 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2607 .build());
2608 // Apps that lack location permission have no business calling this method;
2609 // however, because no permission was declared in the public API, denials must
2610 // all be "soft".
2611 switch (locationResult) {
2612 case DENIED_HARD: /* fall through */
2613 case DENIED_SOFT:
2614 return;
2615 }
2616
2617 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002620 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002622 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 @Override
2631 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 return isRadioOnWithFeature(callingPackage, null);
2633 }
2634
2635
2636 @Override
2637 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2638 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2639 callingFeatureId);
2640 }
2641
2642 @Deprecated
2643 @Override
2644 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2645 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002649 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2650 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002652 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 return false;
2654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 return isRadioOnForSubscriber(subId);
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002662 }
2663
2664 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
2669 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2670 } else {
2671 return false;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
2678 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
Wink Saville36469e72014-06-11 15:17:00 -07002681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 final Phone phone = getPhone(subId);
2688 if (phone != null) {
2689 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Wink Saville36469e72014-06-11 15:17:00 -07002694 }
2695
2696 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002697 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 if (phone == null) {
2707 return false;
2708 }
2709 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2710 toggleRadioOnOffForSubscriber(subId);
2711 }
2712 return true;
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
Wink Saville36469e72014-06-11 15:17:00 -07002717
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002719 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 /*
2721 * If any of the Radios are available, it will need to be
2722 * shutdown. So return true if any Radio is available.
2723 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2727 Phone phone = PhoneFactory.getPhone(i);
2728 if (phone != null && phone.isRadioAvailable()) return true;
2729 }
2730 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2731 return false;
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002734 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 }
2736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002738 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 enforceModifyPermission();
2740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2744 logv("Shutting down Phone " + i);
2745 shutdownRadioUsingPhoneId(i);
2746 }
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002749 }
2750 }
2751
2752 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002753 Phone phone = PhoneFactory.getPhone(phoneId);
2754 if (phone != null && phone.isRadioAvailable()) {
2755 phone.shutdownRadio();
2756 }
2757 }
2758
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2765 if (defaultPhone != null) {
2766 defaultPhone.setRadioPower(turnOn);
2767 return true;
2768 } else {
2769 loge("There's no default phone.");
2770 return false;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002774 }
Wink Saville36469e72014-06-11 15:17:00 -07002775 }
2776
Wink Savilleb564aae2014-10-23 10:18:09 -07002777 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(subId);
2783 if (phone != null) {
2784 phone.setRadioPower(turnOn);
2785 return true;
2786 } else {
2787 return false;
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Wink Saville36469e72014-06-11 15:17:00 -07002794 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 public boolean enableDataConnectivity() {
2797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 int subId = mSubscriptionController.getDefaultDataSubId();
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002804 phone.getDataEnabledSettings().setDataEnabled(
2805 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 return true;
2807 } else {
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
2814
Wink Saville36469e72014-06-11 15:17:00 -07002815 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 public boolean disableDataConnectivity() {
2818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 int subId = mSubscriptionController.getDefaultDataSubId();
2823 final Phone phone = getPhone(subId);
2824 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002825 phone.getDataEnabledSettings().setDataEnabled(
2826 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 return true;
2828 } else {
2829 return false;
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 }
2835
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002837 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 final Phone phone = getPhone(subId);
2841 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002842 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843 } else {
2844 return false;
2845 }
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 }
2850
2851 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002852 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002853 }
2854
pkanwarae03a6b2016-11-06 20:37:09 -08002855 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 enforceCallPermission();
2857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2861 return;
2862 }
2863 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2864 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
pkanwar32d516d2016-10-14 19:37:38 -07002868 };
2869
Wink Savilleb564aae2014-10-23 10:18:09 -07002870 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2876 return false;
2877 }
2878 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002884 /**
2885 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2886 * tag on getCallState Binder call.
2887 */
2888 @Deprecated
2889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002891 if (CompatChanges.isChangeEnabled(
2892 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2893 Binder.getCallingUid())) {
2894 // Do not allow this API to be called on API version 31+, it should only be
2895 // called on old apps using this Binder call directly.
2896 throw new SecurityException("This method can only be used for applications "
2897 + "targeting API version 30 or less.");
2898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 final long identity = Binder.clearCallingIdentity();
2900 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002901 Phone phone = getPhone(getDefaultSubscription());
2902 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2903 PhoneConstantConversions.convertCallState(phone.getState());
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 }
2908
2909 @Override
2910 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2911 if (CompatChanges.isChangeEnabled(
2912 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2913 Binder.getCallingUid())) {
2914 // Check READ_PHONE_STATE for API version 31+
2915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2916 featureId, "getCallStateForSubscription")) {
2917 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2918 + "targeting API level 31+.");
2919 }
2920 }
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2925 PhoneConstantConversions.convertCallState(phone.getState());
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002932 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002933 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2934 }
2935
2936 @Override
2937 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002942 if (phone.isUsingNewDataStack()) {
2943 return phone.getDataNetworkController().getInternetDataNetworkState();
2944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2946 } else {
2947 return PhoneConstantConversions.convertDataState(
2948 PhoneConstants.DataState.DISCONNECTED);
2949 }
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 }
2954
Sanket Padawe356d7632015-06-22 14:03:32 -07002955 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002956 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002957 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2958 }
2959
2960 @Override
2961 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 if (phone != null) {
2966 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2967 } else {
2968 return TelephonyManager.DATA_ACTIVITY_NONE;
2969 }
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
2974
2975 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002976 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002978 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002979
2980 LocationAccessPolicy.LocationPermissionResult locationResult =
2981 LocationAccessPolicy.checkLocationPermission(mApp,
2982 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2983 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002984 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002985 .setCallingPid(Binder.getCallingPid())
2986 .setCallingUid(Binder.getCallingUid())
2987 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002988 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002989 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2990 .build());
2991 switch (locationResult) {
2992 case DENIED_HARD:
2993 throw new SecurityException("Not allowed to access cell location");
2994 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002995 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2996 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 }
2998
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002999 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003003 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003004 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Svetoslav64fad262015-04-14 14:35:21 -07003008 }
3009
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003011 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003012 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3013 // registered cell info, so return a NULL country instead.
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003016 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3017 // Get default phone in this case.
3018 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3019 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003020 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003022 if (phone == null) return "";
3023 ServiceStateTracker sst = phone.getServiceStateTracker();
3024 if (sst == null) return "";
3025 LocaleTracker lt = sst.getLocaleTracker();
3026 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003027 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003031 }
3032
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003033 /**
3034 * This method was removed due to potential issues caused by performing partial
3035 * updates of service state, and lack of a credible use case.
3036 *
3037 * This has the ability to break the telephony implementation by disabling notification of
3038 * changes in device connectivity. DO NOT USE THIS!
3039 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003040 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 public void enableLocationUpdates() {
3042 mApp.enforceCallingOrSelfPermission(
3043 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003044 }
3045
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003046 /**
3047 * This method was removed due to potential issues caused by performing partial
3048 * updates of service state, and lack of a credible use case.
3049 *
3050 * This has the ability to break the telephony implementation by disabling notification of
3051 * changes in device connectivity. DO NOT USE THIS!
3052 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 @Override
3054 public void disableLocationUpdates() {
3055 mApp.enforceCallingOrSelfPermission(
3056 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
3059 @Override
3060 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003061 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3062 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003063 try {
3064 mApp.getSystemService(AppOpsManager.class)
3065 .checkPackage(Binder.getCallingUid(), callingPackage);
3066 } catch (SecurityException e) {
3067 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3068 throw e;
3069 }
3070
Nathan Haroldf096d982020-11-18 17:18:06 -08003071 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003072 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3073 throw new SecurityException(
3074 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3075 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003076
Jordan Liu1617b712019-07-10 15:06:26 -07003077 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3079 return null;
3080 }
Svetoslav64fad262015-04-14 14:35:21 -07003081
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003082 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003083
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003084 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003085 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086
Nathan Haroldf180aac2018-06-01 18:43:55 -07003087 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3088 for (CellInfo ci : info) {
3089 if (ci instanceof CellInfoGsm) {
3090 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3091 } else if (ci instanceof CellInfoWcdma) {
3092 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003095 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
3097
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003098 private List<CellInfo> getCachedCellInfo() {
3099 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3100 for (Phone phone : PhoneFactory.getPhones()) {
3101 List<CellInfo> info = phone.getAllCellInfo();
3102 if (info != null) cellInfos.addAll(info);
3103 }
3104 return cellInfos;
3105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003106
3107 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003108 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003109 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003110 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003111
3112 LocationAccessPolicy.LocationPermissionResult locationResult =
3113 LocationAccessPolicy.checkLocationPermission(mApp,
3114 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3115 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003116 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003117 .setCallingPid(Binder.getCallingPid())
3118 .setCallingUid(Binder.getCallingUid())
3119 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003120 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003121 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3122 .build());
3123 switch (locationResult) {
3124 case DENIED_HARD:
3125 throw new SecurityException("Not allowed to access cell info");
3126 case DENIED_SOFT:
3127 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 }
3129
Nathan Haroldf096d982020-11-18 17:18:06 -08003130 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003131 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3132 return getCachedCellInfo();
3133 }
3134
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003135 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003136 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3140 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003141 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003142 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143 if (info != null) cellInfos.addAll(info);
3144 }
3145 return cellInfos;
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149 }
3150
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003151 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003152 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3153 String callingFeatureId) {
3154 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3155 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003156 }
3157
3158 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003159 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3160 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003161 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003162 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003163 }
3164
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003165 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3166 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003167 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003168 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003169
3170 LocationAccessPolicy.LocationPermissionResult locationResult =
3171 LocationAccessPolicy.checkLocationPermission(mApp,
3172 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3173 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003174 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003175 .setCallingPid(Binder.getCallingPid())
3176 .setCallingUid(Binder.getCallingUid())
3177 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003178 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3179 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 .build());
3181 switch (locationResult) {
3182 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003183 if (TelephonyPermissions
3184 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003185 // Safetynet logging for b/154934934
3186 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3187 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003188 throw new SecurityException("Not allowed to access cell info");
3189 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003190 if (TelephonyPermissions
3191 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003192 // Safetynet logging for b/154934934
3193 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3194 }
Nathan Harold5320c422019-05-09 10:26:08 -07003195 try {
3196 cb.onCellInfo(new ArrayList<CellInfo>());
3197 } catch (RemoteException re) {
3198 // Drop without consequences
3199 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003200 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003201 }
3202
Nathan Harolda939a962019-05-09 10:13:47 -07003203
3204 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003205 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3206
3207 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3208 }
3209
3210 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003212 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003217 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
Shishir Agrawala9f32182016-04-12 12:00:16 -07003223 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003224 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003225 Phone phone = PhoneFactory.getPhone(slotIndex);
3226 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003227 return null;
3228 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003229 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003230 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003231 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003232 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003233 return null;
3234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 return phone.getImei();
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003242 }
3243
3244 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003245 public String getTypeAllocationCodeForSlot(int slotIndex) {
3246 Phone phone = PhoneFactory.getPhone(slotIndex);
3247 String tac = null;
3248 if (phone != null) {
3249 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003250 try {
3251 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3252 } catch (IndexOutOfBoundsException e) {
3253 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3254 return null;
3255 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003256 }
3257 return tac;
3258 }
3259
3260 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003261 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003262 try {
3263 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3264 } catch (SecurityException se) {
3265 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3266 throw new SecurityException("Package " + callingPackage + " does not belong to "
3267 + Binder.getCallingUid());
3268 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003269 Phone phone = PhoneFactory.getPhone(slotIndex);
3270 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003271 return null;
3272 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003273
Jeff Davidson913390f2018-02-23 17:11:49 -08003274 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003275 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003276 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003277 return null;
3278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 return phone.getMeid();
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Jack Yu2af8d712017-03-15 17:14:14 -07003286 }
3287
3288 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003289 public String getManufacturerCodeForSlot(int slotIndex) {
3290 Phone phone = PhoneFactory.getPhone(slotIndex);
3291 String manufacturerCode = null;
3292 if (phone != null) {
3293 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003294 try {
3295 manufacturerCode =
3296 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3297 } catch (IndexOutOfBoundsException e) {
3298 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3299 return null;
3300 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003301 }
3302 return manufacturerCode;
3303 }
3304
3305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003306 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3307 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003308 Phone phone = PhoneFactory.getPhone(slotIndex);
3309 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003310 return null;
3311 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003312 int subId = phone.getSubId();
3313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003314 mApp, subId, callingPackage, callingFeatureId,
3315 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003316 return null;
3317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318
3319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 return phone.getDeviceSvn();
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003325 }
3326
fionaxu43304da2017-11-27 22:51:16 -08003327 @Override
3328 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 final Phone phone = getPhone(subId);
3332 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
fionaxu43304da2017-11-27 22:51:16 -08003336 }
3337
3338 @Override
3339 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 final Phone phone = getPhone(subId);
3343 return phone == null ? null : phone.getCarrierName();
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
fionaxu43304da2017-11-27 22:51:16 -08003347 }
3348
calvinpanffe225e2018-11-01 19:43:06 +08003349 @Override
chen xu0026ca62019-03-06 15:28:50 -08003350 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 final Phone phone = getPhone(subId);
3354 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003355 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
3359 }
3360
3361 @Override
chen xu0026ca62019-03-06 15:28:50 -08003362 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003366 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
3370 }
3371
chen xu651eec72018-11-11 19:03:44 -08003372 @Override
chen xu864e11c2018-12-06 22:10:03 -08003373 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3374 if (!isSubscriptionMccMnc) {
3375 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3376 }
chen xu651eec72018-11-11 19:03:44 -08003377 final Phone phone = PhoneFactory.getPhone(slotIndex);
3378 if (phone == null) {
3379 return TelephonyManager.UNKNOWN_CARRIER_ID;
3380 }
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
3388
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 //
3390 // Internal helper methods.
3391 //
3392
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003393 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003394 * Make sure the caller is the calling package itself
3395 *
3396 * @throws SecurityException if the caller is not the calling package
3397 */
3398 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3399 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003400 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3401 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003402 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003403 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003404 } catch (PackageManager.NameNotFoundException e) {
3405 // packageUid is -1
3406 }
3407 if (packageUid != callingUid) {
3408 throw new SecurityException(message + ": Package " + callingPackage
3409 + " does not belong to " + callingUid);
3410 }
3411 }
3412
3413 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3415 *
3416 * @throws SecurityException if the caller does not have the required permission
3417 */
3418 private void enforceModifyPermission() {
3419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3420 }
3421
Shuo Qian3b6ee772019-11-13 17:43:31 -08003422 private void enforceActiveEmergencySessionPermission() {
3423 mApp.enforceCallingOrSelfPermission(
3424 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3425 }
3426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 /**
3428 * Make sure the caller has the CALL_PHONE permission.
3429 *
3430 * @throws SecurityException if the caller does not have the required permission
3431 */
3432 private void enforceCallPermission() {
3433 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3434 }
3435
paulhu5a773602019-08-23 19:17:33 +08003436 private void enforceSettingsPermission() {
3437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003438 }
3439
Michele Berionne5e411512020-11-13 02:36:59 +00003440 private void enforceRebootPermission() {
3441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3442 }
3443
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 private String createTelUrl(String number) {
3445 if (TextUtils.isEmpty(number)) {
3446 return null;
3447 }
3448
Jake Hambye994d462014-02-03 13:10:13 -08003449 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 }
3451
Ihab Awadf9e92732013-12-05 18:02:52 -08003452 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3454 }
3455
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003456 private static void logv(String msg) {
3457 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3458 }
3459
Ihab Awadf9e92732013-12-05 18:02:52 -08003460 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3462 }
3463
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003464 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003466 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003467 }
3468
Sanket Padawe356d7632015-06-22 14:03:32 -07003469 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003470 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 final Phone phone = PhoneFactory.getPhone(slotIndex);
3474 if (phone == null) {
3475 return PhoneConstants.PHONE_TYPE_NONE;
3476 } else {
3477 return phone.getPhoneType();
3478 }
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 }
3483
3484 /**
3485 * Returns the CDMA ERI icon index to display
3486 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003488 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3489 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3490 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003491 }
3492
Sanket Padawe356d7632015-06-22 14:03:32 -07003493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003494 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3495 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003497 mApp, subId, callingPackage, callingFeatureId,
3498 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003499 return -1;
3500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 final Phone phone = getPhone(subId);
3505 if (phone != null) {
3506 return phone.getCdmaEriIconIndex();
3507 } else {
3508 return -1;
3509 }
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 }
3514
3515 /**
3516 * Returns the CDMA ERI icon mode,
3517 * 0 - ON
3518 * 1 - FLASHING
3519 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3522 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3523 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003524 }
3525
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003527 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3528 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003530 mApp, subId, callingPackage, callingFeatureId,
3531 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 return -1;
3533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = getPhone(subId);
3538 if (phone != null) {
3539 return phone.getCdmaEriIconMode();
3540 } else {
3541 return -1;
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547
3548 /**
3549 * Returns the CDMA ERI text,
3550 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3553 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3554 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003555 }
3556
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3559 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003561 mApp, subId, callingPackage, callingFeatureId,
3562 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 return null;
3564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 return phone.getCdmaEriText();
3571 } else {
3572 return null;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003577 }
3578
3579 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003580 * Returns the CDMA MDN.
3581 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003583 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3585 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586
3587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591 return phone.getLine1Number();
3592 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003593 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594 return null;
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003598 }
3599 }
3600
3601 /**
3602 * Returns the CDMA MIN.
3603 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003605 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3607 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 final Phone phone = getPhone(subId);
3612 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3613 return phone.getCdmaMin();
3614 } else {
3615 return null;
3616 }
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003619 }
3620 }
3621
Hall Liud892bec2018-11-30 14:51:45 -08003622 @Override
3623 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3624 INumberVerificationCallback callback, String callingPackage) {
3625 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3626 != PERMISSION_GRANTED) {
3627 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3628 }
3629 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3630
3631 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3632 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003633 throw new SecurityException("Calling package must be configured in the device config: "
3634 + "calling package: " + callingPackage
3635 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003636 }
3637
3638 if (range == null) {
3639 throw new NullPointerException("Range must be non-null");
3640 }
3641
3642 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003643 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003644
3645 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3646 }
3647
Junda Liuca05d5d2014-08-14 22:36:34 -07003648 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 * Returns true if CDMA provisioning needs to run.
3650 */
3651 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 final long identity = Binder.clearCallingIdentity();
3653 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 }
3659
3660 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003661 * Sets the voice mail number of a given subId.
3662 */
3663 @Override
3664 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003665 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3666 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3671 new Pair<String, String>(alphaTag, number), new Integer(subId));
3672 return success;
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003676 }
3677
Ta-wei Yen87c49842016-05-13 21:19:52 -07003678 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003679 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003681 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3682 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003683 if (!TextUtils.equals(callingPackage, systemDialer)) {
3684 throw new SecurityException("caller must be system dialer");
3685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3690 if (phoneAccountHandle == null) {
3691 return null;
3692 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003693 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003696 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003697 }
3698
3699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003700 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3701 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003704 mApp, subId, callingPackage, callingFeatureId,
3705 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003706 return null;
3707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003709 final long identity = Binder.clearCallingIdentity();
3710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003715 }
3716
3717 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003718 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3719 VisualVoicemailSmsFilterSettings settings) {
3720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003725 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003729 }
3730
3731 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003732 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 }
3743
3744 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003745 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3746 String callingPackage, int subId) {
3747 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
3749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003756 }
3757
3758 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003759 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003765 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003769 }
3770
3771 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003772 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3773 String callingAttributionTag, int subId, String number, int port, String text,
3774 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003776 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003777 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003778 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003779 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3780 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003781 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003782
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003783 /**
fionaxu0152e512016-11-14 13:36:14 -08003784 * Sets the voice activation state of a given subId.
3785 */
3786 @Override
3787 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3789 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 final Phone phone = getPhone(subId);
3794 if (phone != null) {
3795 phone.setVoiceActivationState(activationState);
3796 } else {
3797 loge("setVoiceActivationState fails with invalid subId: " + subId);
3798 }
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003801 }
3802 }
3803
3804 /**
3805 * Sets the data activation state of a given subId.
3806 */
3807 @Override
3808 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3810 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811
3812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 final Phone phone = getPhone(subId);
3815 if (phone != null) {
3816 phone.setDataActivationState(activationState);
3817 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003818 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819 }
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003822 }
3823 }
3824
3825 /**
3826 * Returns the voice activation state of a given subId.
3827 */
3828 @Override
3829 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831
fionaxu0152e512016-11-14 13:36:14 -08003832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 if (phone != null) {
3836 return phone.getVoiceActivationState();
3837 } else {
3838 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3839 }
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003842 }
3843 }
3844
3845 /**
3846 * Returns the data activation state of a given subId.
3847 */
3848 @Override
3849 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851
fionaxu0152e512016-11-14 13:36:14 -08003852 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 if (phone != null) {
3856 return phone.getDataActivationState();
3857 } else {
3858 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3859 }
3860 } finally {
3861 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003862 }
3863 }
3864
3865 /**
Wink Saville36469e72014-06-11 15:17:00 -07003866 * Returns the unread count of voicemails for a subId
3867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003869 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3870 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003872 mApp, subId, callingPackage, callingFeatureId,
3873 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003874 return 0;
3875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 if (phone != null) {
3880 return phone.getVoiceMessageCount();
3881 } else {
3882 return 0;
3883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887 }
3888
3889 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003890 * returns true, if the device is in a state where both voice and data
3891 * are supported simultaneously. This can change based on location or network condition.
3892 */
3893 @Override
3894 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 final Phone phone = getPhone(subId);
3898 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003902 }
3903
3904 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003905 * Send the dialer code if called from the current default dialer or the caller has
3906 * carrier privilege.
3907 * @param inputCode The dialer code to send
3908 */
3909 @Override
3910 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003911 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003913 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3914 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003915 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003916 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003917 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
fionaxu235cc5e2017-03-06 22:25:57 -08003926 }
3927
Pengquan Menga1bb6272018-09-06 09:59:22 -07003928 @Override
3929 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003930 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003931 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003932 mApp, subId, "getNetworkSelectionMode");
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 if (!isActiveSubscription(subId)) {
3936 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3937 }
3938 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003942 }
3943
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003945 public boolean isInEmergencySmsMode() {
3946 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 for (Phone phone : PhoneFactory.getPhones()) {
3950 if (phone.isInEmergencySmsMode()) {
3951 return true;
3952 }
3953 }
3954 } finally {
3955 Binder.restoreCallingIdentity(identity);
3956 }
3957 return false;
3958 }
3959
shilu366312e2019-12-17 09:28:10 -08003960 /**
3961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3962 * @param subId The subscription to use to check the configuration.
3963 * @param c The callback that will be used to send the result.
3964 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003965 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003966 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3967 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003968 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003969 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003970
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003971 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3972 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3973 "IMS not available on device.");
3974 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 final long token = Binder.clearCallingIdentity();
3976 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003977 int slotId = getSlotIndexOrException(subId);
3978 verifyImsMmTelConfiguredOrThrow(slotId);
3979 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003980 } catch (ImsException e) {
3981 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 } finally {
3983 Binder.restoreCallingIdentity(token);
3984 }
3985 }
3986
shilu366312e2019-12-17 09:28:10 -08003987 /**
3988 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3989 * @param subId The subscription to use to check the configuration.
3990 * @param c The callback that will be used to send the result.
3991 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003993 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003994 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003995 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003996 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3997 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3998 }
Meng Wangafbc5852019-09-19 17:37:13 -07003999 final long token = Binder.clearCallingIdentity();
4000 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004001 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4002 .removeRegistrationCallbackForSubscription(c, subId);
4003 } catch (ImsException e) {
4004 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4005 + "is inactive, ignoring unregister.");
4006 // If the subscription is no longer active, just return, since the callback
4007 // will already have been removed internally.
4008 } finally {
4009 Binder.restoreCallingIdentity(token);
4010 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 }
4012
Brad Ebingera34a6c22019-10-22 17:36:18 -07004013 /**
4014 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4015 */
4016 @Override
4017 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4018 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4019 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4020 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4021 "IMS not available on device.");
4022 }
4023 final long token = Binder.clearCallingIdentity();
4024 try {
4025 Phone phone = getPhone(subId);
4026 if (phone == null) {
4027 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4028 + subId + "'");
4029 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4030 }
4031 phone.getImsRegistrationState(regState -> {
4032 try {
4033 consumer.accept((regState == null)
4034 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4035 } catch (RemoteException e) {
4036 // Ignore if the remote process is no longer available to call back.
4037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4038 }
4039 });
4040 } finally {
4041 Binder.restoreCallingIdentity(token);
4042 }
4043 }
4044
4045 /**
4046 * Get the transport type for the IMS service registration state.
4047 */
4048 @Override
4049 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004050 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004051 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004052 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4053 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4054 "IMS not available on device.");
4055 }
4056 final long token = Binder.clearCallingIdentity();
4057 try {
4058 Phone phone = getPhone(subId);
4059 if (phone == null) {
4060 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4061 + subId + "'");
4062 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4063 }
4064 phone.getImsRegistrationTech(regTech -> {
4065 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4066 int regTechConverted = (regTech == null)
4067 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4068 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4069 regTechConverted);
4070 try {
4071 consumer.accept(regTechConverted);
4072 } catch (RemoteException e) {
4073 // Ignore if the remote process is no longer available to call back.
4074 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4075 }
4076 });
4077 } finally {
4078 Binder.restoreCallingIdentity(token);
4079 }
4080 }
4081
shilu366312e2019-12-17 09:28:10 -08004082 /**
4083 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4084 * @param subId The subscription to use to check the configuration.
4085 * @param c The callback that will be used to send the result.
4086 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004088 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4089 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004090 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004091 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004092 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4093 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4094 "IMS not available on device.");
4095 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 final long token = Binder.clearCallingIdentity();
4097 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004098 int slotId = getSlotIndexOrException(subId);
4099 verifyImsMmTelConfiguredOrThrow(slotId);
4100 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004101 } catch (ImsException e) {
4102 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 } finally {
4104 Binder.restoreCallingIdentity(token);
4105 }
4106 }
4107
shilu366312e2019-12-17 09:28:10 -08004108 /**
4109 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4110 * @param subId The subscription to use to check the configuration.
4111 * @param c The callback that will be used to send the result.
4112 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004114 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004115 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004116 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004117 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4118 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4119 }
Meng Wangafbc5852019-09-19 17:37:13 -07004120
4121 final long token = Binder.clearCallingIdentity();
4122 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004123 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004124 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004125 } catch (ImsException e) {
4126 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4127 + "is inactive, ignoring unregister.");
4128 // If the subscription is no longer active, just return, since the callback
4129 // will already have been removed internally.
4130 } finally {
4131 Binder.restoreCallingIdentity(token);
4132 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 }
4134
4135 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004136 public boolean isCapable(int subId, int capability, int regTech) {
4137 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 final long token = Binder.clearCallingIdentity();
4139 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004140 int slotId = getSlotIndexOrException(subId);
4141 verifyImsMmTelConfiguredOrThrow(slotId);
4142 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4145 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004146 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004147 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4148 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 } finally {
4150 Binder.restoreCallingIdentity(token);
4151 }
4152 }
4153
4154 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004155 public boolean isAvailable(int subId, int capability, int regTech) {
4156 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 final long token = Binder.clearCallingIdentity();
4158 try {
4159 Phone phone = getPhone(subId);
4160 if (phone == null) return false;
4161 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004162 } catch (com.android.ims.ImsException e) {
4163 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4164 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 } finally {
4166 Binder.restoreCallingIdentity(token);
4167 }
4168 }
4169
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004170 /**
4171 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4172 * subscription.
4173 * @param subId The subscription to use to check the configuration.
4174 * @param callback The callback that will be used to send the result.
4175 * @param capability The MmTelFeature capability that will be used to send the result.
4176 * @param transportType The transport type of the MmTelFeature capability.
4177 */
4178 @Override
4179 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4180 int transportType) {
4181 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4182 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4183 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4184 "IMS not available on device.");
4185 }
4186 final long token = Binder.clearCallingIdentity();
4187 try {
4188 int slotId = getSlotIndex(subId);
4189 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4190 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4191 + subId + "'");
4192 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4193 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004194 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004195 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4196 transportType, aBoolean -> {
4197 try {
4198 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4199 } catch (RemoteException e) {
4200 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4201 + "running. Ignore");
4202 }
4203 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004204 } catch (ImsException e) {
4205 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004206 } finally {
4207 Binder.restoreCallingIdentity(token);
4208 }
4209 }
4210
shilu366312e2019-12-17 09:28:10 -08004211 /**
4212 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4213 * @param subId The subscription to use to check the configuration.
4214 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 @Override
4216 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004217 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004218 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004219
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 final long token = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004223 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 } catch (ImsException e) {
4226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 } finally {
4228 Binder.restoreCallingIdentity(token);
4229 }
4230 }
4231
4232 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004233 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004235 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 final long identity = Binder.clearCallingIdentity();
4237 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004238 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004239 // This setting doesn't require an active ImsService connection, so do not verify. The
4240 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004241 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
shilu366312e2019-12-17 09:28:10 -08004249 /**
4250 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4251 * @param subId The subscription to use to check the configuration.
4252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004254 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004256 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 final long identity = Binder.clearCallingIdentity();
4258 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004260 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004262 } catch (ImsException e) {
4263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
4267 }
4268
4269 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004270 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004272 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004276 // This setting doesn't require an active ImsService connection, so do not verify. The
4277 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004279 } catch (ImsException e) {
4280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
4284 }
4285
shilu366312e2019-12-17 09:28:10 -08004286 /**
4287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4288 * @param subId The subscription to use to check the configuration.
4289 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 @Override
4291 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004292 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004293 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 final long identity = Binder.clearCallingIdentity();
4295 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004297 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004299 } catch (ImsException e) {
4300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
4304 }
4305
4306 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004307 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004309 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 final long identity = Binder.clearCallingIdentity();
4311 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004312 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004313 // This setting doesn't require an active ImsService connection, so do not verify. The
4314 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004316 } catch (ImsException e) {
4317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 }
4322
shilu366312e2019-12-17 09:28:10 -08004323 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004324 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 */
4328 @Override
4329 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004331 mApp, subId, "isCrossSimCallingEnabledByUser");
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
4342 }
4343
4344 /**
4345 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4346 * Requires MODIFY_PHONE_STATE permission.
4347 * @param subId The subscription to use to check the configuration.
4348 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4349 * false otherwise
4350 */
4351 @Override
4352 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4354 "setCrossSimCallingEnabled");
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004358 // This setting doesn't require an active ImsService connection, so do not verify. The
4359 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004361 } catch (ImsException e) {
4362 throw new ServiceSpecificException(e.getCode());
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
4366 }
4367
4368 /**
shilu366312e2019-12-17 09:28:10 -08004369 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4370 * @param subId The subscription to use to check the configuration.
4371 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004373
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004375 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004376 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 final long identity = Binder.clearCallingIdentity();
4378 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004380 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004382 } catch (ImsException e) {
4383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
4387 }
4388
4389 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004390 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004392 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 final long identity = Binder.clearCallingIdentity();
4394 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004396 // This setting doesn't require an active ImsService connection, so do not verify. The
4397 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004399 } catch (ImsException e) {
4400 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
4406 @Override
4407 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4409 "setVoWiFiNonPersistent");
4410 final long identity = Binder.clearCallingIdentity();
4411 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004412 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004413 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (ImsException e) {
4416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420 }
4421
shilu366312e2019-12-17 09:28:10 -08004422 /**
4423 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4424 * @param subId The subscription to use to check the configuration.
4425 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004426 @Override
4427 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004428 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004429 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 final long identity = Binder.clearCallingIdentity();
4431 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004433 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004434 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004435 } catch (ImsException e) {
4436 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
4440 }
4441
4442 @Override
4443 public void setVoWiFiModeSetting(int subId, int mode) {
4444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4445 "setVoWiFiModeSetting");
4446 final long identity = Binder.clearCallingIdentity();
4447 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004448 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004449 // This setting doesn't require an active ImsService connection, so do not verify. The
4450 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004452 } catch (ImsException e) {
4453 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
4457 }
4458
4459 @Override
4460 public int getVoWiFiRoamingModeSetting(int subId) {
4461 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004465 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004467 } catch (ImsException e) {
4468 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
4472 }
4473
4474 @Override
4475 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4477 "setVoWiFiRoamingModeSetting");
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004481 // This setting doesn't require an active ImsService connection, so do not verify. The
4482 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
4491 @Override
4492 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4494 "setRttCapabilityEnabled");
4495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004498 // This setting doesn't require an active ImsService connection, so do not verify. The
4499 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (ImsException e) {
4502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
shilu366312e2019-12-17 09:28:10 -08004508 /**
4509 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4510 * @param subId The subscription to use to check the configuration.
4511 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 @Override
4513 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004515 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 final long identity = Binder.clearCallingIdentity();
4517 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004519 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
4522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
4526 }
4527
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004528 @Override
4529 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4530 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4531 final long identity = Binder.clearCallingIdentity();
4532 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004533 if (!isImsAvailableOnDevice()) {
4534 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4535 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004536 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 int slotId = getSlotIndexOrException(subId);
4538 verifyImsMmTelConfiguredOrThrow(slotId);
4539 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004540 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 } catch (ImsException e) {
4542 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
4546 }
4547
4548 @Override
4549 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4550 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4551 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4554 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004555 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004556 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004557 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004559 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4560 + "is inactive, ignoring unregister.");
4561 // If the subscription is no longer active, just return, since the callback will already
4562 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
4566 }
4567
allenwtsu99c623b2020-01-03 18:24:23 +08004568
4569 private void checkModifyPhoneStatePermission(int subId, String message) {
4570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4571 message);
4572 }
4573
4574 private boolean isImsProvisioningRequired(int subId, int capability,
4575 boolean isMmtelCapability) {
4576 Phone phone = getPhone(subId);
4577 if (phone == null) {
4578 loge("phone instance null for subid " + subId);
4579 return false;
4580 }
4581 if (isMmtelCapability) {
4582 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4583 return false;
4584 }
4585 } else {
4586 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4587 return false;
4588 }
4589 }
4590 return true;
4591 }
4592
4593 @Override
4594 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4595 boolean isProvisioned) {
4596 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4597
4598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4601 if (!isImsProvisioningRequired(subId, capability, false)) {
4602 return;
4603 }
4604
4605 // this capability requires provisioning, route to the correct API.
4606 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4607 switch (capability) {
4608 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4609 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4610 ims.setEabProvisioned(isProvisioned);
4611 break;
4612 default: {
4613 throw new IllegalArgumentException("Tried to set provisioning for "
4614 + "rcs capability '" + capability + "', which does not require "
4615 + "provisioning.");
4616 }
4617 }
4618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
4621
4622 }
4623
4624
4625 @Override
4626 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4627 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4631 if (!isImsProvisioningRequired(subId, capability, false)) {
4632 return true;
4633 }
4634
4635 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4636 switch (capability) {
4637 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4638 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4639 return ims.isEabProvisionedOnDevice();
4640
4641 default: {
4642 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4643 + "capability '" + capability + "', which does not require "
4644 + "provisioning.");
4645 }
4646 }
4647
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
4651 }
4652
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4655 boolean isProvisioned) {
4656 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004657 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4658 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4661 }
allenwtsu99c623b2020-01-03 18:24:23 +08004662 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004663 final long identity = Binder.clearCallingIdentity();
4664 try {
4665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004666 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 return;
4668 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004669 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4670 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4671 loge("setImsProvisioningStatusForCapability: called for technology that does "
4672 + "not support provisioning - " + tech);
4673 return;
4674 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675
4676 // this capability requires provisioning, route to the correct API.
4677 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4678 switch (capability) {
4679 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4680 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4681 ims.setVolteProvisioned(isProvisioned);
4682 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4683 ims.setWfcProvisioned(isProvisioned);
4684 }
4685 break;
4686 }
4687 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4688 // There is currently no difference in VT provisioning type.
4689 ims.setVtProvisioned(isProvisioned);
4690 break;
4691 }
4692 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4693 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4694 // change the capability of the feature instead if needed.
4695 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4696 == isProvisioned) {
4697 // No change in provisioning.
4698 return;
4699 }
4700 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4701 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004702 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004703 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004704 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4705 + ", Exception" + e.getMessage());
4706 }
4707 break;
4708 }
4709 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004710 throw new IllegalArgumentException("Tried to set provisioning for "
4711 + "MmTel capability '" + capability + "', which does not require "
4712 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713 }
4714 }
4715
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
4719 }
4720
4721 @Override
4722 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4723 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004724 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4725 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4726 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4728 }
4729 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004733 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 return true;
4735 }
4736
Brad Ebinger0d79c572021-04-17 15:20:49 -07004737 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4738 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4739 loge("getImsProvisioningStatusForCapability: called for technology that does "
4740 + "not support provisioning - " + tech);
4741 return true;
4742 }
4743
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4745 switch (capability) {
4746 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4747 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4748 return ims.isVolteProvisionedOnDevice();
4749 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4750 return ims.isWfcProvisionedOnDevice();
4751 }
4752 // This should never happen, since we are checking tech above to make sure it
4753 // is either LTE or IWLAN.
4754 throw new IllegalArgumentException("Invalid radio technology for voice "
4755 + "capability.");
4756 }
4757 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4758 // There is currently no difference in VT provisioning type.
4759 return ims.isVtProvisionedOnDevice();
4760 }
4761 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4762 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4763 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4764 }
4765 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004766 throw new IllegalArgumentException(
4767 "Tried to get provisioning for MmTel capability '" + capability
4768 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004769 }
4770 }
4771
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
4774 }
4775 }
4776
4777 @Override
4778 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4779 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4780 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4781 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4782 }
4783 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4784 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4785 return (provisionedBits & capability) > 0;
4786 }
4787
4788 @Override
4789 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4790 boolean isProvisioned) {
4791 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4792 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4793 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4794 }
4795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4796 "setProvisioningStatusForCapability");
4797 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4798 // If the current provisioning status for capability already matches isProvisioned,
4799 // do nothing.
4800 if (((provisionedBits & capability) > 0) == isProvisioned) {
4801 return;
4802 }
4803 if (isProvisioned) {
4804 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4805 } else {
4806 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4807 }
4808 }
4809
4810 /**
4811 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4812 * technology. The bitfield should mirror the bitfield defined by
4813 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4814 */
4815 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4816 String key = getMmTelProvisioningKey(subId, tech);
4817 // Default is no capabilities are provisioned.
4818 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4819 }
4820
4821 /**
4822 * Sets the MmTel capability provisioning bitfield (defined by
4823 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4824 * technology specified.
4825 *
4826 * Note: This is a synchronous command and should not be called on UI thread.
4827 */
4828 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4829 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4830 String key = getMmTelProvisioningKey(subId, tech);
4831 editor.putInt(key, newField);
4832 editor.commit();
4833 }
4834
4835 private static String getMmTelProvisioningKey(int subId, int tech) {
4836 // resulting key is provision_ims_mmtel_{subId}_{tech}
4837 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4838 }
4839
4840 /**
4841 * Query CarrierConfig to see if the specified capability requires provisioning for the
4842 * carrier associated with the subscription id.
4843 */
4844 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4845 int capability) {
4846 CarrierConfigManager configManager = new CarrierConfigManager(context);
4847 PersistableBundle c = configManager.getConfigForSubId(subId);
4848 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004849 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4851 false);
4852 boolean requireVoiceVtProvisioning = c.getBoolean(
4853 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4854
4855 // First check to make sure that the capability requires provisioning.
4856 switch (capability) {
4857 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4858 // intentional fallthrough
4859 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4860 if (requireVoiceVtProvisioning) {
4861 // Voice and Video requires provisioning
4862 return true;
4863 }
4864 break;
4865 }
4866 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4867 if (requireUtProvisioning) {
4868 // UT requires provisioning
4869 return true;
4870 }
4871 break;
4872 }
4873 }
4874 return false;
4875 }
4876
allenwtsu99c623b2020-01-03 18:24:23 +08004877 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4878 int capability) {
4879 CarrierConfigManager configManager = new CarrierConfigManager(context);
4880 PersistableBundle c = configManager.getConfigForSubId(subId);
4881
4882 boolean requireRcsProvisioning = c.getBoolean(
4883 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4884
4885 // First check to make sure that the capability requires provisioning.
4886 switch (capability) {
4887 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4888 // intentional fallthrough
4889 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4890 if (requireRcsProvisioning) {
4891 // OPTION or PRESENCE requires provisioning
4892 return true;
4893 }
4894 break;
4895 }
4896 }
4897 return false;
4898 }
4899
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004901 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4903 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4904 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004905 enforceReadPrivilegedPermission("getImsProvisioningInt");
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909 int slotId = getSlotIndex(subId);
4910 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4911 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4912 + subId + "' for key:" + key);
4913 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4914 }
calvinpanb5a34062021-02-08 19:59:36 +08004915 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004916 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4918 + subId + "' for key:" + key);
4919 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
4925 @Override
4926 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4928 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4929 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004930 enforceReadPrivilegedPermission("getImsProvisioningString");
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004934 int slotId = getSlotIndex(subId);
4935 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4936 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4937 + subId + "' for key:" + key);
4938 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4939 }
calvinpanb5a34062021-02-08 19:59:36 +08004940 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004941 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004942 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4943 + subId + "' for key:" + key);
4944 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
4948 }
4949
4950 @Override
4951 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4953 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4954 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4956 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 int slotId = getSlotIndex(subId);
4961 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4962 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4963 + subId + "' for key:" + key);
4964 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4965 }
calvinpanb5a34062021-02-08 19:59:36 +08004966 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4967 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004969 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
4974 }
4975
4976 @Override
4977 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004978 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4979 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4980 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4982 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004986 int slotId = getSlotIndex(subId);
4987 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4988 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4989 + subId + "' for key:" + key);
4990 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4991 }
calvinpanb5a34062021-02-08 19:59:36 +08004992 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4993 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004994 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004995 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004996 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
5000 }
5001
Brad Ebinger919631e2021-06-02 17:46:35 -07005002 /**
5003 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5004 * for the given slot ID or no ImsResolver instance has been created.
5005 * @param slotId The slot ID that the IMS service is created for.
5006 * @throws ImsException If there is no ImsService configured for this slot.
5007 */
5008 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5009 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5010 ImsFeature.FEATURE_MMTEL)) {
5011 throw new ImsException("This subscription does not support MMTEL over IMS",
5012 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5013 }
5014 }
5015
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005016 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005017 int slotId = SubscriptionManager.getSlotIndex(subId);
5018 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005019 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5020 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005021 }
5022 return slotId;
5023 }
5024
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 private int getSlotIndex(int subId) {
5026 int slotId = SubscriptionManager.getSlotIndex(subId);
5027 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5028 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5029 }
5030 return slotId;
5031 }
5032
Wink Saville36469e72014-06-11 15:17:00 -07005033 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005034 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005035 */
5036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005037 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5038 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005039 try {
5040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5041 } catch (SecurityException se) {
5042 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5043 throw new SecurityException("Package " + callingPackage + " does not belong to "
5044 + Binder.getCallingUid());
5045 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005046 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005047 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005048 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005049 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005050 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005051 mApp, subId, callingPackage, callingFeatureId,
5052 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005053 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5054 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 final Phone phone = getPhone(subId);
5059 if (phone != null) {
5060 return phone.getServiceState().getDataNetworkType();
5061 } else {
5062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005067 }
5068
5069 /**
5070 * Returns the data network type
5071 */
5072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005073 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005074 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5075 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005076 }
5077
5078 /**
5079 * Returns the data network type for a subId
5080 */
5081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005082 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5083 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005085 mApp, subId, callingPackage, callingFeatureId,
5086 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5088 }
5089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 final Phone phone = getPhone(subId);
5093 if (phone != null) {
5094 return phone.getServiceState().getDataNetworkType();
5095 } else {
5096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005101 }
5102
5103 /**
Wink Saville36469e72014-06-11 15:17:00 -07005104 * Returns the Voice network type for a subId
5105 */
5106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005107 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5108 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005110 mApp, subId, callingPackage, callingFeatureId,
5111 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5113 }
5114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 final Phone phone = getPhone(subId);
5118 if (phone != null) {
5119 return phone.getServiceState().getVoiceNetworkType();
5120 } else {
5121 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5122 }
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005126 }
5127
5128 /**
5129 * @return true if a ICC card is present
5130 */
5131 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005132 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005133 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5134 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005135 }
5136
5137 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005138 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005139 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005140 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005141 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 final Phone phone = PhoneFactory.getPhone(slotIndex);
5145 if (phone != null) {
5146 return phone.getIccCard().hasIccCard();
5147 } else {
5148 return false;
5149 }
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005153 }
5154
5155 /**
5156 * Return if the current radio is LTE on CDMA. This
5157 * is a tri-state return value as for a period of time
5158 * the mode may be unknown.
5159 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005160 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005162 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005163 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005165 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5166 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5167 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005168 }
5169
Sanket Padawe356d7632015-06-22 14:03:32 -07005170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005171 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5172 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005173 try {
5174 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5175 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005176 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5177 }
5178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 final Phone phone = getPhone(subId);
5182 if (phone == null) {
5183 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5184 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005185 return TelephonyProperties.lte_on_cdma_device()
5186 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 }
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005190 }
Wink Saville36469e72014-06-11 15:17:00 -07005191 }
5192
Wink Saville36469e72014-06-11 15:17:00 -07005193 /**
5194 * {@hide}
5195 * Returns Default subId, 0 in the case of single standby.
5196 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005197 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005198 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005199 }
5200
Shishir Agrawala9f32182016-04-12 12:00:16 -07005201 private int getSlotForDefaultSubscription() {
5202 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5203 }
5204
Wink Savilleb564aae2014-10-23 10:18:09 -07005205 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005206 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005207 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005208
Pengquan Menge92a50d2018-09-21 15:54:48 -07005209 private boolean isActiveSubscription(int subId) {
5210 return mSubscriptionController.isActiveSubId(subId);
5211 }
5212
Ihab Awadf2177b72013-11-25 13:33:23 -08005213 /**
5214 * @see android.telephony.TelephonyManager.WifiCallingChoices
5215 */
5216 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 final long identity = Binder.clearCallingIdentity();
5218 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5221 getWhenToMakeWifiCallsDefaultPreference());
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005225 }
5226
5227 /**
5228 * @see android.telephony.TelephonyManager.WifiCallingChoices
5229 */
5230 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005239 }
5240
Sailesh Nepald1e68152013-12-12 19:08:02 -08005241 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005242 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005243 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005244 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005245
Jordan Liu4c733742019-02-28 12:03:40 -08005246 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5247 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5248 if (phoneId == -1) {
5249 throw new IllegalArgumentException("Given slot index: " + slotIndex
5250 + " does not correspond to an active phone");
5251 }
5252 return PhoneFactory.getPhone(phoneId);
5253 }
5254
Shishir Agrawal566b7612013-10-28 14:41:00 -07005255 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005256 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5257 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5259 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005261 if (DBG) {
5262 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5263 }
5264 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5265 p2);
5266 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005267
Jordan Liu4c733742019-02-28 12:03:40 -08005268
5269 @Override
5270 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5271 int slotIndex, String callingPackage, String aid, int p2) {
5272 enforceModifyPermission();
5273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5274 if (DBG) {
5275 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5276 }
5277 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5278 callingPackage, aid, p2);
5279 }
5280
5281 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5282 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 if (TextUtils.equals(ISDR_AID, aid)) {
5286 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005287 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5288 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 if (bestComponent == null
5290 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5291 loge("The calling package is not allowed to access ISD-R.");
5292 throw new SecurityException(
5293 "The calling package is not allowed to access ISD-R.");
5294 }
Derek Tan740e1672017-06-27 14:56:27 -07005295 }
Derek Tan740e1672017-06-27 14:56:27 -07005296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005298 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5299 null /* workSource */);
5300 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 return response;
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005305 }
5306
5307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005308 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005311 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5312 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5313 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005314
Jordan Liu4c733742019-02-28 12:03:40 -08005315 @Override
5316 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5317 enforceModifyPermission();
5318 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5319 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5320 channel);
5321 }
5322
5323 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 if (channel < 0) {
5327 return false;
5328 }
Jordan Liu4c733742019-02-28 12:03:40 -08005329 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5330 null /* workSource */);
5331 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 return success;
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005335 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005336 }
5337
5338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005339 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005340 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5342 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005343 if (DBG) {
5344 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5345 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5346 + p3 + " data=" + data);
5347 }
5348 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5349 command, p1, p2, p3, data);
5350 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005351
Jordan Liu4c733742019-02-28 12:03:40 -08005352 @Override
5353 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5354 int command, int p1, int p2, int p3, String data) {
5355 enforceModifyPermission();
5356 if (DBG) {
5357 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5358 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5359 + p3 + " data=" + data);
5360 }
5361 return iccTransmitApduLogicalChannelWithPermission(
5362 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5363 data);
5364 }
5365
5366 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5367 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 final long identity = Binder.clearCallingIdentity();
5369 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005370 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 return "";
5372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005375 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5376 null /* workSource */);
5377 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 // Append the returned status code to the end of the response payload.
5380 String s = Integer.toHexString(
5381 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5382 if (response.payload != null) {
5383 s = IccUtils.bytesToHexString(response.payload) + s;
5384 }
5385 return s;
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005388 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005389 }
Jake Hambye994d462014-02-03 13:10:13 -08005390
Evan Charltonc66da362014-05-16 14:06:40 -07005391 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005392 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5393 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5395 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005397 if (DBG) {
5398 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5399 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5400 }
5401 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5402 cla, command, p1, p2, p3, data);
5403 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005404
Jordan Liu4c733742019-02-28 12:03:40 -08005405 @Override
5406 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5407 int command, int p1, int p2, int p3, String data) {
5408 enforceModifyPermission();
5409 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5410 if (DBG) {
5411 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5412 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5413 + " data=" + data);
5414 }
5415
5416 return iccTransmitApduBasicChannelWithPermission(
5417 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5418 p2, p3, data);
5419 }
5420
5421 // open APDU basic channel assuming the caller has sufficient permissions
5422 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5423 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5427 && TextUtils.equals(ISDR_AID, data)) {
5428 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005429 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5430 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 if (bestComponent == null
5432 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5433 loge("The calling package is not allowed to select ISD-R.");
5434 throw new SecurityException(
5435 "The calling package is not allowed to select ISD-R.");
5436 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005437 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005440 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5441 null /* workSource */);
5442 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 // Append the returned status code to the end of the response payload.
5445 String s = Integer.toHexString(
5446 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5447 if (response.payload != null) {
5448 s = IccUtils.bytesToHexString(response.payload) + s;
5449 }
5450 return s;
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005453 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005454 }
5455
5456 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005457 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005458 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5460 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 if (DBG) {
5465 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5466 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5467 }
5468
5469 IccIoResult response =
5470 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5471 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5472 subId);
5473
5474 if (DBG) {
5475 log("Exchange SIM_IO [R]" + response);
5476 }
5477
5478 byte[] result = null;
5479 int length = 2;
5480 if (response.payload != null) {
5481 length = 2 + response.payload.length;
5482 result = new byte[length];
5483 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5484 } else {
5485 result = new byte[length];
5486 }
5487
5488 result[length - 1] = (byte) response.sw2;
5489 result[length - 2] = (byte) response.sw1;
5490 return result;
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005493 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005494 }
5495
Nathan Haroldb3014052017-01-25 15:57:32 -08005496 /**
5497 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5498 * on a particular subscription
5499 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005500 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5501 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005503 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005504 return null;
5505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 if (appType != TelephonyManager.APPTYPE_USIM
5510 && appType != TelephonyManager.APPTYPE_SIM) {
5511 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5512 return null;
5513 }
5514 Object response = sendRequest(
5515 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5516 if (response instanceof String[]) {
5517 return (String[]) response;
5518 }
yincheng zhao2737e882019-09-06 17:06:54 -07005519 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005521 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 } finally {
5523 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005524 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005525 }
5526
yincheng zhao2737e882019-09-06 17:06:54 -07005527 /**
5528 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5529 * subscription.
5530 *
5531 * @param subId the id of the subscription.
5532 * @param appType the uicc app type, must be USIM or SIM.
5533 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5534 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005535 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005536 * @return number of fplmns that is successfully written to the SIM.
5537 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005538 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5539 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5541 mApp, subId, "setForbiddenPlmns");
5542
yincheng zhao2737e882019-09-06 17:06:54 -07005543 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5544 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5545 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5546 }
5547 if (fplmns == null) {
5548 throw new IllegalArgumentException("Fplmn List provided is null");
5549 }
5550 for (String fplmn : fplmns) {
5551 if (!CellIdentity.isValidPlmn(fplmn)) {
5552 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5553 }
5554 }
5555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 Object response = sendRequest(
5558 CMD_SET_FORBIDDEN_PLMNS,
5559 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5560 subId);
5561 return (int) response;
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
5564 }
5565 }
5566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005567 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005568 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5570 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 final long identity = Binder.clearCallingIdentity();
5573 try {
5574 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5575 if (response.payload == null) {
5576 return "";
5577 }
Evan Charltonc66da362014-05-16 14:06:40 -07005578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 // Append the returned status code to the end of the response payload.
5580 String s = Integer.toHexString(
5581 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5582 s = IccUtils.bytesToHexString(response.payload) + s;
5583 return s;
5584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Evan Charltonc66da362014-05-16 14:06:40 -07005587 }
5588
Jake Hambye994d462014-02-03 13:10:13 -08005589 /**
5590 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5591 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5592 *
5593 * @param itemID the ID of the item to read
5594 * @return the NV item as a String, or null on error.
5595 */
5596 @Override
5597 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5600 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601
5602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005605 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5607 return value;
5608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Jake Hambye994d462014-02-03 13:10:13 -08005611 }
5612
5613 /**
5614 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5615 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5616 *
5617 * @param itemID the ID of the item to read
5618 * @param itemValue the value to write, as a String
5619 * @return true on success; false on any failure
5620 */
5621 @Override
5622 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005623 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5625 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626
5627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5630 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005631 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5633 return success;
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Jake Hambye994d462014-02-03 13:10:13 -08005637 }
5638
5639 /**
5640 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5641 * Used for device configuration by some CDMA operators.
5642 *
5643 * @param preferredRoamingList byte array containing the new PRL
5644 * @return true on success; false on any failure
5645 */
5646 @Override
5647 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5649 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650
5651 final long identity = Binder.clearCallingIdentity();
5652 try {
5653 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5654 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5655 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5656 return success;
5657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Jake Hambye994d462014-02-03 13:10:13 -08005660 }
5661
5662 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005663 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005664 * Used for device configuration by some CDMA operators.
5665 *
chen xu6dac5ab2018-10-26 17:39:23 -07005666 * @param slotIndex - device slot.
5667 *
Jake Hambye994d462014-02-03 13:10:13 -08005668 * @return true on success; false on any failure
5669 */
5670 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005671 public boolean resetModemConfig(int slotIndex) {
5672 Phone phone = PhoneFactory.getPhone(slotIndex);
5673 if (phone != null) {
5674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5675 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676
chen xu6dac5ab2018-10-26 17:39:23 -07005677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5680 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5681 return success;
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 }
chen xu6dac5ab2018-10-26 17:39:23 -07005686 return false;
5687 }
5688
5689 /**
5690 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5691 *
5692 * @param slotIndex - device slot.
5693 *
5694 * @return true on success; false on any failure
5695 */
5696 @Override
5697 public boolean rebootModem(int slotIndex) {
5698 Phone phone = PhoneFactory.getPhone(slotIndex);
5699 if (phone != null) {
5700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5701 mApp, phone.getSubId(), "rebootModem");
5702
5703 final long identity = Binder.clearCallingIdentity();
5704 try {
5705 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5706 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5707 return success;
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
5711 }
5712 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005713 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005714
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 public String[] getPcscfAddress(String apnType, String callingPackage,
5716 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005717 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5719 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005720 return new String[0];
5721 }
5722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 final long identity = Binder.clearCallingIdentity();
5724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Wink Saville36469e72014-06-11 15:17:00 -07005729 }
5730
Brad Ebinger51f743a2017-01-23 13:50:20 -08005731 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005732 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5733 * {@link #disableIms(int)}.
5734 * @param slotIndex device slot.
5735 */
5736 public void resetIms(int slotIndex) {
5737 enforceModifyPermission();
5738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 if (mImsResolver == null) {
5742 // may happen if the does not support IMS.
5743 return;
5744 }
5745 mImsResolver.disableIms(slotIndex);
5746 mImsResolver.enableIms(slotIndex);
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
5750 }
5751
5752 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005753 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5754 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005755 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005756 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005761 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005762 // may happen if the device does not support IMS.
5763 return;
5764 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005765 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005769 }
5770
5771 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005772 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5773 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005774 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005775 public void disableIms(int slotId) {
5776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777
5778 final long identity = Binder.clearCallingIdentity();
5779 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005780 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005781 // may happen if the device does not support IMS.
5782 return;
5783 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005784 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005788 }
5789
5790 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005791 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5792 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005793 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005794 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005795 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797
5798 final long identity = Binder.clearCallingIdentity();
5799 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005800 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005801 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5802 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005803 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005804 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005808 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005809 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005810 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5811 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005812 @Override
5813 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005814 enforceModifyPermission();
5815
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005819 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
5823 }
5824
5825 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005826 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005827 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005828 */
5829 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5830 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831
5832 final long identity = Binder.clearCallingIdentity();
5833 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005835 // may happen if the device does not support IMS.
5836 return null;
5837 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005838 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005842 }
5843
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005844 /**
5845 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005846 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005847 */
5848 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5849 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850
5851 final long identity = Binder.clearCallingIdentity();
5852 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005853 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005854 // may happen if the device does not support IMS.
5855 return null;
5856 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005861 }
5862
Brad Ebinger884c07b2018-02-15 16:17:40 -08005863 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005864 * Sets the ImsService Package Name that Telephony will bind to.
5865 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 * @param slotIndex the slot ID that the ImsService should bind for.
5867 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005868 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 * @param featureTypes An integer array of feature types associated with a packageName.
5870 * @param packageName The name of the package that the current configuration will be replaced
5871 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005872 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5875 int[] featureTypes, String packageName) {
5876 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5879 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005884 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005885 // may happen if the device does not support IMS.
5886 return false;
5887 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005888 Map<Integer, String> featureConfig = new HashMap<>();
5889 for (int featureType : featureTypes) {
5890 featureConfig.put(featureType, packageName);
5891 }
5892 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5893 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005897 }
5898
5899 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005900 * Clears any carrier ImsService overrides for the slot index specified that were previously
5901 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5902 *
5903 * This should only be used for testing.
5904 *
5905 * @param slotIndex the slot ID that the ImsService should bind for.
5906 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5907 */
5908 @Override
5909 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5910 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5912 "clearCarrierImsServiceOverride");
5913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5914 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5915 "clearCarrierImsServiceOverride");
5916
5917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 if (mImsResolver == null) {
5920 // may happen if the device does not support IMS.
5921 return false;
5922 }
5923 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
5927 }
5928
5929 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005931 *
5932 * @param slotId The slot that the ImsService is associated with.
5933 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5934 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005936 * @return the package name of the ImsService configuration.
5937 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5939 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005940 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005942 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005943 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5944 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 final long identity = Binder.clearCallingIdentity();
5947 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005948 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005949 // may happen if the device does not support IMS.
5950 return "";
5951 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005952 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005953 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5954 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005958 }
5959
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005960 /**
5961 * Get the MmTelFeature state associated with the requested subscription id.
5962 * @param subId The subscription that the MmTelFeature is associated with.
5963 * @param callback A callback with an integer containing the
5964 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5965 */
5966 @Override
5967 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5968 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5969 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5970 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5971 "IMS not available on device.");
5972 }
5973 final long token = Binder.clearCallingIdentity();
5974 try {
5975 int slotId = getSlotIndex(subId);
5976 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5977 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5978 + subId + "'");
5979 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5980 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005981 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005982 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5983 try {
5984 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5985 } catch (RemoteException e) {
5986 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5987 + "Ignore");
5988 }
5989 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005990 } catch (ImsException e) {
5991 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005992 } finally {
5993 Binder.restoreCallingIdentity(token);
5994 }
5995 }
5996
Daniel Brightbb5840b2021-01-12 15:48:18 -08005997 /**
5998 * Sets the ims registration state on all valid {@link Phone}s.
5999 */
6000 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002
6003 final long identity = Binder.clearCallingIdentity();
6004 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006005 // NOTE: Before S, this method only set the default phone.
6006 for (final Phone phone : PhoneFactory.getPhones()) {
6007 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6008 phone.setImsRegistrationState(registered);
6009 }
6010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
Wink Saville36469e72014-06-11 15:17:00 -07006014 }
6015
6016 /**
Stuart Scott54788802015-03-30 13:18:01 -07006017 * Set the network selection mode to automatic.
6018 *
6019 */
6020 @Override
6021 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6023 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024
6025 final long identity = Binder.clearCallingIdentity();
6026 try {
shilufc958392020-01-20 11:36:01 -08006027 if (!isActiveSubscription(subId)) {
6028 return;
6029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006031 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6032 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
Stuart Scott54788802015-03-30 13:18:01 -07006036 }
6037
Jack Yud10cdd42020-09-28 20:28:01 -07006038 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006039 * Ask the radio to connect to the input network and change selection mode to manual.
6040 *
6041 * @param subId the id of the subscription.
6042 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6043 * the operator to attach to.
6044 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6045 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6046 * normal network selection next time.
6047 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006048 */
6049 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006050 public boolean setNetworkSelectionModeManual(
6051 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6053 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006054
6055 if (!isActiveSubscription(subId)) {
6056 return false;
6057 }
6058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 final long identity = Binder.clearCallingIdentity();
6060 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006061 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006063 if (DBG) {
6064 log("setNetworkSelectionModeManual: subId: " + subId
6065 + " operator: " + operatorInfo);
6066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006071 }
shilu84f6e8b2019-12-19 13:58:01 -08006072 /**
6073 * Get the manual network selection
6074 *
6075 * @param subId the id of the subscription.
6076 *
6077 * @return the previously saved user selected PLMN
6078 */
6079 @Override
6080 public String getManualNetworkSelectionPlmn(int subId) {
6081 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006082 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006083 mApp, subId, "getManualNetworkSelectionPlmn");
6084
6085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006088 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006089 }
6090
6091 final Phone phone = getPhone(subId);
6092 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006093 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006094 }
6095 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6096 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6097 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
6100 }
6101 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006102
6103 /**
6104 * Scans for available networks.
6105 */
6106 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006107 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6108 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6110 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006111 LocationAccessPolicy.LocationPermissionResult locationResult =
6112 LocationAccessPolicy.checkLocationPermission(mApp,
6113 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6114 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006115 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006116 .setCallingPid(Binder.getCallingPid())
6117 .setCallingUid(Binder.getCallingUid())
6118 .setMethod("getCellNetworkScanResults")
6119 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006120 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6121 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006122 .build());
6123 switch (locationResult) {
6124 case DENIED_HARD:
6125 throw new SecurityException("Not allowed to access scan results -- location");
6126 case DENIED_SOFT:
6127 return null;
6128 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129
Pengquan Menga1bb6272018-09-06 09:59:22 -07006130 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 try {
6132 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006133 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006138 }
6139
6140 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006141 * Get the call forwarding info, given the call forwarding reason.
6142 */
6143 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006144 public void getCallForwarding(int subId, int callForwardingReason,
6145 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006146 enforceReadPrivilegedPermission("getCallForwarding");
6147 long identity = Binder.clearCallingIdentity();
6148 try {
6149 if (DBG) {
6150 log("getCallForwarding: subId " + subId
6151 + " callForwardingReason" + callForwardingReason);
6152 }
Hall Liu27d24262020-09-18 19:04:59 -07006153
6154 Phone phone = getPhone(subId);
6155 if (phone == null) {
6156 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006157 callback.onError(
6158 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006159 } catch (RemoteException e) {
6160 // ignore
6161 }
6162 return;
6163 }
6164
6165 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6166 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6167 @Override
6168 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6169 try {
6170 callback.onCallForwardingInfoAvailable(info);
6171 } catch (RemoteException e) {
6172 // ignore
6173 }
6174 }
6175
6176 @Override
6177 public void onError(int error) {
6178 try {
6179 callback.onError(error);
6180 } catch (RemoteException e) {
6181 // ignore
6182 }
6183 }
6184 });
6185 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
6189 }
6190
6191 /**
6192 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6193 * reason, the number to forward, and the timeout before the forwarding is attempted.
6194 */
6195 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006196 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6197 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006198 enforceModifyPermission();
6199 long identity = Binder.clearCallingIdentity();
6200 try {
6201 if (DBG) {
6202 log("setCallForwarding: subId " + subId
6203 + " callForwardingInfo" + callForwardingInfo);
6204 }
Hall Liu27d24262020-09-18 19:04:59 -07006205
6206 Phone phone = getPhone(subId);
6207 if (phone == null) {
6208 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006209 callback.accept(
6210 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006211 } catch (RemoteException e) {
6212 // ignore
6213 }
6214 return;
6215 }
6216
6217 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6218 FunctionalUtils.ignoreRemoteException(callback::accept));
6219
6220 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006221 } finally {
6222 Binder.restoreCallingIdentity(identity);
6223 }
6224 }
6225
6226 /**
Hall Liu27d24262020-09-18 19:04:59 -07006227 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006228 */
6229 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006230 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006231 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006232 long identity = Binder.clearCallingIdentity();
6233 try {
Hall Liu27d24262020-09-18 19:04:59 -07006234 Phone phone = getPhone(subId);
6235 if (phone == null) {
6236 try {
6237 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6238 } catch (RemoteException e) {
6239 // ignore
6240 }
6241 return;
6242 }
SongFerngWang0e767992021-03-31 22:08:45 +08006243 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6244 PersistableBundle c = configManager.getConfigForSubId(subId);
6245 boolean requireUssd = c.getBoolean(
6246 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006247
Shuo Qian4a594052020-01-23 11:59:30 -08006248 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006249 if (requireUssd) {
6250 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6251 getSubscriptionCarrierId(subId));
6252 String newUssdCommand = "";
6253 try {
6254 newUssdCommand = carrierXmlParser.getFeature(
6255 CarrierXmlParser.FEATURE_CALL_WAITING)
6256 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6257 } catch (NullPointerException e) {
6258 loge("Failed to generate USSD number" + e);
6259 }
6260 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6261 mMainThreadHandler, callback, carrierXmlParser,
6262 CarrierXmlParser.SsEntry.SSAction.QUERY);
6263 final String ussdCommand = newUssdCommand;
6264 Executors.newSingleThreadExecutor().execute(() -> {
6265 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6266 });
6267 } else {
6268 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6269 callback::accept);
6270 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6271 }
Shuo Qian4a594052020-01-23 11:59:30 -08006272 } finally {
6273 Binder.restoreCallingIdentity(identity);
6274 }
6275 }
6276
6277 /**
Hall Liu27d24262020-09-18 19:04:59 -07006278 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006279 */
6280 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006281 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006282 enforceModifyPermission();
6283 long identity = Binder.clearCallingIdentity();
6284 try {
Hall Liu27d24262020-09-18 19:04:59 -07006285 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6286
6287 Phone phone = getPhone(subId);
6288 if (phone == null) {
6289 try {
6290 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6291 } catch (RemoteException e) {
6292 // ignore
6293 }
6294 return;
6295 }
6296
SongFerngWang0e767992021-03-31 22:08:45 +08006297 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6298 PersistableBundle c = configManager.getConfigForSubId(subId);
6299 boolean requireUssd = c.getBoolean(
6300 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006301
SongFerngWang0e767992021-03-31 22:08:45 +08006302 if (DBG) log("getCallWaitingStatus: subId " + subId);
6303 if (requireUssd) {
6304 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6305 getSubscriptionCarrierId(subId));
6306 CarrierXmlParser.SsEntry.SSAction ssAction =
6307 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6308 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6309 String newUssdCommand = "";
6310 try {
6311 newUssdCommand = carrierXmlParser.getFeature(
6312 CarrierXmlParser.FEATURE_CALL_WAITING)
6313 .makeCommand(ssAction, null);
6314 } catch (NullPointerException e) {
6315 loge("Failed to generate USSD number" + e);
6316 }
6317 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6318 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6319 final String ussdCommand = newUssdCommand;
6320 Executors.newSingleThreadExecutor().execute(() -> {
6321 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6322 });
6323 } else {
6324 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6325 FunctionalUtils.ignoreRemoteException(callback::accept));
6326
6327 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6328 }
Shuo Qian4a594052020-01-23 11:59:30 -08006329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 }
6333
6334 /**
yinxub1bed742017-04-17 11:45:04 -07006335 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006336 *
yinxub1bed742017-04-17 11:45:04 -07006337 * @param subId id of the subscription
6338 * @param request contains the radio access networks with bands/channels to scan
6339 * @param messenger callback messenger for scan results or errors
6340 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006341 * @return the id of the requested scan which can be used to stop the scan.
6342 */
6343 @Override
6344 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006345 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6347 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006348 LocationAccessPolicy.LocationPermissionResult locationResult =
6349 LocationAccessPolicy.checkLocationPermission(mApp,
6350 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6351 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006352 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006353 .setCallingPid(Binder.getCallingPid())
6354 .setCallingUid(Binder.getCallingUid())
6355 .setMethod("requestNetworkScan")
6356 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006357 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6358 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006359 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006360 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006361 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6362 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006363 if (e != null) {
6364 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6365 throw e;
6366 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006367 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006368 return TelephonyScanManager.INVALID_SCAN_ID;
6369 }
6370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 }
Hall Liu912dfd32019-04-25 14:02:26 -07006372 int callingUid = Binder.getCallingUid();
6373 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 return mNetworkScanRequestTracker.startNetworkScan(
6377 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006378 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
yinxu504e1392017-04-12 16:03:22 -07006382 }
6383
Hall Liub2ac8ef2019-02-28 15:56:23 -08006384 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006385 NetworkScanRequest request, int subId, String callingPackage) {
6386 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006387 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6388 boolean hasNetworkScanPermission =
6389 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6390 == PERMISSION_GRANTED;
6391
6392 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6393 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6394 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006395 }
6396
6397 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6398 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006399 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6400 return new SecurityException("Specific channels must not be"
6401 + " scanned without location access.");
6402 }
6403 }
6404 }
6405
Hall Liub2ac8ef2019-02-28 15:56:23 -08006406 return null;
6407 }
6408
yinxu504e1392017-04-12 16:03:22 -07006409 /**
6410 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006411 *
6412 * @param subId id of the subscription
6413 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006414 */
6415 @Override
6416 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6418 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419
Hall Liu912dfd32019-04-25 14:02:26 -07006420 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 final long identity = Binder.clearCallingIdentity();
6422 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006423 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
yinxu504e1392017-04-12 16:03:22 -07006427 }
6428
6429 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006430 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006431 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006432 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006433 */
6434 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006435 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006436 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006437 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006438 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439
6440 final long identity = Binder.clearCallingIdentity();
6441 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006442 if (DBG) log("getAllowedNetworkTypesBitmask");
6443 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6444 int networkTypesBitmask = (result != null ? result[0] : -1);
6445 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6446 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006450 }
6451
6452 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006453 * Get the allowed network types for certain reason.
6454 *
6455 * @param subId the id of the subscription.
6456 * @param reason the reason the allowed network type change is taking place
6457 * @return the allowed network types.
6458 */
6459 @Override
6460 public long getAllowedNetworkTypesForReason(int subId,
6461 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006462 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006463 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006473 * Enable/Disable E-UTRA-NR Dual Connectivity
6474 * @param subId subscription id of the sim card
6475 * @param nrDualConnectivityState expected NR dual connectivity state
6476 * This can be passed following states
6477 * <ol>
6478 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6479 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6480 * <li>Disable NR dual connectivity and force secondary cell to be released
6481 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6482 * </ol>
6483 * @return operation result.
6484 */
6485 @Override
6486 public int setNrDualConnectivityState(int subId,
6487 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6489 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006490 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006491 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6492 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6493 }
6494
Sooraj Sasindran37444802020-08-11 10:40:43 -07006495 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6499 nrDualConnectivityState, subId,
6500 workSource);
6501 if (DBG) log("enableNRDualConnectivity result: " + result);
6502 return result;
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 /**
6509 * Is E-UTRA-NR Dual Connectivity enabled
6510 * @return true if dual connectivity is enabled else false
6511 */
6512 @Override
6513 public boolean isNrDualConnectivityEnabled(int subId) {
6514 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006515 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006516 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006517 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006518 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6519 return false;
6520 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6522 final long identity = Binder.clearCallingIdentity();
6523 try {
6524 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6525 null, subId, workSource);
6526 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6527 return isEnabled;
6528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
6531 }
6532
6533 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006534 * Set the allowed network types of the device and
6535 * provide the reason triggering the allowed network change.
6536 *
6537 * @param subId the id of the subscription.
6538 * @param reason the reason the allowed network type change is taking place
6539 * @param allowedNetworkTypes the allowed network types.
6540 * @return true on success; false on any failure.
6541 */
6542 @Override
6543 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006544 @TelephonyManager.AllowedNetworkTypesReason int reason,
6545 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6547 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006548 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006549 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6550 return false;
6551 }
6552 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6553 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 return false;
6555 }
6556
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006557 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6558 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6559
6560
6561 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6562 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6563 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006564 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006565
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006566 final long identity = Binder.clearCallingIdentity();
6567 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006568 Boolean success = (Boolean) sendRequest(
6569 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6570 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6571
6572 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6573 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
6577 }
6578
6579 /**
Miaoa84611c2019-03-15 09:21:10 +08006580 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006581 *
Miaoa84611c2019-03-15 09:21:10 +08006582 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006583 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006584 * @hide
6585 */
6586 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006587 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006590 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 try {
Miaoa84611c2019-03-15 09:21:10 +08006592 if (phone != null) {
6593 return phone.hasMatchedTetherApnSetting();
6594 } else {
6595 return false;
6596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 } finally {
6598 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006599 }
Junda Liu475951f2014-11-07 16:45:03 -08006600 }
6601
6602 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006603 * Get the user enabled state of Mobile Data.
6604 *
6605 * TODO: remove and use isUserDataEnabled.
6606 * This can't be removed now because some vendor codes
6607 * calls through ITelephony directly while they should
6608 * use TelephonyManager.
6609 *
6610 * @return true on enabled
6611 */
6612 @Override
6613 public boolean getDataEnabled(int subId) {
6614 return isUserDataEnabled(subId);
6615 }
6616
6617 /**
6618 * Get whether mobile data is enabled per user setting.
6619 *
6620 * There are other factors deciding whether mobile data is actually enabled, but they are
6621 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006622 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006623 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006624 *
6625 * @return {@code true} if data is enabled else {@code false}
6626 */
6627 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006628 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006629 try {
6630 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6631 null);
6632 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6634 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 int phoneId = mSubscriptionController.getPhoneId(subId);
6640 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6641 Phone phone = PhoneFactory.getPhone(phoneId);
6642 if (phone != null) {
6643 boolean retVal = phone.isUserDataEnabled();
6644 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6645 return retVal;
6646 } else {
6647 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6648 return false;
6649 }
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006652 }
6653 }
6654
6655 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006656 * Checks if the device is capable of mobile data by considering whether whether the
6657 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6658 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006659 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006660 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006661 */
6662 @Override
6663 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006664 try {
6665 try {
6666 mApp.enforceCallingOrSelfPermission(
6667 android.Manifest.permission.ACCESS_NETWORK_STATE,
6668 null);
6669 } catch (Exception e) {
6670 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6671 "isDataEnabled");
6672 }
6673 } catch (Exception e) {
6674 enforceReadPrivilegedPermission("isDataEnabled");
6675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676
6677 final long identity = Binder.clearCallingIdentity();
6678 try {
6679 int phoneId = mSubscriptionController.getPhoneId(subId);
6680 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6681 Phone phone = PhoneFactory.getPhone(phoneId);
6682 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006683 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6685 return retVal;
6686 } else {
6687 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6688 return false;
6689 }
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006692 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006693 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006694
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006695 /**
6696 * Check if data is enabled for a specific reason
6697 * @param subId Subscription index
6698 * @param reason the reason the data enable change is taking place
6699 * @return {@code true} if the overall data is enabled; {@code false} if not.
6700 */
6701 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006702 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006703 @TelephonyManager.DataEnabledReason int reason) {
6704 try {
6705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6706 null);
6707 } catch (Exception e) {
6708 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006709 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 }
6711
6712
6713 final long identity = Binder.clearCallingIdentity();
6714 try {
6715 int phoneId = mSubscriptionController.getPhoneId(subId);
6716 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006717 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006718 + " reason=" + reason);
6719 }
6720 Phone phone = PhoneFactory.getPhone(phoneId);
6721 if (phone != null) {
6722 boolean retVal;
6723 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6724 retVal = phone.isUserDataEnabled();
6725 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006726 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006727 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006728 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006729 return retVal;
6730 } else {
6731 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006732 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006733 + subId + " retVal=false");
6734 }
6735 return false;
6736 }
6737 } finally {
6738 Binder.restoreCallingIdentity(identity);
6739 }
6740 }
6741
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006742 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006743 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006744 if (uid == Process.PHONE_UID) {
6745 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6746 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6748 }
6749
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006750 //load access rules from carrier configs, and check those as well: b/139133814
6751 SubscriptionController subController = SubscriptionController.getInstance();
6752 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6753 || subController == null) return privilegeFromSim;
6754
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006755 PackageManager pkgMgr = phone.getContext().getPackageManager();
6756 String[] packages = pkgMgr.getPackagesForUid(uid);
6757
6758 final long identity = Binder.clearCallingIdentity();
6759 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006760 int subId = phone.getSubId();
6761 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6762 // A test override is in place for the privileges for this subId, so don't try to
6763 // read the subscription privileges.
6764 return privilegeFromSim;
6765 }
6766 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006767 SubscriptionManager subManager = (SubscriptionManager)
6768 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6769 for (String pkg : packages) {
6770 if (subManager.canManageSubscription(subInfo, pkg)) {
6771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6772 }
6773 }
6774 return privilegeFromSim;
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
6778 }
6779
6780 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6781 String pkgName) {
6782 //load access rules from carrier configs, and check those as well: b/139133814
6783 SubscriptionController subController = SubscriptionController.getInstance();
6784 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6785 || subController == null) return privilegeFromSim;
6786
6787 final long identity = Binder.clearCallingIdentity();
6788 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006789 int subId = phone.getSubId();
6790 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6791 // A test override is in place for the privileges for this subId, so don't try to
6792 // read the subscription privileges.
6793 return privilegeFromSim;
6794 }
6795 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006796 SubscriptionManager subManager = (SubscriptionManager)
6797 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6798 return subManager.canManageSubscription(subInfo, pkgName)
6799 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6800 } finally {
6801 Binder.restoreCallingIdentity(identity);
6802 }
6803 }
6804
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006805 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006806 public int getCarrierPrivilegeStatus(int subId) {
6807 final Phone phone = getPhone(subId);
6808 if (phone == null) {
6809 loge("getCarrierPrivilegeStatus: Invalid subId");
6810 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6811 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006812 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6813 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006814 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6816 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006817
6818 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006819 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006820 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006821 }
Junda Liu29340342014-07-10 15:23:27 -07006822
6823 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006824 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006825 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006826 final Phone phone = getPhone(subId);
6827 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006828 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006829 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6830 }
6831 UiccProfile profile =
6832 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6833 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006834 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006835 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6836 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006837 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006838 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006839 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 }
6841
6842 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006843 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006844 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006845 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006847 }
6848
6849 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006850 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6851 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006852 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006853 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6854 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006855 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006856 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006857 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006858 }
6859
6860 @Override
6861 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006862 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006863 if (TextUtils.isEmpty(pkgName))
6864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006865 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6866 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006867 UiccPort port = UiccController.getInstance().getUiccPort(i);
6868 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006869 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006870 continue;
6871 }
6872
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006873 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006874 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006875 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006876 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6877 break;
6878 }
6879 }
6880
6881 return result;
Junda Liu29340342014-07-10 15:23:27 -07006882 }
Derek Tan89e89d42014-07-08 17:00:10 -07006883
6884 @Override
Junda Liue64de782015-04-16 17:19:16 -07006885 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006886 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006887 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6888 loge("phoneId " + phoneId + " is not valid.");
6889 return null;
6890 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006891 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6892 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006893 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006894 return null ;
6895 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006896 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006897 }
6898
Amith Yamasani6e118872016-02-19 12:53:51 -08006899 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006900 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006901 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006902 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006903 List<String> privilegedPackages = new ArrayList<>();
6904 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006905 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006906 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006907 if (port != null) {
6908 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006909 if (packages == null) {
6910 // Only check packages in user 0 for now
6911 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006912 PackageManager.MATCH_DISABLED_COMPONENTS
6913 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006914 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006915 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006916 }
6917 for (int p = packages.size() - 1; p >= 0; p--) {
6918 PackageInfo pkgInfo = packages.get(p);
6919 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006920 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6921 port.getCarrierPrivilegeStatus(pkgInfo),
6922 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006923 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006924 privilegedPackages.add(pkgInfo.packageName);
6925 }
6926 }
6927 }
6928 }
6929 return privilegedPackages;
6930 }
6931
chen xuf7e9fe82019-05-09 19:31:02 -07006932 @Override
6933 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006934 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6935
6936 final long identity = Binder.clearCallingIdentity();
6937
chen xuf7e9fe82019-05-09 19:31:02 -07006938 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006939 try {
6940 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6941 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6942 }
6943 } finally {
6944 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006945 }
6946 return privilegedPackages;
6947 }
6948
Wink Savilleb564aae2014-10-23 10:18:09 -07006949 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006950 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006951 UiccPort port = phone == null ? null : phone.getUiccPort();
6952 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006953 return null;
6954 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006955 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006956 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006957 return null;
6958 }
6959 return iccId;
6960 }
6961
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006962 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006963 public void setCallComposerStatus(int subId, int status) {
6964 enforceModifyPermission();
6965
6966 final long identity = Binder.clearCallingIdentity();
6967 try {
6968 Phone phone = getPhone(subId);
6969 if (phone != null) {
6970 Phone defaultPhone = phone.getImsPhone();
6971 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6972 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6973 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006974 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6975 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006976 }
6977 }
Shuo Qian284ae752020-12-22 19:10:14 -08006978 } catch (ImsException e) {
6979 throw new ServiceSpecificException(e.getCode());
6980 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006981 Binder.restoreCallingIdentity(identity);
6982 }
6983 }
6984
6985 @Override
6986 public int getCallComposerStatus(int subId) {
6987 enforceReadPrivilegedPermission("getCallComposerStatus");
6988
6989 final long identity = Binder.clearCallingIdentity();
6990 try {
6991 Phone phone = getPhone(subId);
6992 if (phone != null) {
6993 Phone defaultPhone = phone.getImsPhone();
6994 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6995 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6996 return imsPhone.getCallComposerStatus();
6997 }
6998 }
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
7002 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7003 }
7004
7005 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007006 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7007 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007008 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007009 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007011 final long identity = Binder.clearCallingIdentity();
7012 try {
7013 final String iccId = getIccId(subId);
7014 final Phone phone = getPhone(subId);
7015 if (phone == null) {
7016 return false;
7017 }
7018 final String subscriberId = phone.getSubscriberId();
7019
7020 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007021 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 + subscriberId + " to " + number);
7023 }
7024
7025 if (TextUtils.isEmpty(iccId)) {
7026 return false;
7027 }
7028
7029 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7030
7031 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7032 if (alphaTag == null) {
7033 editor.remove(alphaTagPrefKey);
7034 } else {
7035 editor.putString(alphaTagPrefKey, alphaTag);
7036 }
7037
7038 // Record both the line number and IMSI for this ICCID, since we need to
7039 // track all merged IMSIs based on line number
7040 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7041 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7042 if (number == null) {
7043 editor.remove(numberPrefKey);
7044 editor.remove(subscriberPrefKey);
7045 } else {
7046 editor.putString(numberPrefKey, number);
7047 editor.putString(subscriberPrefKey, subscriberId);
7048 }
7049
7050 editor.commit();
7051 return true;
7052 } finally {
7053 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007054 }
Derek Tan7226c842014-07-02 17:42:23 -07007055 }
7056
7057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007058 public String getLine1NumberForDisplay(int subId, String callingPackage,
7059 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007060 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007062 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007063 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007064 return null;
7065 }
Derek Tan97ebb422014-09-05 16:55:38 -07007066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 final long identity = Binder.clearCallingIdentity();
7068 try {
7069 String iccId = getIccId(subId);
7070 if (iccId != null) {
7071 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7072 if (DBG_MERGE) {
7073 log("getLine1NumberForDisplay returning "
7074 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7075 }
7076 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7079 return null;
7080 } finally {
7081 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007082 }
Derek Tan7226c842014-07-02 17:42:23 -07007083 }
7084
7085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007086 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7087 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007089 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007090 return null;
7091 }
Derek Tan97ebb422014-09-05 16:55:38 -07007092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 final long identity = Binder.clearCallingIdentity();
7094 try {
7095 String iccId = getIccId(subId);
7096 if (iccId != null) {
7097 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7098 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7099 }
7100 return null;
7101 } finally {
7102 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007103 }
Derek Tan7226c842014-07-02 17:42:23 -07007104 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007105
7106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007107 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7108 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007109 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7110 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007112 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007113 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007114 return null;
7115 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007116
Jordan Liub49b04b2019-05-06 14:45:15 -07007117 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7118 // the process, where TelephonyManager was instantiated.
7119 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007120 final long identity = Binder.clearCallingIdentity();
7121 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007122 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 final TelephonyManager tele = TelephonyManager.from(context);
7124 final SubscriptionManager sub = SubscriptionManager.from(context);
7125
7126 // Figure out what subscribers are currently active
7127 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128
Jordan Liub49b04b2019-05-06 14:45:15 -07007129 // Only consider subs which match the current subId
7130 // This logic can be simplified. See b/131189269 for progress.
7131 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007132 activeSubscriberIds.add(tele.getSubscriberId(subId));
7133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134
7135 // First pass, find a number override for an active subscriber
7136 String mergeNumber = null;
7137 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7138 for (String key : prefs.keySet()) {
7139 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7140 final String subscriberId = (String) prefs.get(key);
7141 if (activeSubscriberIds.contains(subscriberId)) {
7142 final String iccId = key.substring(
7143 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7144 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7145 mergeNumber = (String) prefs.get(numberKey);
7146 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007147 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148 + " for active subscriber " + subscriberId);
7149 }
7150 if (!TextUtils.isEmpty(mergeNumber)) {
7151 break;
7152 }
7153 }
7154 }
7155 }
7156
7157 // Shortcut when no active merged subscribers
7158 if (TextUtils.isEmpty(mergeNumber)) {
7159 return null;
7160 }
7161
7162 // Second pass, find all subscribers under that line override
7163 final ArraySet<String> result = new ArraySet<>();
7164 for (String key : prefs.keySet()) {
7165 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7166 final String number = (String) prefs.get(key);
7167 if (mergeNumber.equals(number)) {
7168 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7169 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7170 final String subscriberId = (String) prefs.get(subscriberKey);
7171 if (!TextUtils.isEmpty(subscriberId)) {
7172 result.add(subscriberId);
7173 }
7174 }
7175 }
7176 }
7177
7178 final String[] resultArray = result.toArray(new String[result.size()]);
7179 Arrays.sort(resultArray);
7180 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007181 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7183 }
7184 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007185 } finally {
7186 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007187 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007188 }
7189
7190 @Override
zoey chen38003472019-12-13 17:16:31 +08007191 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7192 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007193
7194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 final TelephonyManager telephonyManager = mApp.getSystemService(
7197 TelephonyManager.class);
7198 String subscriberId = telephonyManager.getSubscriberId(subId);
7199 if (subscriberId == null) {
7200 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007201 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007202 + subId);
7203 }
7204 return null;
7205 }
7206
7207 final SubscriptionInfo info = SubscriptionController.getInstance()
7208 .getSubscriptionInfo(subId);
7209 final ParcelUuid groupUuid = info.getGroupUuid();
7210 // If it doesn't belong to any group, return just subscriberId of itself.
7211 if (groupUuid == null) {
7212 return new String[]{subscriberId};
7213 }
7214
7215 // Get all subscriberIds from the group.
7216 final List<String> mergedSubscriberIds = new ArrayList<>();
7217 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007218 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007219 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007220 for (SubscriptionInfo subInfo : groupInfos) {
7221 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7222 if (subscriberId != null) {
7223 mergedSubscriberIds.add(subscriberId);
7224 }
7225 }
7226
7227 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7228 } finally {
7229 Binder.restoreCallingIdentity(identity);
7230
7231 }
7232 }
7233
7234 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007235 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007236 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007237 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238
7239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 final Phone phone = getPhone(subId);
7242 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007246 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007247
7248 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007249 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007250 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7251 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007252 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7253 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254
7255 final long identity = Binder.clearCallingIdentity();
7256 try {
7257 final Phone phone = getPhone(subId);
7258 if (phone == null) {
7259 return false;
7260 }
7261 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7262 cdmaNonRoamingList);
7263 } finally {
7264 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007265 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007266 }
7267
7268 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007269 @Deprecated
7270 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7271 enforceModifyPermission();
7272
7273 int returnValue = 0;
7274 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007275 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007276 if(result.exception == null) {
7277 if (result.result != null) {
7278 byte[] responseData = (byte[])(result.result);
7279 if(responseData.length > oemResp.length) {
7280 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7281 responseData.length + "bytes. Buffer Size is " +
7282 oemResp.length + "bytes.");
7283 }
7284 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7285 returnValue = responseData.length;
7286 }
7287 } else {
7288 CommandException ex = (CommandException) result.exception;
7289 returnValue = ex.getCommandError().ordinal();
7290 if(returnValue > 0) returnValue *= -1;
7291 }
7292 } catch (RuntimeException e) {
7293 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7294 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7295 if(returnValue > 0) returnValue *= -1;
7296 }
7297
7298 return returnValue;
7299 }
7300
7301 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007302 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007303 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007304 try {
7305 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007306 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007307 mApp, phone.getSubId(), "getRadioAccessFamily");
7308 } catch (SecurityException e) {
7309 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7310 throw e;
7311 }
chen xub97461a2018-10-26 14:17:57 -07007312 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007313 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007314 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007316 final long identity = Binder.clearCallingIdentity();
7317 try {
chen xub97461a2018-10-26 14:17:57 -07007318 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007319 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007320 mApp, phone.getSubId(), "getRadioAccessFamily");
7321 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 } finally {
7323 Binder.restoreCallingIdentity(identity);
7324 }
chen xub97461a2018-10-26 14:17:57 -07007325 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007326 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007327
7328 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007329 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007330 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007331 try {
7332 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7333 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007334 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007335 }
7336 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007337 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007338 }
7339 RoleManager rm = mApp.getSystemService(RoleManager.class);
7340 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7341 if (!dialerRoleHolders.contains(callingPackage)) {
7342 throw new SecurityException("App must be the dialer role holder to"
7343 + " upload a call composer pic");
7344 }
7345
7346 Executors.newSingleThreadExecutor().execute(() -> {
7347 ByteArrayOutputStream output = new ByteArrayOutputStream(
7348 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7349 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7350 boolean readUntilEnd = false;
7351 int totalBytesRead = 0;
7352 byte[] buffer = new byte[16 * 1024];
7353 while (true) {
7354 int numRead;
7355 try {
7356 numRead = input.read(buffer);
7357 } catch (IOException e) {
7358 try {
7359 fd.checkError();
7360 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7361 null);
7362 } catch (IOException e1) {
7363 // This means that the other side closed explicitly with an error. If this
7364 // happens, log and ignore.
7365 loge("Remote end of call composer picture pipe closed: " + e1);
7366 }
7367 break;
7368 }
7369 if (numRead == -1) {
7370 readUntilEnd = true;
7371 break;
7372 }
7373 totalBytesRead += numRead;
7374 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7375 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7376 try {
7377 input.close();
7378 } catch (IOException e) {
7379 // ignore
7380 }
7381 break;
7382 }
7383 output.write(buffer, 0, numRead);
7384 }
7385 // Generally, the remote end will close the file descriptors. The only case where we
7386 // close is above, where the picture size is too big.
7387
7388 try {
7389 fd.checkError();
7390 } catch (IOException e) {
7391 loge("Remote end for call composer closed with an error: " + e);
7392 return;
7393 }
7394
Hall Liuaa4211e2021-01-20 15:43:39 -08007395 if (!readUntilEnd) {
7396 loge("Did not finish reading entire image; aborting");
7397 return;
7398 }
Hall Liu82694d52020-12-11 18:22:04 -08007399
Hall Liuaa4211e2021-01-20 15:43:39 -08007400 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7401 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7402 new CallComposerPictureTransfer.Factory() {},
7403 imageData,
7404 (result) -> {
7405 if (result.first != null) {
7406 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7407 Bundle outputResult = new Bundle();
7408 outputResult.putParcelable(
7409 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7410 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7411 outputResult);
7412 } else {
7413 callback.send(result.second, null);
7414 }
7415 }
7416 );
Hall Liu82694d52020-12-11 18:22:04 -08007417 });
7418 }
7419
7420 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007421 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007422 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007423 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424
7425 final long identity = Binder.clearCallingIdentity();
7426 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 ImsManager.getInstance(defaultPhone.getContext(),
7428 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007432 }
7433
7434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007435 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007436 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7438 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007439 return false;
7440 }
Svet Ganovb320e182015-04-16 12:30:10 -07007441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 final long identity = Binder.clearCallingIdentity();
7443 try {
7444 // Check the user preference and the system-level IMS setting. Even if the user has
7445 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7446 // In the long run, we may instead need to check if there exists a connection service
7447 // which can support video calling.
7448 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 return imsManager.isVtEnabledByPlatform()
7451 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7452 && imsManager.isVtEnabledByUser();
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007456 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007457
Andrew Leea1239f22015-03-02 17:44:07 -08007458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007459 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7460 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007462 mApp, subId, callingPackage, callingFeatureId,
7463 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 return false;
7465 }
7466
7467 final long identity = Binder.clearCallingIdentity();
7468 try {
7469 CarrierConfigManager configManager =
7470 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007471 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7473 } finally {
7474 Binder.restoreCallingIdentity(identity);
7475 }
Andrew Leea1239f22015-03-02 17:44:07 -08007476 }
7477
7478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007479 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 return false;
7483 }
7484
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
7487 CarrierConfigManager configManager =
7488 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007489 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
Andrew Leea1239f22015-03-02 17:44:07 -08007494 }
7495
Andrew Lee9431b832015-03-09 18:46:45 -07007496 @Override
7497 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007498 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007499 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007500 }
7501
7502 @Override
7503 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 final long identity = Binder.clearCallingIdentity();
7505 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007506 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
Andrew Lee9431b832015-03-09 18:46:45 -07007510 }
7511
Hall Liuf6668912018-10-31 17:05:23 -07007512 /**
7513 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7514 * support for the feature and device firmware support.
7515 *
7516 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7517 */
7518 @Override
7519 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007521 final Phone phone = getPhone(subscriptionId);
7522 if (phone == null) {
7523 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7524 return false;
7525 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007527 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7529 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007530 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 return isCarrierSupported && isDeviceSupported;
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
Hall Liu98187582018-01-22 19:15:32 -08007535 }
7536
Hall Liuf6668912018-10-31 17:05:23 -07007537 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007538 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7539 * RTT setting, will return true if the device and carrier both support RTT.
7540 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007541 */
7542 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 final long identity = Binder.clearCallingIdentity();
7544 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007545 boolean isRttSupported = isRttSupported(subscriptionId);
7546 boolean isUserRttSettingOn = Settings.Secure.getInt(
7547 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7548 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7549 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7550 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007554 }
7555
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007556 @Deprecated
7557 @Override
7558 public String getDeviceId(String callingPackage) {
7559 return getDeviceIdWithFeature(callingPackage, null);
7560 }
7561
Sanket Padawe7310cc72015-01-14 09:53:20 -08007562 /**
7563 * Returns the unique device ID of phone, for example, the IMEI for
7564 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7565 *
7566 * <p>Requires Permission:
7567 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7568 */
7569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007570 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007571 try {
7572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7573 } catch (SecurityException se) {
7574 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7575 throw new SecurityException("Package " + callingPackage + " does not belong to "
7576 + Binder.getCallingUid());
7577 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007578 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007579 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007580 return null;
7581 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007582 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007583 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007584 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007585 return null;
7586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587
7588 final long identity = Binder.clearCallingIdentity();
7589 try {
7590 return phone.getDeviceId();
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007594 }
7595
Ping Sunc67b7c22016-03-02 19:16:45 +08007596 /**
7597 * {@hide}
7598 * Returns the IMS Registration Status on a particular subid
7599 *
7600 * @param subId
7601 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007602 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007603 Phone phone = getPhone(subId);
7604 if (phone != null) {
7605 return phone.isImsRegistered();
7606 } else {
7607 return false;
7608 }
7609 }
7610
Santos Cordon7a1885b2015-02-03 11:15:19 -08007611 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007612 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007613 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007615 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007616 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7617 }
7618 final long identity = Binder.clearCallingIdentity();
7619 try {
7620 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
7625
7626 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007627 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007628 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007629 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007630 mApp,
7631 subscriptionId,
7632 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 Phone phone = getPhone(subscriptionId);
7636 if (phone == null) {
7637 return null;
7638 }
7639 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7640 } finally {
7641 Binder.restoreCallingIdentity(identity);
7642 }
7643 }
7644
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007645 /**
7646 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007647 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007648 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 Phone phone = getPhone(subId);
7652 if (phone != null) {
7653 return phone.isWifiCallingEnabled();
7654 } else {
7655 return false;
7656 }
7657 } finally {
7658 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007659 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007660 }
7661
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007664 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007665 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 Phone phone = getPhone(subId);
7669 if (phone != null) {
7670 return phone.isVideoEnabled();
7671 } else {
7672 return false;
7673 }
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007676 }
7677 }
7678
7679 /**
7680 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7681 * defined in {@link ImsRegistrationImplBase}.
7682 */
7683 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684 final long identity = Binder.clearCallingIdentity();
7685 try {
7686 Phone phone = getPhone(subId);
7687 if (phone != null) {
7688 return phone.getImsRegistrationTech();
7689 } else {
7690 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7691 }
7692 } finally {
7693 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007694 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007695 }
7696
Stuart Scott8eef64f2015-04-08 15:13:54 -07007697 @Override
7698 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007699 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007700 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7701 return;
7702 }
Kai Shif70f46f2021-03-03 13:59:46 -08007703 Phone defaultPhone = getDefaultPhone();
7704 if (defaultPhone != null) {
7705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7706 mApp, getDefaultPhone().getSubId(), "factoryReset");
7707 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007708 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007709
Svet Ganovcc087f82015-05-12 20:35:54 -07007710 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007711 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7712 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007713 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007714 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007715 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007716 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007717 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007718 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007719 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007720 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007721 // There has been issues when Sms raw table somehow stores orphan
7722 // fragments. They lead to garbled message when new fragments come
7723 // in and combined with those stale ones. In case this happens again,
7724 // user can reset all network settings which will clean up this table.
7725 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007726 // Clean up IMS settings as well here.
7727 int slotId = getSlotIndex(subId);
7728 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7729 ImsManager.getInstance(mApp, slotId).factoryReset();
7730 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007731
Kai Shif70f46f2021-03-03 13:59:46 -08007732 if (defaultPhone == null) {
7733 return;
7734 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007735 // Erase modem config if erase modem on network setting is enabled.
7736 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7737 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7738 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007739 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007740 }
Kai Shif70f46f2021-03-03 13:59:46 -08007741
7742 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007743 } finally {
7744 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007745 }
7746 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007747
SongFerngWangfd89b102021-05-27 22:44:54 +08007748 @VisibleForTesting
7749 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7750 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7751 return;
7752 }
7753 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7754 RILConstants.PREFERRED_NETWORK_MODE);
7755 SubscriptionManager.setSubscriptionProperty(subId,
7756 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7757 "user=" + defaultNetworkType);
7758 phone.loadAllowedNetworksFromSubscriptionDatabase();
7759 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7760 defaultNetworkType, null);
7761 }
7762
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007763 private void cleanUpSmsRawTable(Context context) {
7764 ContentResolver resolver = context.getContentResolver();
7765 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7766 resolver.delete(uri, null, null);
7767 }
7768
Narayan Kamath1c496c22015-04-16 14:40:19 +01007769 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007770 public String getSimLocaleForSubscriber(int subId) {
7771 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7772 final Phone phone = getPhone(subId);
7773 if (phone == null) {
7774 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007775 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 final long identity = Binder.clearCallingIdentity();
7778 try {
chen xu5d3637b2019-01-21 23:31:38 -08007779 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007780 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007781 if (info == null) {
7782 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7783 return null;
7784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 // Try and fetch the locale from the carrier properties or from the SIM language
7786 // preferences (EF-PL and EF-LI)...
7787 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007789 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7790 if (localeFromDefaultSim != null) {
7791 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7792 if (DBG) log("Using locale from subId: " + subId + " locale: "
7793 + localeFromDefaultSim);
7794 return localeFromDefaultSim.toLanguageTag();
7795 } else {
7796 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 }
7798 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 // The SIM language preferences only store a language (e.g. fr = French), not an
7801 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7802 // the SIM and carrier preferences does not include a country we add the country
7803 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007804 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007806 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807 return mccLocale.toLanguageTag();
7808 }
7809
7810 if (DBG) log("No locale found - returning null");
7811 return null;
7812 } finally {
7813 Binder.restoreCallingIdentity(identity);
7814 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007815 }
7816
7817 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007818 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007819 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007820 }
7821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 /**
7823 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7824 */
7825 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007826 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007827 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007828 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007829
Chenjie Yu1ba97252018-01-11 18:16:20 -08007830 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007831 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007832
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007833 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007834 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7835 * representing the state of the modem.
7836 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007837 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7838 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007839 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007840 */
7841 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007842 public void requestModemActivityInfo(ResultReceiver result) {
7843 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007844 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845
7846 final long identity = Binder.clearCallingIdentity();
7847 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007848 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 } finally {
7850 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007851 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007852 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007853
Siddharth Rayb8114062018-06-17 15:02:38 -07007854 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7855 // less than total activity duration.
7856 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7857 if (info == null) {
7858 return false;
7859 }
7860 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007861 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7862 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7863
Siddharth Rayb8114062018-06-17 15:02:38 -07007864 return (info.isValid()
7865 && (info.getSleepTimeMillis() <= activityDurationMs)
7866 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007867 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007868 && (totalTxTimeMs <= activityDurationMs));
7869 }
7870
Jack Yu85bd38a2015-11-09 11:34:32 -08007871 /**
7872 * {@hide}
7873 * Returns the service state information on specified subscription.
7874 */
7875 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007876 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7877 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007878 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007879 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007880 return null;
7881 }
7882
Hall Liuf19c44f2018-11-27 14:38:17 -08007883 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7884 LocationAccessPolicy.checkLocationPermission(mApp,
7885 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7886 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007887 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007888 .setCallingPid(Binder.getCallingPid())
7889 .setCallingUid(Binder.getCallingUid())
7890 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007891 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007892 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007893 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7894 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007895 .build());
7896
7897 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7898 LocationAccessPolicy.checkLocationPermission(mApp,
7899 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7900 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007901 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007902 .setCallingPid(Binder.getCallingPid())
7903 .setCallingUid(Binder.getCallingUid())
7904 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007905 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007906 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007907 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7908 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007909 .build());
7910 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7911 boolean hasFinePermission =
7912 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7913 boolean hasCoarsePermission =
7914 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7915
Jack Yu479f40e2020-10-27 21:29:25 -07007916 final Phone phone = getPhone(subId);
7917 if (phone == null) {
7918 return null;
7919 }
7920
Jordan Liu0f2bc442020-11-18 16:47:37 -08007921 final long identity = Binder.clearCallingIdentity();
7922
Jack Yu479f40e2020-10-27 21:29:25 -07007923 boolean isCallingPackageDataService = phone.getDataServicePackages()
7924 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007926 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7927 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7928 Rlog.d(LOG_TAG,
7929 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7930 return null;
7931 }
7932
Hall Liuf19c44f2018-11-27 14:38:17 -08007933 ServiceState ss = phone.getServiceState();
7934
7935 // Scrub out the location info in ServiceState depending on what level of access
7936 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007937 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007938 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7939 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 } finally {
7941 Binder.restoreCallingIdentity(identity);
7942 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007943 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007944
7945 /**
7946 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7947 *
7948 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7949 * voicemail ringtone.
7950 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7951 * PhoneAccount.
7952 */
7953 @Override
7954 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 final long identity = Binder.clearCallingIdentity();
7956 try {
7957 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7958 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007959 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007960 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7963 } finally {
7964 Binder.restoreCallingIdentity(identity);
7965 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007966 }
7967
7968 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007969 * Sets the per-account voicemail ringtone.
7970 *
7971 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7972 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7973 *
7974 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7975 * voicemail ringtone.
7976 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7977 * PhoneAccount.
7978 */
7979 @Override
7980 public void setVoicemailRingtoneUri(String callingPackage,
7981 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007982 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007983 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007984 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7985 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7987 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7988 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990
7991 final long identity = Binder.clearCallingIdentity();
7992 try {
7993 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7994 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007995 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 }
7997 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7998 } finally {
7999 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008000 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 }
8002
8003 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008004 * Returns whether vibration is set for voicemail notification in Phone settings.
8005 *
8006 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8007 * voicemail vibration setting.
8008 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8009 */
8010 @Override
8011 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 final long identity = Binder.clearCallingIdentity();
8013 try {
8014 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8015 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008016 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8020 } finally {
8021 Binder.restoreCallingIdentity(identity);
8022 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008023 }
8024
Youhan Wange64578a2016-05-02 15:32:42 -07008025 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008026 * Sets the per-account voicemail vibration.
8027 *
8028 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8029 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8030 *
8031 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8032 * voicemail vibration setting.
8033 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8034 * specific PhoneAccount.
8035 */
8036 @Override
8037 public void setVoicemailVibrationEnabled(String callingPackage,
8038 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008039 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008041 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8042 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8044 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8045 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008046 }
8047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 final long identity = Binder.clearCallingIdentity();
8049 try {
8050 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8051 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008052 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 }
8054 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8055 } finally {
8056 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008057 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008058 }
8059
8060 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008061 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8062 *
8063 * @throws SecurityException if the caller does not have the required permission
8064 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008065 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008066 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008067 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008068 }
8069
8070 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008071 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8072 * permission.
8073 *
8074 * @throws SecurityException if the caller does not have the required permission
8075 */
8076 private void enforceSendSmsPermission() {
8077 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8078 }
8079
8080 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008081 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008082 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008083 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008084 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008085 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 final long identity = Binder.clearCallingIdentity();
8087 try {
8088 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008089 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 if (componentName == null) {
8091 throw new SecurityException(
8092 "Caller not current active visual voicemail package[null]");
8093 }
8094 String vvmPackage = componentName.getPackageName();
8095 if (!callingPackage.equals(vvmPackage)) {
8096 throw new SecurityException("Caller not current active visual voicemail package["
8097 + vvmPackage + "]");
8098 }
8099 } finally {
8100 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008101 }
8102 }
8103
8104 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008105 * Return the application ID for the app type.
8106 *
8107 * @param subId the subscription ID that this request applies to.
8108 * @param appType the uicc app type.
8109 * @return Application ID for specificied app type, or null if no uicc.
8110 */
8111 @Override
8112 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008113 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008114 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115
8116 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008117 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 if (phone == null) {
8119 return null;
8120 }
8121 String aid = null;
8122 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008123 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 .getApplicationByType(appType).getAid();
8125 } catch (Exception e) {
8126 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8127 }
8128 return aid;
8129 } finally {
8130 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008131 }
Youhan Wange64578a2016-05-02 15:32:42 -07008132 }
8133
Youhan Wang4001d252016-05-11 10:29:41 -07008134 /**
8135 * Return the Electronic Serial Number.
8136 *
8137 * @param subId the subscription ID that this request applies to.
8138 * @return ESN or null if error.
8139 */
8140 @Override
8141 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008142 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008143 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008144
8145 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008146 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008147 if (phone == null) {
8148 return null;
8149 }
8150 String esn = null;
8151 try {
8152 esn = phone.getEsn();
8153 } catch (Exception e) {
8154 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8155 }
8156 return esn;
8157 } finally {
8158 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008159 }
Youhan Wang4001d252016-05-11 10:29:41 -07008160 }
8161
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008162 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008163 * Return the Preferred Roaming List Version.
8164 *
8165 * @param subId the subscription ID that this request applies to.
8166 * @return PRLVersion or null if error.
8167 */
8168 @Override
8169 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008170 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008171 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008172
8173 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008174 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 if (phone == null) {
8176 return null;
8177 }
8178 String cdmaPrlVersion = null;
8179 try {
8180 cdmaPrlVersion = phone.getCdmaPrlVersion();
8181 } catch (Exception e) {
8182 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8183 }
8184 return cdmaPrlVersion;
8185 } finally {
8186 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008187 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008188 }
8189
8190 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008191 * Get snapshot of Telephony histograms
8192 * @return List of Telephony histograms
8193 * @hide
8194 */
8195 @Override
8196 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8198 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199
8200 final long identity = Binder.clearCallingIdentity();
8201 try {
8202 return RIL.getTelephonyRILTimingHistograms();
8203 } finally {
8204 Binder.restoreCallingIdentity(identity);
8205 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008206 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008207
8208 /**
8209 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008210 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8211 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008212 * Require system privileges. In the future we may add this to carrier APIs.
8213 *
Michele Berionne482f8202018-11-27 18:57:59 -08008214 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008215 */
8216 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008217 @TelephonyManager.SetCarrierRestrictionResult
8218 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008219 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008220 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008221
Michele Berionne482f8202018-11-27 18:57:59 -08008222 if (carrierRestrictionRules == null) {
8223 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008224 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 final long identity = Binder.clearCallingIdentity();
8227 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008228 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008229 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230 } finally {
8231 Binder.restoreCallingIdentity(identity);
8232 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008233 }
8234
8235 /**
8236 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008237 * Get the allowed carrier list and the excluded carrier list, including the priority between
8238 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008239 * Require system privileges. In the future we may add this to carrier APIs.
8240 *
Michele Berionne482f8202018-11-27 18:57:59 -08008241 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008242 */
8243 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008244 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008245 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008246 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247
8248 final long identity = Binder.clearCallingIdentity();
8249 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008250 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8251 if (response instanceof CarrierRestrictionRules) {
8252 return (CarrierRestrictionRules) response;
8253 }
8254 // Response is an Exception of some kind,
8255 // which is signalled to the user as a NULL retval
8256 return null;
8257 } catch (Exception e) {
8258 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8259 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 } finally {
8261 Binder.restoreCallingIdentity(identity);
8262 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008263 }
8264
fionaxu59545b42016-05-25 15:53:37 -07008265 /**
fionaxu59545b42016-05-25 15:53:37 -07008266 * Action set from carrier signalling broadcast receivers to enable/disable radio
8267 * @param subId the subscription ID that this action applies to.
8268 * @param enabled control enable or disable radio.
8269 * {@hide}
8270 */
8271 @Override
8272 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8273 enforceModifyPermission();
8274 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275
8276 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008277 if (phone == null) {
8278 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8279 return;
8280 }
8281 try {
8282 phone.carrierActionSetRadioEnabled(enabled);
8283 } catch (Exception e) {
8284 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 } finally {
8286 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008287 }
8288 }
8289
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008290 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008291 * Enable or disable Voice over NR (VoNR)
8292 * @param subId the subscription ID that this action applies to.
8293 * @param enabled enable or disable VoNR.
8294 * @return operation result.
8295 */
8296 @Override
8297 public int setVoNrEnabled(int subId, boolean enabled) {
8298 enforceModifyPermission();
8299 final Phone phone = getPhone(subId);
8300
8301 final long identity = Binder.clearCallingIdentity();
8302 if (phone == null) {
8303 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8304 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8305 }
8306
8307 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8308 try {
8309 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8310 workSource);
8311 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008312
8313 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8314 if (DBG) {
8315 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8316 }
8317 SubscriptionManager.setSubscriptionProperty(
8318 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8319 (enabled ? "1" : "0"));
8320 }
8321
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008322 return result;
8323 } finally {
8324 Binder.restoreCallingIdentity(identity);
8325 }
8326 }
8327
8328 /**
8329 * Is voice over NR enabled
8330 * @return true if VoNR is enabled else false
8331 */
8332 @Override
8333 public boolean isVoNrEnabled(int subId) {
8334 enforceReadPrivilegedPermission("isVoNrEnabled");
8335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8336 final long identity = Binder.clearCallingIdentity();
8337 try {
8338 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8339 null, subId, workSource);
8340 if (DBG) log("isVoNrEnabled: " + isEnabled);
8341 return isEnabled;
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
8345 }
8346
8347 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008348 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8349 * network status based on which carrier apps could apply actions accordingly,
8350 * enable/disable default url handler for example.
8351 *
8352 * @param subId the subscription ID that this action applies to.
8353 * @param report control start/stop reporting the default network status.
8354 * {@hide}
8355 */
8356 @Override
8357 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8358 enforceModifyPermission();
8359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360
8361 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008362 if (phone == null) {
8363 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8364 return;
8365 }
8366 try {
8367 phone.carrierActionReportDefaultNetworkStatus(report);
8368 } catch (Exception e) {
8369 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370 } finally {
8371 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008372 }
8373 }
8374
8375 /**
fionaxud9622282017-07-17 17:51:30 -07008376 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8377 * @param subId the subscription ID that this action applies to.
8378 * {@hide}
8379 */
8380 @Override
8381 public void carrierActionResetAll(int subId) {
8382 enforceModifyPermission();
8383 final Phone phone = getPhone(subId);
8384 if (phone == null) {
8385 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8386 return;
8387 }
8388 try {
8389 phone.carrierActionResetAll();
8390 } catch (Exception e) {
8391 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8392 }
8393 }
8394
8395 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008396 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8397 * bug report is being generated.
8398 */
8399 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008400 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008401 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8402 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008403 writer.println("Permission Denial: can't dump Phone from pid="
8404 + Binder.getCallingPid()
8405 + ", uid=" + Binder.getCallingUid()
8406 + "without permission "
8407 + android.Manifest.permission.DUMP);
8408 return;
8409 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008410 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008411 }
Jack Yueb89b242016-06-22 13:27:47 -07008412
Brad Ebingerdac2f002018-04-03 15:17:52 -07008413 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008414 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8415 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8416 @NonNull String[] args) {
8417 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8418 this, in.getFileDescriptor(), out.getFileDescriptor(),
8419 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008420 }
8421
Jack Yueb89b242016-06-22 13:27:47 -07008422 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008423 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008424 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008425 * @param reason the reason the data enable change is taking place
8426 * @param enabled True if enabling the data, otherwise disabling.
8427 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008428 */
8429 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008430 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008431 boolean enabled) {
8432 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8433 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8434 try {
8435 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008436 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008437 } catch (SecurityException se) {
8438 enforceModifyPermission();
8439 }
8440 } else {
8441 enforceModifyPermission();
8442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008443
8444 final long identity = Binder.clearCallingIdentity();
8445 try {
8446 Phone phone = getPhone(subId);
8447 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008448 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8449 phone.carrierActionSetMeteredApnsEnabled(enabled);
8450 } else {
8451 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 }
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008456 }
8457 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008458
8459 /**
8460 * Get Client request stats
8461 * @return List of Client Request Stats
8462 * @hide
8463 */
8464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8466 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008468 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008469 return null;
8470 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008471 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008473 final long identity = Binder.clearCallingIdentity();
8474 try {
8475 if (phone != null) {
8476 return phone.getClientRequestStats();
8477 }
8478
8479 return null;
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
8482 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008483 }
8484
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008485 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008486 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008487 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008488 }
Jack Yueb4124c2017-02-16 15:32:43 -08008489
8490 /**
Grace Chen70990072017-03-24 17:21:30 -07008491 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008492 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008493 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008494 * @param state State of SIM (power down, power up, pass through)
8495 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8496 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8497 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008498 *
8499 **/
8500 @Override
Grace Chen70990072017-03-24 17:21:30 -07008501 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008502 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008503 Phone phone = PhoneFactory.getPhone(slotIndex);
8504
vagdeviaf9a5b92018-08-15 16:01:53 -07008505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008507 final long identity = Binder.clearCallingIdentity();
8508 try {
8509 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008510 phone.setSimPowerState(state, null, workSource);
8511 }
8512 } finally {
8513 Binder.restoreCallingIdentity(identity);
8514 }
8515 }
8516
8517 /**
8518 * Set SIM card power state.
8519 *
8520 * @param slotIndex SIM slot id.
8521 * @param state State of SIM (power down, power up, pass through)
8522 * @param callback callback to trigger after success or failure
8523 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8524 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8525 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8526 *
8527 **/
8528 @Override
8529 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8530 IIntegerConsumer callback) {
8531 enforceModifyPermission();
8532 Phone phone = PhoneFactory.getPhone(slotIndex);
8533
8534 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8535
8536 final long identity = Binder.clearCallingIdentity();
8537 try {
8538 if (phone != null) {
8539 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8540 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541 }
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008544 }
8545 }
Shuo Qiandd210312017-04-12 22:11:33 +00008546
Tyler Gunn65d45c22017-06-05 11:22:26 -07008547 private boolean isUssdApiAllowed(int subId) {
8548 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008549 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008550 if (configManager == null) {
8551 return false;
8552 }
8553 PersistableBundle pb = configManager.getConfigForSubId(subId);
8554 if (pb == null) {
8555 return false;
8556 }
8557 return pb.getBoolean(
8558 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8559 }
8560
Shuo Qiandd210312017-04-12 22:11:33 +00008561 /**
8562 * Check if phone is in emergency callback mode
8563 * @return true if phone is in emergency callback mode
8564 * @param subId sub id
8565 */
goneil9c5f4872017-12-05 14:07:56 -08008566 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008567 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008568 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008569 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570
8571 final long identity = Binder.clearCallingIdentity();
8572 try {
8573 if (phone != null) {
8574 return phone.isInEcm();
8575 } else {
8576 return false;
8577 }
8578 } finally {
8579 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008580 }
8581 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008582
8583 /**
8584 * Get the current signal strength information for the given subscription.
8585 * Because this information is not updated when the device is in a low power state
8586 * it should not be relied-upon to be current.
8587 * @param subId Subscription index
8588 * @return the most recent cached signal strength info from the modem
8589 */
8590 @Override
8591 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008592 final long identity = Binder.clearCallingIdentity();
8593 try {
8594 Phone p = getPhone(subId);
8595 if (p == null) {
8596 return null;
8597 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599 return p.getSignalStrength();
8600 } finally {
8601 Binder.restoreCallingIdentity(identity);
8602 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008603 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008604
Pengquan Meng77b7f132018-08-22 14:49:57 -07008605 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008606 * Get the current modem radio state for the given slot.
8607 * @param slotIndex slot index.
8608 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008609 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008610 * @return the current radio power state from the modem
8611 */
8612 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008613 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008614 Phone phone = PhoneFactory.getPhone(slotIndex);
8615 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8617 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008618 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8619 }
8620
8621 final long identity = Binder.clearCallingIdentity();
8622 try {
8623 return phone.getRadioPowerState();
8624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
8627 }
8628 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8629 }
8630
8631 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008632 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8633 *
8634 * <p>Requires one of the following permissions:
8635 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8636 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8637 * privileges.
8638 *
8639 * @param subId subscription id
8640 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8641 * {@code false}.
8642 */
8643 @Override
8644 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008645 try {
8646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8647 null);
8648 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008649 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008650 mApp, subId, "isDataRoamingEnabled");
8651 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008652
Pengquan Menga1bb6272018-09-06 09:59:22 -07008653 boolean isEnabled = false;
8654 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008655 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008656 Phone phone = getPhone(subId);
8657 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008658 } finally {
8659 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008660 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008661 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008662 }
8663
8664
8665 /**
8666 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8667 *
8668 * <p> Requires permission:
8669 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8670 * privileges.
8671 *
8672 * @param subId subscription id
8673 * @param isEnabled {@code true} means enable, {@code false} means disable.
8674 */
8675 @Override
8676 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8678 mApp, subId, "setDataRoamingEnabled");
8679
Pengquan Menga1bb6272018-09-06 09:59:22 -07008680 final long identity = Binder.clearCallingIdentity();
8681 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008682 Phone phone = getPhone(subId);
8683 if (phone != null) {
8684 phone.setDataRoamingEnabled(isEnabled);
8685 }
8686 } finally {
8687 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008688 }
8689 }
8690
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008691 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008692 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008693 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008694 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008695 mApp, subId, "isManualNetworkSelectionAllowed");
8696
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008697 boolean isAllowed = true;
8698 final long identity = Binder.clearCallingIdentity();
8699 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008700 Phone phone = getPhone(subId);
8701 if (phone != null) {
8702 isAllowed = phone.isCspPlmnEnabled();
8703 }
8704 } finally {
8705 Binder.restoreCallingIdentity(identity);
8706 }
8707 return isAllowed;
8708 }
8709
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008710 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8711 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8712 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8713 // Update each UiccPort object based on privilege access
8714 UiccPort[] uiccPorts = card.getUiccPortList();
8715 for (UiccPort port : uiccPorts) {
8716 UiccProfile profile = port.getUiccProfile();
8717 if (profile == null ||
8718 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8719 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8720 return false;
8721 }
8722 }
8723 return true;
8724 }
8725
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008726 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008727 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008728 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008729 mApp.getSystemService(AppOpsManager.class)
8730 .checkPackage(Binder.getCallingUid(), callingPackage);
8731
Jordan Liu1e142fc2019-04-22 15:10:43 -07008732 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008733 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008734 try {
8735 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008736 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008737 } catch (SecurityException e) {
8738 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8739 // has carrier privileges on an active UICC
8740 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8741 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008742 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008743 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008744 }
sandeepjsb6c87872021-09-27 15:34:44 +00008745 // checking compatibility, if calling app's target SDK is T and beyond.
8746 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8747 Binder.getCallingUid())) {
8748 isIccIdAccessRestricted = true;
8749 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008750 final long identity = Binder.clearCallingIdentity();
8751 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008752 UiccController uiccController = UiccController.getInstance();
8753 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008754 if (hasReadPermission) {
8755 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008756 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008757
8758 // Remove private info if the caller doesn't have access
8759 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8760 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008761 //setting the value after compatibility check
8762 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008763 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8764 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008765 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008766 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8767 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8768 if (card == null || card.getUiccPortList().length == 0) {
8769 // assume no access if the card or ports are unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008770 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008771 continue;
8772 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008773 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008774 filteredInfos.add(cardInfo);
8775 } else {
sandeepjsb6c87872021-09-27 15:34:44 +00008776 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008777 }
8778 }
8779 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008780 } finally {
8781 Binder.restoreCallingIdentity(identity);
8782 }
8783 }
8784
sandeepjsb6c87872021-09-27 15:34:44 +00008785 /**
8786 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8787 * generally private and require carrier privileges to view.
8788 *
8789 * @hide
8790 */
8791 @NonNull
8792 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8793 List<UiccPortInfo> portinfo = new ArrayList<>();
8794 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8795 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8796 }
8797 return new UiccCardInfo(
8798 cardInfo.isEuicc(),
8799 cardInfo.getCardId(),
8800 null,
8801 cardInfo.getPhysicalSlotIndex(),
8802 cardInfo.isRemovable(),
8803 cardInfo.isMultipleEnabledProfilesSupported(),
8804 portinfo
8805 );
8806 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008807
sandeepjsb6c87872021-09-27 15:34:44 +00008808 /**
8809 * @hide
8810 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8811 * These values are generally private and require carrier privileges to view.
8812 */
8813 @NonNull
8814 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8815 return new UiccPortInfo(
8816 UiccPortInfo.ICCID_REDACTED,
8817 portInfo.getPortIndex(),
8818 portInfo.getLogicalSlotIndex(),
8819 portInfo.isActive()
8820 );
8821 }
8822 @Override
8823 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008824 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008825 mApp.getSystemService(AppOpsManager.class)
8826 .checkPackage(Binder.getCallingUid(), callingPackage);
8827
8828 boolean hasReadPermission = false;
8829 boolean isLogicalSlotAccessRestricted = false;
8830 String iccId;
8831
8832 try {
8833 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8834 hasReadPermission = true;
8835 } catch (SecurityException e) {
8836 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8837 // has carrier privileges on an active UICC
8838 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8839 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8840 hasReadPermission = true;
8841 }
8842 }
8843
8844 // checking compatibility, if calling app's target SDK is T and beyond.
8845 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8846 Binder.getCallingUid())) {
8847 isLogicalSlotAccessRestricted = true;
8848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008849 final long identity = Binder.clearCallingIdentity();
8850 try {
8851 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8852 if (slots == null) {
8853 Rlog.i(LOG_TAG, "slots is null.");
8854 return null;
8855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008856 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8857 for (int i = 0; i < slots.length; i++) {
8858 UiccSlot slot = slots[i];
8859 if (slot == null) {
8860 continue;
8861 }
8862
Jordan Liu7be7e652019-05-06 18:55:02 +00008863 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008864 UiccCard card = slot.getUiccCard();
sandeepjsb6c87872021-09-27 15:34:44 +00008865 //if has read permission
8866 if (hasReadPermission) {
8867 iccId = slot.getIccId();
8868 } else {
sandeepjsa208e3b2021-11-17 04:05:58 +00008869 if (card != null) {
8870 // if no read permission checking carrier
8871 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
8872 iccId = slot.getIccId();
8873 } else {
8874 //if no carrier permission redact ICCID
8875 iccId = IccUtils.TEST_ICCID;
8876 }
sandeepjsb6c87872021-09-27 15:34:44 +00008877 } else {
sandeepjsa208e3b2021-11-17 04:05:58 +00008878 iccId = null;
sandeepjsb6c87872021-09-27 15:34:44 +00008879 }
8880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 if (card != null) {
8882 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008883 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008884 cardId = slot.getEid();
8885 if (TextUtils.isEmpty(cardId)) {
sandeepjsb6c87872021-09-27 15:34:44 +00008886 cardId = iccId;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008888 }
8889
Jordan Liu857451f2019-05-09 16:35:35 -07008890 if (cardId != null) {
8891 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8892 // if cardId is an EID, it's all digits so this is fine
8893 cardId = IccUtils.stripTrailingFs(cardId);
8894 }
8895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008896 int cardState = 0;
8897 switch (slot.getCardState()) {
8898 case CARDSTATE_ABSENT:
8899 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8900 break;
8901 case CARDSTATE_PRESENT:
8902 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8903 break;
8904 case CARDSTATE_ERROR:
8905 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8906 break;
8907 case CARDSTATE_RESTRICTED:
8908 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8909 break;
8910 default:
8911 break;
8912
8913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008914 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 slot.isEuicc(),
8916 cardId,
8917 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008918 slot.isExtendedApduSupported(),
sandeepjsb6c87872021-09-27 15:34:44 +00008919 slot.isRemovable(), Collections.singletonList(
8920 new UiccPortInfo(
8921 iccId,
8922 0 /* TODO: to use portList from UiccSlots */,
8923 slot.getPhoneId(),
8924 slot.isActive())));
8925 //setting the value after compatibility check
8926 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 }
8928 return infos;
8929 } finally {
8930 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008931 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008932 }
8933
8934 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008935 @Deprecated
8936 //TODO : once integrating with HAL Changes we can clean up this Internal API.
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008937 public boolean switchSlots(int[] physicalSlots) {
8938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008939
8940 final long identity = Binder.clearCallingIdentity();
8941 try {
8942 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8943 } finally {
8944 Binder.restoreCallingIdentity(identity);
8945 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008946 }
Jack Yu4c988042018-02-27 15:30:01 -08008947
8948 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008949 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8950 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8951 enforceModifyPermission();
8952
8953 final long identity = Binder.clearCallingIdentity();
8954 try {
8955 //TODO: once integrating the HAL changes we can proceed with to work on the parsing side
8956 int[] physicalSlots = new int[slotMapping.size()];
8957 for (int i = 0; i < physicalSlots.length; i++) {
8958 physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex();
8959 }
8960 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8961 } finally {
8962 Binder.restoreCallingIdentity(identity);
8963 }
8964 }
8965
8966 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008967 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008968 final long identity = Binder.clearCallingIdentity();
8969 try {
8970 return UiccController.getInstance().getCardIdForDefaultEuicc();
8971 } finally {
8972 Binder.restoreCallingIdentity(identity);
8973 }
8974 }
8975
Pengquan Meng85728fb2018-03-12 16:31:21 -07008976 /**
goneil47ffb6e2018-04-06 15:40:58 -07008977 * A test API to reload the UICC profile.
8978 *
8979 * <p>Requires that the calling app has permission
8980 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8981 * @hide
8982 */
8983 @Override
8984 public void refreshUiccProfile(int subId) {
8985 enforceModifyPermission();
8986
8987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 Phone phone = getPhone(subId);
8990 if (phone == null) {
8991 return;
8992 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008993 UiccPort uiccPort = phone.getUiccPort();
8994 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008995 return;
8996 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008997 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008998 if (uiccProfile == null) {
8999 return;
9000 }
9001 uiccProfile.refresh();
9002 } finally {
9003 Binder.restoreCallingIdentity(identity);
9004 }
9005 }
9006
9007 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009008 * Returns false if the mobile data is disabled by default, otherwise return true.
9009 */
9010 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009011 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009012 }
9013
9014 /**
9015 * Returns true if the data roaming is enabled by default, i.e the system property
9016 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9017 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9018 */
9019 private boolean getDefaultDataRoamingEnabled(int subId) {
9020 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009021 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009022 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009023 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9024 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9025 return isDataRoamingEnabled;
9026 }
9027
9028 /**
9029 * Returns the default network type for the given {@code subId}, if the default network type is
9030 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9031 */
9032 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009033 List<Integer> list = TelephonyProperties.default_network();
9034 int phoneId = mSubscriptionController.getPhoneId(subId);
9035 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9036 return list.get(phoneId);
9037 }
9038 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009039 }
fionaxua13278b2018-03-21 00:08:13 -07009040
9041 @Override
9042 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009043 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009044 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045
9046 final long identity = Binder.clearCallingIdentity();
9047 try {
9048 final Phone phone = getPhone(subId);
9049 if (phone == null) {
9050 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9051 return;
9052 }
chen xueaba88a2019-03-15 13:15:10 -07009053 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9054 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009055 if (carrierPrivilegeRules == null) {
9056 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9057 } else {
9058 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009060 } finally {
9061 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009062 }
fionaxua13278b2018-03-21 00:08:13 -07009063 }
9064
9065 @Override
9066 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009067 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068
9069 final long identity = Binder.clearCallingIdentity();
9070 try {
9071 final Phone phone = getPhone(subId);
9072 if (phone == null) {
9073 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9074 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9075 }
9076 return phone.getCarrierIdListVersion();
9077 } finally {
9078 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009079 }
fionaxua13278b2018-03-21 00:08:13 -07009080 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009081
9082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009083 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9084 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009086 mApp, subId, callingPackage, callingFeatureId,
9087 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009088 return -1;
9089 }
9090
9091 final long identity = Binder.clearCallingIdentity();
9092 try {
9093 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
9097 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009098
9099 @Override
9100 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009101 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009102 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009103 mApp, subId, "getCdmaRoamingMode");
9104
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
9107 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9108 } finally {
9109 Binder.restoreCallingIdentity(identity);
9110 }
9111 }
9112
9113 @Override
9114 public boolean setCdmaRoamingMode(int subId, int mode) {
9115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9116 mApp, subId, "setCdmaRoamingMode");
9117
9118 final long identity = Binder.clearCallingIdentity();
9119 try {
9120 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
9123 }
9124 }
9125
9126 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009127 public int getCdmaSubscriptionMode(int subId) {
9128 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009129 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009130 mApp, subId, "getCdmaSubscriptionMode");
9131
9132 final long identity = Binder.clearCallingIdentity();
9133 try {
9134 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9135 } finally {
9136 Binder.restoreCallingIdentity(identity);
9137 }
9138 }
9139
9140 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009141 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9143 mApp, subId, "setCdmaSubscriptionMode");
9144
9145 final long identity = Binder.clearCallingIdentity();
9146 try {
9147 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009152
sqianc5eccab2018-10-19 18:46:41 -07009153 @Override
sqian8c685422019-02-22 15:55:18 -08009154 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009155 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009157 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9158 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009159 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9160 }
9161 final long identity = Binder.clearCallingIdentity();
9162 try {
sqian854d44b2018-12-12 16:48:18 -08009163 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9164 for (Phone phone: PhoneFactory.getPhones()) {
9165 if (phone.getEmergencyNumberTracker() != null
9166 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9167 emergencyNumberListInternal.put(
9168 phone.getSubId(),
9169 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9170 }
sqian11b7a0e2018-12-05 18:48:28 -08009171 }
sqian854d44b2018-12-12 16:48:18 -08009172 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009173 } finally {
9174 Binder.restoreCallingIdentity(identity);
9175 }
sqianc5eccab2018-10-19 18:46:41 -07009176 }
9177
9178 @Override
sqian8c685422019-02-22 15:55:18 -08009179 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009180 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009181 if (!exactMatch) {
9182 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009183 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009184 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009185 }
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
sqian854d44b2018-12-12 16:48:18 -08009188 for (Phone phone: PhoneFactory.getPhones()) {
9189 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009190 && phone.getEmergencyNumberTracker()
9191 .isEmergencyNumber(number, exactMatch)) {
9192 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009193 }
sqian11b7a0e2018-12-05 18:48:28 -08009194 }
9195 return false;
9196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
9199 }
9200
sqianf4ca7ed2019-01-15 18:32:07 -08009201 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009202 * Start emergency callback mode for GsmCdmaPhone for testing.
9203 */
9204 @Override
9205 public void startEmergencyCallbackMode() {
9206 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9207 "startEmergencyCallbackMode");
9208 enforceModifyPermission();
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 for (Phone phone : PhoneFactory.getPhones()) {
9212 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9213 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9214 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9215 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9216 gsmCdmaPhone.obtainMessage(
9217 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9218 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9219 }
9220 }
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
9225
9226 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009227 * Update emergency number list for test mode.
9228 */
9229 @Override
9230 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9232 "updateEmergencyNumberListTestMode");
9233
9234 final long identity = Binder.clearCallingIdentity();
9235 try {
9236 for (Phone phone: PhoneFactory.getPhones()) {
9237 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9238 if (tracker != null) {
9239 tracker.executeEmergencyNumberTestModeCommand(action, num);
9240 }
9241 }
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
9246
9247 /**
9248 * Get the full emergency number list for test mode.
9249 */
9250 @Override
9251 public List<String> getEmergencyNumberListTestMode() {
9252 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9253 "getEmergencyNumberListTestMode");
9254
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 Set<String> emergencyNumbers = new HashSet<>();
9258 for (Phone phone: PhoneFactory.getPhones()) {
9259 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9260 if (tracker != null) {
9261 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9262 emergencyNumbers.add(num.getNumber());
9263 }
9264 }
9265 }
9266 return new ArrayList<>(emergencyNumbers);
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 }
9271
chen xud6b45bd2018-10-30 22:27:10 -07009272 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009273 public int getEmergencyNumberDbVersion(int subId) {
9274 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9275
9276 final long identity = Binder.clearCallingIdentity();
9277 try {
9278 final Phone phone = getPhone(subId);
9279 if (phone == null) {
9280 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9281 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9282 }
9283 return phone.getEmergencyNumberDbVersion();
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
9289 @Override
9290 public void notifyOtaEmergencyNumberDbInstalled() {
9291 enforceModifyPermission();
9292
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 for (Phone phone: PhoneFactory.getPhones()) {
9296 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9297 if (tracker != null) {
9298 tracker.updateOtaEmergencyNumberDatabase();
9299 }
9300 }
9301 } finally {
9302 Binder.restoreCallingIdentity(identity);
9303 }
9304 }
9305
9306 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009307 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009308 enforceActiveEmergencySessionPermission();
9309
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 for (Phone phone: PhoneFactory.getPhones()) {
9313 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9314 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009315 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9316 }
9317 }
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
9323 @Override
9324 public void resetOtaEmergencyNumberDbFilePath() {
9325 enforceActiveEmergencySessionPermission();
9326
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 for (Phone phone: PhoneFactory.getPhones()) {
9330 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9331 if (tracker != null) {
9332 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009333 }
9334 }
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 }
9339
9340 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009341 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9342 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9343 Phone phone = getPhone(subId);
9344 if (phone == null) {
9345 return null;
9346 }
9347 final long identity = Binder.clearCallingIdentity();
9348 try {
9349 UiccProfile profile = UiccController.getInstance()
9350 .getUiccProfileForPhone(phone.getPhoneId());
9351 if (profile != null) {
9352 return profile.getCertsFromCarrierPrivilegeAccessRules();
9353 }
9354 } finally {
9355 Binder.restoreCallingIdentity(identity);
9356 }
9357 return null;
9358 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009359
9360 /**
9361 * Enable or disable a modem stack.
9362 */
9363 @Override
9364 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9365 enforceModifyPermission();
9366
9367 final long identity = Binder.clearCallingIdentity();
9368 try {
9369 Phone phone = PhoneFactory.getPhone(slotIndex);
9370 if (phone == null) {
9371 return false;
9372 } else {
9373 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9374 }
9375 } finally {
9376 Binder.restoreCallingIdentity(identity);
9377 }
9378 }
Michelecea4cf22018-12-21 15:00:11 -08009379
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009380 /**
9381 * Whether a modem stack is enabled or not.
9382 */
9383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009384 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9385 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009386 Phone phone = PhoneFactory.getPhone(slotIndex);
9387 if (phone == null) return false;
9388
9389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009390 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9391 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009392 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9393 }
9394
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009397 try {
9398 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9399 } catch (NoSuchElementException ex) {
9400 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9401 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009402 } finally {
9403 Binder.restoreCallingIdentity(identity);
9404 }
9405 }
9406
Michelecea4cf22018-12-21 15:00:11 -08009407 @Override
Michele0ea7d782019-03-19 14:58:42 -07009408 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009409 enforceModifyPermission();
9410
9411 final long identity = Binder.clearCallingIdentity();
9412 try {
9413 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009414 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009415 .commit();
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
9420
9421 @Override
Michele0ea7d782019-03-19 14:58:42 -07009422 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009423 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009425 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9426 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009427 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009428 }
Michelecea4cf22018-12-21 15:00:11 -08009429
9430 final long identity = Binder.clearCallingIdentity();
9431 try {
Michele0ea7d782019-03-19 14:58:42 -07009432 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009433 } finally {
9434 Binder.restoreCallingIdentity(identity);
9435 }
9436 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009437
Michele0ea7d782019-03-19 14:58:42 -07009438 @TelephonyManager.IsMultiSimSupportedResult
9439 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009440 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9441 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9442 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009443 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9444 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009445 }
9446 // Check if the hardware supports multisim functionality. If usage of multisim is not
9447 // supported by the modem, indicate that it is restricted.
9448 PhoneCapability staticCapability =
9449 mPhoneConfigurationManager.getStaticPhoneCapability();
9450 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009451 loge("isMultiSimSupportedInternal: no static configuration available");
9452 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009453 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009454 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009455 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9456 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009457 }
9458 // Check if support of multiple SIMs is restricted by carrier
9459 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009460 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009461 }
9462
Michele0ea7d782019-03-19 14:58:42 -07009463 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009464 }
9465
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009466 /**
9467 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009468 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9469 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9470 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009471 * @param numOfSims number of active sims we want to switch to
9472 */
9473 @Override
9474 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009475 if (numOfSims == 1) {
9476 enforceModifyPermission();
9477 } else {
9478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9479 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9480 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009481 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009482
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009483 try {
Michele30b57b22019-03-01 12:01:14 -08009484 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009485 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009486 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9487 return;
9488 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009489 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9490 } finally {
9491 Binder.restoreCallingIdentity(identity);
9492 }
9493 }
9494
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009495 @Override
9496 public boolean isApplicationOnUicc(int subId, int appType) {
9497 enforceReadPrivilegedPermission("isApplicationOnUicc");
9498 Phone phone = getPhone(subId);
9499 if (phone == null) {
9500 return false;
9501 }
9502 final long identity = Binder.clearCallingIdentity();
9503 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009504 UiccPort uiccPort = phone.getUiccPort();
9505 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009506 return false;
9507 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009508 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009509 if (uiccProfile == null) {
9510 return false;
9511 }
9512 if (TelephonyManager.APPTYPE_SIM <= appType
9513 && appType <= TelephonyManager.APPTYPE_ISIM) {
9514 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9515 }
9516 return false;
9517 } finally {
9518 Binder.restoreCallingIdentity(identity);
9519 }
9520 }
9521
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009522 /**
chen xub4baa772019-04-03 10:23:41 -07009523 * Get whether making changes to modem configurations will trigger reboot.
9524 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009525 */
9526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009527 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9528 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009530 mApp, subId, callingPackage, callingFeatureId,
9531 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009532 return false;
9533 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009534 final long identity = Binder.clearCallingIdentity();
9535 try {
9536 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9537 } finally {
9538 Binder.restoreCallingIdentity(identity);
9539 }
9540 }
9541
Nathan Harold29f5f052019-02-15 13:41:57 -08009542 private void updateModemStateMetrics() {
9543 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9544 // TODO: check the state for each modem if the api is ready.
9545 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9546 }
9547
Pengquan Meng3889a572019-01-23 11:16:29 -08009548 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009549 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009550 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009551 // Verify that the callingPackage belongs to the calling UID
9552 mApp.getSystemService(AppOpsManager.class)
9553 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009554 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009555 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009556 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009557 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9558 if (slotInfos != null) {
9559 for (int i = 0; i < slotInfos.length; i++) {
9560 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9561 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9562 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9563 portInfo.getLogicalSlotIndex()));
9564 }
9565 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009566 }
9567 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009568 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009569 } finally {
9570 Binder.restoreCallingIdentity(identity);
9571 }
9572 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009573
9574 /**
9575 * Get the IRadio HAL Version
9576 */
9577 @Override
9578 public int getRadioHalVersion() {
9579 Phone phone = getDefaultPhone();
9580 if (phone == null) return -1;
9581 HalVersion hv = phone.getHalVersion();
9582 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9583 return hv.major * 100 + hv.minor;
9584 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009585
9586 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009587 * Get the current calling package name.
9588 * @return the current calling package name
9589 */
9590 @Override
9591 public String getCurrentPackageName() {
9592 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9593 }
9594
9595 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009596 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9597 * corresponding network requests on a subId.
9598 *
9599 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009600 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009601 * 2) APN is un-metered for this subscription, or
9602 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009603 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009604 *
9605 * @return whether data is allowed for a apn type.
9606 *
9607 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009608 */
9609 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009610 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009611 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9612 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009613
9614 // Now that all security checks passes, perform the operation as ourselves.
9615 final long identity = Binder.clearCallingIdentity();
9616 try {
9617 Phone phone = getPhone(subId);
9618 if (phone == null) return false;
9619
Jack Yu41407ee2019-05-13 16:54:09 -07009620 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009621 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
9626
9627 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009628 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009629 enforceReadPrivilegedPermission("isApnMetered");
9630
9631 // Now that all security checks passes, perform the operation as ourselves.
9632 final long identity = Binder.clearCallingIdentity();
9633 try {
9634 Phone phone = getPhone(subId);
9635 if (phone == null) return true; // By default return true.
9636
Jack Yu41407ee2019-05-13 16:54:09 -07009637 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009642
9643 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009644 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9645 int subscriptionId, IBooleanConsumer resultCallback) {
9646 enforceModifyPermission();
9647 long token = Binder.clearCallingIdentity();
9648 try {
9649 Phone phone = getPhone(subscriptionId);
9650 if (phone == null) {
9651 try {
9652 if (resultCallback != null) {
9653 resultCallback.accept(false);
9654 }
9655 } catch (RemoteException e) {
9656 // ignore
9657 }
9658 return;
9659 }
9660 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9661 Pair.create(specifiers, (x) -> {
9662 try {
9663 if (resultCallback != null) {
9664 resultCallback.accept(x);
9665 }
9666 } catch (RemoteException e) {
9667 // ignore
9668 }
9669 });
9670 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9671 } finally {
9672 Binder.restoreCallingIdentity(token);
9673 }
9674 }
9675
9676 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009677 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9678 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009679 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009680 mApp, subId, "getSystemSelectionChannels");
9681 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9682 final long identity = Binder.clearCallingIdentity();
9683 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009684 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9685 if (result instanceof IllegalStateException) {
9686 throw (IllegalStateException) result;
9687 }
9688 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009689 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9690 return specifiers;
9691 } finally {
9692 Binder.restoreCallingIdentity(identity);
9693 }
9694 }
9695
9696 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009697 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009698 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009699 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9700 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9701 if (iccRecords == null) {
9702 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9703 return false;
9704 }
9705 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9706 }
9707
9708 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009709 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9710 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009711 if (callingPackage == null) {
9712 callingPackage = getCurrentPackageName();
9713 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009714 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9715 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009716 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9717 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009718 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9719 }
9720 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9721 Intent intent = new Intent();
9722 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9723 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9724 // Bring up choose default SMS subscription dialog right now
9725 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9726 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9727 mApp.startActivity(intent);
9728 }
chen xud5ca2d52019-05-28 15:20:57 -07009729
9730 @Override
9731 public String getMmsUAProfUrl(int subId) {
9732 //TODO investigate if this API should require proper permission check in R b/133791609
9733 final long identity = Binder.clearCallingIdentity();
9734 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009735 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9736 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9737 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9738 return carrierUAProfUrl;
9739 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009740 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9741 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009742 } finally {
9743 Binder.restoreCallingIdentity(identity);
9744 }
9745 }
9746
9747 @Override
9748 public String getMmsUserAgent(int subId) {
9749 //TODO investigate if this API should require proper permission check in R b/133791609
9750 final long identity = Binder.clearCallingIdentity();
9751 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009752 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9753 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9754 if (!TextUtils.isEmpty(carrierUserAgent)) {
9755 return carrierUserAgent;
9756 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009757 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9758 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009759 } finally {
9760 Binder.restoreCallingIdentity(identity);
9761 }
9762 }
Jack Yub07d4972019-05-28 16:12:25 -07009763
9764 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009765 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9766 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009767
Jack Yub07d4972019-05-28 16:12:25 -07009768 final long identity = Binder.clearCallingIdentity();
9769 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009770 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009771 if (phone == null) return false;
9772
Hall Liua62f5da2020-09-25 10:42:19 -07009773 switch (policy) {
9774 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9775 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9776 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9777 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9778 default:
9779 throw new IllegalArgumentException(policy + " is not a valid policy");
9780 }
Jack Yub07d4972019-05-28 16:12:25 -07009781 } finally {
9782 Binder.restoreCallingIdentity(identity);
9783 }
9784 }
9785
9786 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009787 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009788 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009789 enforceModifyPermission();
9790
changbettyd5c246e2019-12-24 15:40:37 +08009791 final long identity = Binder.clearCallingIdentity();
9792 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009793 Phone phone = getPhone(subscriptionId);
9794 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009795
Hall Liua62f5da2020-09-25 10:42:19 -07009796 switch (policy) {
9797 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9798 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9799 break;
9800 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9801 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9802 break;
9803 default:
9804 throw new IllegalArgumentException(policy + " is not a valid policy");
9805 }
changbettyd5c246e2019-12-24 15:40:37 +08009806 } finally {
9807 Binder.restoreCallingIdentity(identity);
9808 }
9809 }
9810
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009811 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009812 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009813 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9814 * otherwise.
9815 */
9816 @Override
9817 public void setCepEnabled(boolean isCepEnabled) {
9818 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9819
9820 final long identity = Binder.clearCallingIdentity();
9821 try {
9822 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9823 for (Phone phone : PhoneFactory.getPhones()) {
9824 Phone defaultPhone = phone.getImsPhone();
9825 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9826 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9827 ImsPhoneCallTracker imsPhoneCallTracker =
9828 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9829 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9830 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9831 + imsPhone.getMsisdn());
9832 }
9833 }
9834 } finally {
9835 Binder.restoreCallingIdentity(identity);
9836 }
9837 }
allenwtsu46dcc572020-01-08 18:24:03 +08009838
9839 /**
9840 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9841 *
9842 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9843 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9844 * before being read.
9845 */
9846 @Override
9847 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9848 isCompressed) {
9849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9850 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9852 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9853 }
9854 if (!isImsAvailableOnDevice()) {
9855 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9856 "IMS not available on device.");
9857 }
9858
9859 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009860 try {
Hui Wang761a6682020-10-31 05:12:53 +00009861 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9862 } finally {
9863 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009864 }
9865 }
zoey chene02881a2019-12-30 16:11:23 +08009866
9867 @Override
9868 public boolean isIccLockEnabled(int subId) {
9869 enforceReadPrivilegedPermission("isIccLockEnabled");
9870
9871 // Now that all security checks passes, perform the operation as ourselves.
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 Phone phone = getPhone(subId);
9875 if (phone != null && phone.getIccCard() != null) {
9876 return phone.getIccCard().getIccLockEnabled();
9877 } else {
9878 return false;
9879 }
9880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
9884
9885 /**
9886 * Set the ICC pin lock enabled or disabled.
9887 *
9888 * @return an integer representing the status of IccLock enabled or disabled in the following
9889 * three cases:
9890 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9891 * successfully.
9892 * - Positive number and zero for remaining password attempts.
9893 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9894 *
9895 */
9896 @Override
9897 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9898 enforceModifyPermission();
9899
9900 Phone phone = getPhone(subId);
9901 if (phone == null) {
9902 return 0;
9903 }
9904 // Now that all security checks passes, perform the operation as ourselves.
9905 final long identity = Binder.clearCallingIdentity();
9906 try {
9907 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9908 new Pair<Boolean, String>(enabled, password), phone, null);
9909 return attemptsRemaining;
9910
9911 } catch (Exception e) {
9912 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9913 } finally {
9914 Binder.restoreCallingIdentity(identity);
9915 }
9916 return 0;
9917 }
9918
9919 /**
9920 * Change the ICC password used in ICC pin lock.
9921 *
9922 * @return an integer representing the status of IccLock changed in the following three cases:
9923 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9924 * - Positive number and zero for remaining password attempts.
9925 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9926 *
9927 */
9928 @Override
9929 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9930 enforceModifyPermission();
9931
9932 Phone phone = getPhone(subId);
9933 if (phone == null) {
9934 return 0;
9935 }
9936 // Now that all security checks passes, perform the operation as ourselves.
9937 final long identity = Binder.clearCallingIdentity();
9938 try {
9939 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9940 new Pair<String, String>(oldPassword, newPassword), phone, null);
9941 return attemptsRemaining;
9942
9943 } catch (Exception e) {
9944 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 return 0;
9949 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009950
9951 /**
9952 * Request for receiving user activity notification
9953 */
9954 @Override
9955 public void requestUserActivityNotification() {
9956 if (!mNotifyUserActivity.get()
9957 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9958 mNotifyUserActivity.set(true);
9959 }
9960 }
9961
9962 /**
9963 * Called when userActivity is signalled in the power manager.
9964 * This is safe to call from any thread, with any window manager locks held or not.
9965 */
9966 @Override
9967 public void userActivity() {
9968 // ***************************************
9969 // * Inherited from PhoneWindowManager *
9970 // ***************************************
9971 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9972 // WITH ITS LOCKS HELD.
9973 //
9974 // This code must be VERY careful about the locks
9975 // it acquires.
9976 // In fact, the current code acquires way too many,
9977 // and probably has lurking deadlocks.
9978
9979 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9980 throw new SecurityException("Only the OS may call notifyUserActivity()");
9981 }
9982
9983 if (mNotifyUserActivity.getAndSet(false)) {
9984 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9985 USER_ACTIVITY_NOTIFICATION_DELAY);
9986 }
9987 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009988
9989 @Override
9990 public boolean canConnectTo5GInDsdsMode() {
9991 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9992 }
Jack Yud10cdd42020-09-28 20:28:01 -07009993
9994 @Override
9995 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9996 String callingFeatureId) {
9997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9998 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9999 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10000 }
10001
10002 Phone phone = getPhone(subId);
10003 if (phone == null) {
10004 throw new RuntimeException("phone is not available");
10005 }
10006 // Now that all security checks passes, perform the operation as ourselves.
10007 final long identity = Binder.clearCallingIdentity();
10008 try {
10009 return phone.getEquivalentHomePlmns();
10010 } finally {
10011 Binder.restoreCallingIdentity(identity);
10012 }
10013 }
Daniel Bright59e67312020-11-13 11:49:37 -080010014
10015 @Override
10016 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010017 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10018 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010019 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010020 if (radioInterfaceCapabilities == null) {
10021 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010022 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010023 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010024 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010025
Hui Wang641e81c2020-10-12 12:14:23 -070010026 @Override
10027 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10028 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010029 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10030 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10031 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10032 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10033 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010034 if (DBG) {
10035 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10036 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10037 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10038 }
10039
10040 if (!SubscriptionManager.isValidSubscriptionId(subId)
10041 || appType < TelephonyManager.APPTYPE_UNKNOWN
10042 || appType > TelephonyManager.APPTYPE_ISIM
10043 || nafUrl == null || securityProtocol == null || callback == null) {
10044 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10045 if (callback != null) {
10046 try {
10047 callback.onAuthenticationFailure(
10048 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10049 } catch (RemoteException exception) {
10050 log("Fail to notify onAuthenticationFailure due to " + exception);
10051 }
10052 return;
10053 }
10054 }
10055
10056 final long token = Binder.clearCallingIdentity();
10057 try {
10058 getGbaManager(subId).bootstrapAuthenticationRequest(
10059 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10060 forceBootStrapping, callback));
10061 } finally {
10062 Binder.restoreCallingIdentity(token);
10063 }
10064 }
10065
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010066 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010067 * Attempts to set the radio power state for all phones for thermal reason.
10068 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010069 * requested radio power state will actually be set. See {@link
10070 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10071 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010072 * @param enable {@code true} if trying to turn radio on.
10073 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10074 * false}.
10075 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010076 private boolean setRadioPowerForThermal(boolean enable) {
10077 boolean isPhoneAvailable = false;
10078 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10079 Phone phone = PhoneFactory.getPhone(i);
10080 if (phone != null) {
10081 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10082 isPhoneAvailable = true;
10083 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010084 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010085
10086 // return true if successfully informed the phone object about the thermal radio power
10087 // request.
10088 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010089 }
10090
10091 private int handleDataThrottlingRequest(int subId,
10092 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010093 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10094 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10095 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10096 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10097 throw new IllegalArgumentException("modem does not support data throttling");
10098 }
10099
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010100 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10101 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010102 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010103 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10104 }
10105
10106 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10107
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010108 if (isDataThrottlingSupported) {
10109 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010110 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010111 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10112 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10113 } else if (thermalMitigationResult
10114 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010115 log("Modem likely does not support data throttling on secondary carrier. Data " +
10116 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10117 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010118 }
10119 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010120 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010121
10122 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010123 }
10124
Jack Nudelman644b91a2021-03-12 14:09:48 -080010125 private static List<String> getThermalMitigationAllowlist(Context context) {
10126 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10127 for (String pckg : context.getResources()
10128 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10129 sThermalMitigationAllowlistedPackages.add(pckg);
10130 }
10131 }
10132
10133 return sThermalMitigationAllowlistedPackages;
10134 }
10135
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010136 private boolean isAnyPhoneInEmergencyState() {
10137 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10138 if (tm.isInEmergencyCall()) {
10139 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10140 return true;
10141 }
10142 for (Phone phone : PhoneFactory.getPhones()) {
10143 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10144 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10145 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10146 + phone.isInEcm());
10147 return true;
10148 }
10149 }
10150
10151 return false;
10152 }
10153
Jack Nudelman644b91a2021-03-12 14:09:48 -080010154 /**
10155 * Used by shell commands to add an authorized package name for thermal mitigation.
10156 * @param packageName name of package to be allowlisted
10157 * @param context
10158 */
10159 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10160 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10161 sThermalMitigationAllowlistedPackages.add(packageName);
10162 }
10163
10164 /**
10165 * Used by shell commands to remove an authorized package name for thermal mitigation.
10166 * @param packageName name of package to remove from allowlist
10167 * @param context
10168 */
10169 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10170 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10171 sThermalMitigationAllowlistedPackages.remove(packageName);
10172 }
10173
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010174 /**
10175 * Thermal mitigation request to control functionalities at modem.
10176 *
10177 * @param subId the id of the subscription.
10178 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010179 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010180 *
10181 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10182 */
10183 @Override
10184 @ThermalMitigationResult
10185 public int sendThermalMitigationRequest(
10186 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010187 ThermalMitigationRequest thermalMitigationRequest,
10188 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010189 enforceModifyPermission();
10190
Jack Nudelman644b91a2021-03-12 14:09:48 -080010191 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10192 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10193 .contains(callingPackage)) {
10194 throw new SecurityException("Calling package must be configured in the device config. "
10195 + "calling package: " + callingPackage);
10196 }
10197
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010198 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10199 final long identity = Binder.clearCallingIdentity();
10200
10201 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10202 try {
10203 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10204 switch (thermalMitigationAction) {
10205 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10206 thermalMitigationResult =
10207 handleDataThrottlingRequest(subId,
10208 thermalMitigationRequest.getDataThrottlingRequest());
10209 break;
10210 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10211 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10212 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10213 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10214 }
10215
10216 // Ensure that radio is on. If not able to power on due to phone being
10217 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010218 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010219 thermalMitigationResult =
10220 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10221 break;
10222 }
10223
10224 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10225 false);
10226 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10227 break;
10228 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10229 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10230 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10231 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10232 }
10233
10234 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10235 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010236 Phone phone = getPhone(subId);
10237 if (phone == null) {
10238 thermalMitigationResult =
10239 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10240 break;
10241 }
10242
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010243 TelephonyConnectionService service =
10244 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010245 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010246 Log.e(LOG_TAG, "An emergency call is pending");
10247 thermalMitigationResult =
10248 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10249 break;
10250 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 thermalMitigationResult =
10252 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10253 break;
10254 }
10255 } else {
10256 thermalMitigationResult =
10257 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10258 break;
10259 }
10260
10261 // Turn radio off. If not able to power off due to phone being unavailable,
10262 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010263 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010264 thermalMitigationResult =
10265 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10266 break;
10267 }
10268 thermalMitigationResult =
10269 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10270 break;
10271 default:
10272 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10273 + "not exist. Requested action: " + thermalMitigationAction);
10274 }
10275 } catch (IllegalArgumentException e) {
10276 throw e;
10277 } catch (Exception e) {
10278 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10279 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10280 } finally {
10281 Binder.restoreCallingIdentity(identity);
10282 }
10283
10284 if (DBG) {
10285 log("thermalMitigationRequest returning with thermalMitigationResult: "
10286 + thermalMitigationResult);
10287 }
10288
10289 return thermalMitigationResult;
10290 }
Hui Wang641e81c2020-10-12 12:14:23 -070010291
10292 /**
10293 * Set the GbaService Package Name that Telephony will bind to.
10294 *
10295 * @param subId The sim that the GbaService is associated with.
10296 * @param packageName The name of the package to be replaced with.
10297 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10298 */
10299 @Override
10300 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10301 enforceModifyPermission();
10302
10303 final long identity = Binder.clearCallingIdentity();
10304 try {
10305 return getGbaManager(subId).overrideServicePackage(packageName);
10306 } finally {
10307 Binder.restoreCallingIdentity(identity);
10308 }
10309 }
10310
10311 /**
10312 * Return the package name of the currently bound GbaService.
10313 *
10314 * @param subId The sim that the GbaService is associated with.
10315 * @return the package name of the GbaService configuration, null if GBA is not supported.
10316 */
10317 @Override
10318 public String getBoundGbaService(int subId) {
10319 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10320
10321 final long identity = Binder.clearCallingIdentity();
10322 try {
10323 return getGbaManager(subId).getServicePackage();
10324 } finally {
10325 Binder.restoreCallingIdentity(identity);
10326 }
10327 }
10328
10329 /**
10330 * Set the release time for telephony to unbind GbaService.
10331 *
10332 * @param subId The sim that the GbaService is associated with.
10333 * @param interval The release time to unbind GbaService by millisecond.
10334 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10335 */
10336 @Override
10337 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10338 enforceModifyPermission();
10339
10340 final long identity = Binder.clearCallingIdentity();
10341 try {
10342 return getGbaManager(subId).overrideReleaseTime(interval);
10343 } finally {
10344 Binder.restoreCallingIdentity(identity);
10345 }
10346 }
10347
10348 /**
10349 * Return the release time for telephony to unbind GbaService.
10350 *
10351 * @param subId The sim that the GbaService is associated with.
10352 * @return The release time to unbind GbaService by millisecond.
10353 */
10354 @Override
10355 public int getGbaReleaseTime(int subId) {
10356 enforceReadPrivilegedPermission("getGbaReleaseTime");
10357
10358 final long identity = Binder.clearCallingIdentity();
10359 try {
10360 return getGbaManager(subId).getReleaseTime();
10361 } finally {
10362 Binder.restoreCallingIdentity(identity);
10363 }
10364 }
10365
10366 private GbaManager getGbaManager(int subId) {
10367 GbaManager instance = GbaManager.getInstance(subId);
10368 if (instance == null) {
10369 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10370 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10371 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10372 }
10373 return instance;
10374 }
Hui Wang761a6682020-10-31 05:12:53 +000010375
10376 /**
10377 * indicate whether the device and the carrier can support
10378 * RCS VoLTE single registration.
10379 */
10380 @Override
10381 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010382 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10383 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10384 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10385 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010386
10387 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10388 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10389 }
10390
10391 final long identity = Binder.clearCallingIdentity();
10392 try {
10393 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10394 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010395 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10396 if (isCapable != null) {
10397 return isCapable;
10398 }
Hui Wang761a6682020-10-31 05:12:53 +000010399 }
Hui Wang67af90e2021-06-04 16:57:15 -070010400 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10401 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
10407 /**
10408 * Register RCS provisioning callback.
10409 */
10410 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010411 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010412 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010413 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010414 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010415 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10416 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010417
10418 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10419 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10420 }
10421 if (!isImsAvailableOnDevice()) {
10422 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10423 "IMS not available on device.");
10424 }
10425
10426 final long identity = Binder.clearCallingIdentity();
10427 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010428 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010429 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010430 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10431 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010432 }
Hui Wang761a6682020-10-31 05:12:53 +000010433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436 }
10437
10438 /**
10439 * Unregister RCS provisioning callback.
10440 */
10441 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010442 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010443 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010444 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010445 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010446 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10447 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010448
10449 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10450 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10451 }
10452 if (!isImsAvailableOnDevice()) {
10453 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10454 "IMS not available on device.");
10455 }
10456
10457 final long identity = Binder.clearCallingIdentity();
10458 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010459 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010460 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010461 } finally {
10462 Binder.restoreCallingIdentity(identity);
10463 }
10464 }
10465
10466 /**
10467 * trigger RCS reconfiguration.
10468 */
10469 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010470 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10471 "triggerRcsReconfiguration",
10472 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010473
10474 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10475 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10476 }
10477 if (!isImsAvailableOnDevice()) {
10478 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10479 "IMS not available on device.");
10480 }
10481
10482 final long identity = Binder.clearCallingIdentity();
10483 try {
10484 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10485 } finally {
10486 Binder.restoreCallingIdentity(identity);
10487 }
10488 }
10489
10490 /**
10491 * Provide the client configuration parameters of the RCS application.
10492 */
10493 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010494 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10495 "setRcsClientConfiguration",
10496 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010497
10498 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10499 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10500 }
10501 if (!isImsAvailableOnDevice()) {
10502 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10503 "IMS not available on device.");
10504 }
10505
10506 final long identity = Binder.clearCallingIdentity();
10507
10508 try {
10509 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10510 if (configBinder == null) {
10511 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010512 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10513 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010514 } else {
10515 configBinder.setRcsClientConfiguration(rcc);
10516 }
joonhunshin3e154242021-09-17 06:33:39 +000010517
10518 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10519 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010520 } catch (RemoteException e) {
10521 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010522 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10523 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010524 } finally {
10525 Binder.restoreCallingIdentity(identity);
10526 }
10527 }
10528
10529 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010530 * Enables or disables the test mode for RCS VoLTE single registration.
10531 */
10532 @Override
10533 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10534 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10535 "setRcsSingleRegistrationTestModeEnabled");
10536
10537 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10538 }
10539
10540 /**
10541 * Gets the test mode for RCS VoLTE single registration.
10542 */
10543 @Override
10544 public boolean getRcsSingleRegistrationTestModeEnabled() {
10545 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10546 "getRcsSingleRegistrationTestModeEnabled");
10547
10548 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10549 }
10550
10551 /**
Hui Wang761a6682020-10-31 05:12:53 +000010552 * Overrides the config of RCS VoLTE single registration enabled for the device.
10553 */
10554 @Override
10555 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10556 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10557 "setDeviceSingleRegistrationEnabledOverride");
10558 enforceModifyPermission();
10559
10560 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10561 : Boolean.parseBoolean(enabledStr);
10562 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010563 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010564 }
10565
10566 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010567 * Sends a device to device communication message. Only usable via shell.
10568 * @param message message to send.
10569 * @param value message value.
10570 */
10571 @Override
10572 public void sendDeviceToDeviceMessage(int message, int value) {
10573 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010574 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010575 enforceModifyPermission();
10576
10577 final long identity = Binder.clearCallingIdentity();
10578 try {
10579 TelephonyConnectionService service =
10580 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10581 if (service == null) {
10582 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10583 return;
10584 }
10585 service.sendTestDeviceToDeviceMessage(message, value);
10586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
10590
Tyler Gunnbabbda02021-02-10 11:05:02 -080010591 /**
10592 * Sets the specified device to device transport active.
10593 * @param transport The transport to set active.
10594 */
10595 @Override
10596 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10597 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10598 "setActiveDeviceToDeviceTransport");
10599 enforceModifyPermission();
10600
10601 final long identity = Binder.clearCallingIdentity();
10602 try {
10603 TelephonyConnectionService service =
10604 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10605 if (service == null) {
10606 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10607 return;
10608 }
10609 service.setActiveDeviceToDeviceTransport(transport);
10610 } finally {
10611 Binder.restoreCallingIdentity(identity);
10612 }
10613 }
Tyler Gunn92479152021-01-20 16:30:10 -080010614
Tyler Gunnd4339262021-05-03 14:46:49 -070010615 @Override
10616 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10617 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10618 "setDeviceToDeviceForceEnabled");
10619
10620 final long identity = Binder.clearCallingIdentity();
10621 try {
10622 Arrays.stream(PhoneFactory.getPhones()).forEach(
10623 p -> {
10624 Phone thePhone = p.getImsPhone();
10625 if (thePhone != null && thePhone instanceof ImsPhone) {
10626 ImsPhone imsPhone = (ImsPhone) thePhone;
10627 CallTracker tracker = imsPhone.getCallTracker();
10628 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10629 ImsPhoneCallTracker imsPhoneCallTracker =
10630 (ImsPhoneCallTracker) tracker;
10631 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10632 }
10633 }
10634 }
10635 );
10636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
10640
Tyler Gunn92479152021-01-20 16:30:10 -080010641 /**
Hui Wang761a6682020-10-31 05:12:53 +000010642 * Gets the config of RCS VoLTE single registration enabled for the device.
10643 */
10644 @Override
10645 public boolean getDeviceSingleRegistrationEnabled() {
10646 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10647 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10648 }
10649
10650 /**
10651 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10652 */
10653 @Override
10654 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10655 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10656 "setCarrierSingleRegistrationEnabledOverride");
10657 enforceModifyPermission();
10658
10659 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10660 : Boolean.parseBoolean(enabledStr);
10661 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10662 subId, enabled);
10663 }
10664
10665 /**
10666 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10667 */
10668 @Override
10669 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10670 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10671 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10672 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010673
10674 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010675 * Overrides the ims feature validation result
10676 */
10677 @Override
10678 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10679 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10680 "setImsFeatureValidationOverride");
10681
10682 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10683 : Boolean.parseBoolean(enabledStr);
10684 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10685 subId, enabled);
10686 }
10687
10688 /**
10689 * Gets the ims feature validation override value
10690 */
10691 @Override
10692 public boolean getImsFeatureValidationOverride(int subId) {
10693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10694 "getImsFeatureValidationOverride");
10695 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10696 }
10697
10698 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010699 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10700 * their mobile plan.
10701 */
10702 @Override
10703 public String getMobileProvisioningUrl() {
10704 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 return getDefaultPhone().getMobileProvisioningUrl();
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010712
James.cf Linbcdf8b32021-01-14 16:44:13 +080010713 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010714 * Get the EAB contact from the EAB database.
10715 */
10716 @Override
10717 public String getContactFromEab(String contact) {
10718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10719 enforceModifyPermission();
10720 final long identity = Binder.clearCallingIdentity();
10721 try {
10722 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10723 } finally {
10724 Binder.restoreCallingIdentity(identity);
10725 }
10726 }
10727
10728 /**
Calvin Pana1434322021-07-01 19:27:01 +080010729 * Get the EAB capability from the EAB database.
10730 */
10731 @Override
10732 public String getCapabilityFromEab(String contact) {
10733 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10734 enforceModifyPermission();
10735 final long identity = Binder.clearCallingIdentity();
10736 try {
10737 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10738 } finally {
10739 Binder.restoreCallingIdentity(identity);
10740 }
10741 }
10742
10743 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010744 * Remove the EAB contacts from the EAB database.
10745 */
10746 @Override
10747 public int removeContactFromEab(int subId, String contacts) {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10749 enforceModifyPermission();
10750 final long identity = Binder.clearCallingIdentity();
10751 try {
10752 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10753 } finally {
10754 Binder.restoreCallingIdentity(identity);
10755 }
10756 }
10757
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010758 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010759 public boolean getDeviceUceEnabled() {
10760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10761 final long identity = Binder.clearCallingIdentity();
10762 try {
10763 return mApp.getDeviceUceEnabled();
10764 } finally {
10765 Binder.restoreCallingIdentity(identity);
10766 }
10767 }
10768
10769 @Override
10770 public void setDeviceUceEnabled(boolean isEnabled) {
10771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10772 final long identity = Binder.clearCallingIdentity();
10773 try {
10774 mApp.setDeviceUceEnabled(isEnabled);
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
Brad Ebinger14d467f2021-02-12 06:18:28 +000010780 /**
10781 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10782 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10783 */
10784 // Used for SHELL command only right now.
10785 @Override
10786 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10787 List<String> featureTags) {
10788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10789 "addUceRegistrationOverrideShell");
10790 final long identity = Binder.clearCallingIdentity();
10791 try {
10792 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10793 new ArraySet<>(featureTags));
10794 } catch (ImsException e) {
10795 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10796 } finally {
10797 Binder.restoreCallingIdentity(identity);
10798 }
10799 }
10800
10801 /**
10802 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10803 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10804 */
10805 // Used for SHELL command only right now.
10806 @Override
10807 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10808 List<String> featureTags) {
10809 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10810 "removeUceRegistrationOverrideShell");
10811 final long identity = Binder.clearCallingIdentity();
10812 try {
10813 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10814 new ArraySet<>(featureTags));
10815 } catch (ImsException e) {
10816 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10817 } finally {
10818 Binder.restoreCallingIdentity(identity);
10819 }
10820 }
10821
10822 /**
10823 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10824 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10825 */
10826 // Used for SHELL command only right now.
10827 @Override
10828 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10830 "clearUceRegistrationOverrideShell");
10831 final long identity = Binder.clearCallingIdentity();
10832 try {
10833 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10834 } catch (ImsException e) {
10835 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10836 } finally {
10837 Binder.restoreCallingIdentity(identity);
10838 }
10839 }
10840
10841 /**
10842 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10843 */
10844 // Used for SHELL command only right now.
10845 @Override
10846 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10848 "getLatestRcsContactUceCapabilityShell");
10849 final long identity = Binder.clearCallingIdentity();
10850 try {
10851 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10852 } catch (ImsException e) {
10853 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10854 } finally {
10855 Binder.restoreCallingIdentity(identity);
10856 }
10857 }
10858
10859 /**
10860 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10861 * device does not have an active PUBLISH.
10862 */
10863 // Used for SHELL command only right now.
10864 @Override
10865 public String getLastUcePidfXmlShell(int subId) {
10866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10867 final long identity = Binder.clearCallingIdentity();
10868 try {
10869 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10870 } catch (ImsException e) {
10871 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10872 } finally {
10873 Binder.restoreCallingIdentity(identity);
10874 }
10875 }
10876
James.cf Line8713a42021-04-29 16:04:26 +080010877 /**
10878 * Remove UCE requests cannot be sent to the network status.
10879 */
10880 // Used for SHELL command only right now.
10881 @Override
10882 public boolean removeUceRequestDisallowedStatus(int subId) {
10883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10884 final long identity = Binder.clearCallingIdentity();
10885 try {
10886 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10887 } catch (ImsException e) {
10888 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10889 } finally {
10890 Binder.restoreCallingIdentity(identity);
10891 }
10892 }
10893
James.cf Lin18bb9002021-05-25 01:37:38 +080010894 /**
10895 * Remove UCE requests cannot be sent to the network status.
10896 */
10897 // Used for SHELL command only.
10898 @Override
10899 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10900 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10901 final long identity = Binder.clearCallingIdentity();
10902 try {
10903 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10904 } catch (ImsException e) {
10905 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10906 } finally {
10907 Binder.restoreCallingIdentity(identity);
10908 }
10909 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010910
James.cf Lin4b784aa2021-01-31 03:25:15 +080010911 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010912 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10913 String callingPackage) {
10914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10915 mApp, subId, "setSignalStrengthUpdateRequest");
10916
10917 final int callingUid = Binder.getCallingUid();
10918 // Verify that tha callingPackage belongs to the calling UID
10919 mApp.getSystemService(AppOpsManager.class)
10920 .checkPackage(callingUid, callingPackage);
10921
Rambo Wang3607f502021-02-01 21:51:40 -080010922 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010923
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
10926 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10927 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10928
10929 if (result instanceof IllegalStateException) {
10930 throw (IllegalStateException) result;
10931 }
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
10936
10937 @Override
10938 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10939 String callingPackage) {
10940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10941 mApp, subId, "clearSignalStrengthUpdateRequest");
10942
10943 final int callingUid = Binder.getCallingUid();
10944 // Verify that tha callingPackage belongs to the calling UID
10945 mApp.getSystemService(AppOpsManager.class)
10946 .checkPackage(callingUid, callingPackage);
10947
10948 final long identity = Binder.clearCallingIdentity();
10949 try {
10950 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10951 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10952
10953 if (result instanceof IllegalStateException) {
10954 throw (IllegalStateException) result;
10955 }
10956 } finally {
10957 Binder.restoreCallingIdentity(identity);
10958 }
10959 }
10960
Rambo Wang3607f502021-02-01 21:51:40 -080010961 private static void validateSignalStrengthUpdateRequest(Context context,
10962 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010963 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10964 // phone/system process do not have further restriction on request
10965 return;
10966 }
10967
10968 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010969 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010970 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010971 context.enforceCallingOrSelfPermission(
10972 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10973 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010974 }
10975
10976 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10977 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10978 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10979 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10980 || info.isEnabled()) {
10981 throw new IllegalArgumentException(
10982 "Only system can set hide fields in SignalThresholdInfo");
10983 }
10984
10985 // Thresholds length for each RAN need in range. This has been validated in
10986 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10987 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10988 final int[] thresholds = info.getThresholds();
10989 Objects.requireNonNull(thresholds);
10990 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10991 || thresholds.length
10992 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10993 throw new IllegalArgumentException(
10994 "thresholds length is out of range: " + thresholds.length);
10995 }
10996 }
10997 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010998
10999 /**
11000 * Gets the current phone capability.
11001 *
11002 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11003 * @return the PhoneCapability which describes the data connection capability of modem.
11004 * It's used to evaluate possible phone config change, for example from single
11005 * SIM device to multi-SIM device.
11006 */
11007 @Override
11008 public PhoneCapability getPhoneCapability() {
11009 enforceReadPrivilegedPermission("getPhoneCapability");
11010 final long identity = Binder.clearCallingIdentity();
11011 try {
11012 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11013 } finally {
11014 Binder.restoreCallingIdentity(identity);
11015 }
11016 }
Michele Berionne5e411512020-11-13 02:36:59 +000011017
11018 /**
11019 * Prepare TelephonyManager for an unattended reboot. The reboot is
11020 * required to be done shortly after the API is invoked.
11021 */
11022 @Override
11023 @TelephonyManager.PrepareUnattendedRebootResult
11024 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011025 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011026 enforceRebootPermission();
11027
11028 final long identity = Binder.clearCallingIdentity();
11029 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011030 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011035
11036 /**
11037 * Request to get the current slicing configuration including URSP rules and
11038 * NSSAIs (configured, allowed and rejected).
11039 *
11040 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11041 */
11042 @Override
11043 public void getSlicingConfig(ResultReceiver callback) {
11044 enforceReadPrivilegedPermission("getSlicingConfig");
11045
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
11048 Phone phone = getDefaultPhone();
11049 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11050 } finally {
11051 Binder.restoreCallingIdentity(identity);
11052 }
11053 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011054
11055 /**
11056 * Register an IMS connection state callback
11057 */
11058 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011059 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11060 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011061 if (feature == ImsFeature.FEATURE_MMTEL) {
11062 // ImsMmTelManager
11063 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11064 TelephonyPermissions
11065 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11066 mApp, subId, "registerImsStateCallback");
11067 } else if (feature == ImsFeature.FEATURE_RCS) {
11068 // ImsRcsManager or SipDelegateManager
11069 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11070 Binder.getCallingUid(), "registerImsStateCallback",
11071 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11072 Manifest.permission.READ_PRECISE_PHONE_STATE,
11073 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11074 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11075 }
11076
11077 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11078 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11079 "IMS not available on device.");
11080 }
11081
11082 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11083 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11084 }
11085
11086 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11087 if (controller == null) {
11088 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11089 "IMS not available on device.");
11090 }
11091
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011092 if (callingPackage == null) {
11093 callingPackage = getCurrentPackageName();
11094 }
11095
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011096 final long token = Binder.clearCallingIdentity();
11097 try {
11098 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011099 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011100 } catch (ImsException e) {
11101 throw new ServiceSpecificException(e.getCode());
11102 } finally {
11103 Binder.restoreCallingIdentity(token);
11104 }
11105 }
11106
11107 /**
11108 * Unregister an IMS connection state callback
11109 */
11110 @Override
11111 public void unregisterImsStateCallback(IImsStateCallback cb) {
11112 final long token = Binder.clearCallingIdentity();
11113 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11114 if (controller == null) {
11115 return;
11116 }
11117 try {
11118 controller.unregisterImsStateCallback(cb);
11119 } finally {
11120 Binder.restoreCallingIdentity(token);
11121 }
11122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011123}